Mercurial > hg > ltpda
comparison m-toolbox/m/gui/pzmodel_designer/pzmodel_helper.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function pzmodel_helper(varargin) | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: PZMODEL_HELPER opens the LTPDA pzmodel GUI. | |
5 % | |
6 % CALL: pzmodel_helper() | |
7 % | |
8 % VERSION: $Id: pzmodel_helper.m,v 1.12 2009/09/07 17:23:07 nicola Exp $ | |
9 % | |
10 % HISTORY: 07-09-2009 N Tateo | |
11 % Creation | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 | |
16 | |
17 % This function draws the PZmodel helper main figure. | |
18 | |
19 % Some initial setup | |
20 import utils.const.* | |
21 prefs = getappdata(0, 'LTPDApreferences'); | |
22 utils.helper.msg(msg.PROC1, 'building Main Figure'); | |
23 | |
24 Screen = get(0,'screensize'); | |
25 mainfig.Gproperties.Screen = Screen; | |
26 mainfig.Gproperties.Gwidth = 0.6; | |
27 mainfig.Gproperties.Gheight = 0.9; | |
28 mainfig.Gproperties.Gborder = 10; | |
29 fontSize = (prefs.repository.fontsize+2)*(1440/Screen(3)); | |
30 | |
31 l = (0.5-mainfig.Gproperties.Gwidth/2); | |
32 b = (0.5-mainfig.Gproperties.Gheight/2); | |
33 w = mainfig.Gproperties.Gwidth; | |
34 h = mainfig.Gproperties.Gheight; | |
35 mainfig.Gproperties.Gposition = [l b w h]; | |
36 | |
37 if ~isempty(varargin) && ishandle(varargin{1}) | |
38 mainfig.handle = varargin{1}; | |
39 set(mainfig.handle, 'Tag', 'PZMODELhelpermainfig'); | |
40 set(mainfig.handle, 'Units', 'normalized'); | |
41 set(mainfig.handle, 'Visible', 'on'); | |
42 else | |
43 % Initialize and hide the GUI as it is being constructed. | |
44 mainfig.handle = figure('Name', 'PZModel Helper GUI',... | |
45 'NumberTitle', 'off',... | |
46 'Visible','on',... | |
47 'Units','normalized',... | |
48 'Position',mainfig.Gproperties.Gposition,... | |
49 'Toolbar', 'none',... | |
50 'MenuBar', 'none',... | |
51 'Color', 'w',... | |
52 'Resize', 'on',... | |
53 'Tag', 'PZMODELhelpermainfig'); | |
54 end | |
55 | |
56 % % DEFINE THE HANDLES VARIABLE | |
57 % handles = struct(); | |
58 % handles.pzEdit = findobj(gcf,'Tag','pzEdit'); | |
59 % handles.phaseAxes = findobj(gcf,'Tag','phaseAxes'); | |
60 % handles.filterStrEdit = findobj(gcf,'Tag','filterStrEdit'); | |
61 % handles.fsEdit = findobj(gcf,'Tag','fsEdit'); | |
62 % handles.nfEdit = findobj(gcf,'Tag','nfEdit'); | |
63 % handles.f2Edit = findobj(gcf,'Tag','f2Edit'); | |
64 % handles.f1Edit = findobj(gcf,'Tag','f1Edit'); | |
65 % handles.gainEdit = findobj(gcf,'Tag','gainEdit'); | |
66 % handles.magAxes = findobj(gcf,'Tag','magAxes'); | |
67 % handles.poleList = findobj(gcf,'Tag','poleList'); | |
68 % handles.zeroList = findobj(gcf,'Tag','zeroList'); | |
69 % handles.main = gcf; | |
70 % % handles. = findobj(gcf,'Tag',''); | |
71 % % handles. = findobj(gcf,'Tag',''); | |
72 % | |
73 % % 'uipanel1' | |
74 % % 'uipanel2' | |
75 % % 'saveAObtn' | |
76 % % 'figureBtn' | |
77 % % 'replotBtn' | |
78 % % 'GainTxt' | |
79 % % 'addZeroBtn' | |
80 % % 'addPoleBtn' | |
81 % % 'deleteZerosBtn' | |
82 % % 'deletePolesBtn' | |
83 % % 'clearBtn' | |
84 % % 'output' | |
85 | |
86 % create empty lists | |
87 poles = []; | |
88 zeros = []; | |
89 setappdata(gcf, 'poles', poles); | |
90 setappdata(gcf, 'zeros', zeros); | |
91 setappdata(gcf, 'filt', []); | |
92 | |
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
94 %%%%%%%%%%%%%%%%%%%%%%%%%% DRAW CONTENTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
95 | |
96 uip1 = uipanel('Title', 'Response',... | |
97 'FontSize', fontSize-1,... | |
98 'BackgroundColor','white',... | |
99 'Tag', 'uipanel1',... | |
100 'Position',[.35 .15 .64 .84]); | |
101 | |
102 uip2 = uipanel('Title', 'Pole/zero entry',... | |
103 'FontSize', fontSize-1,... | |
104 'BackgroundColor','white',... | |
105 'Tag', 'uipanel2',... | |
106 'Position',[.01 .6 .32 .39]); | |
107 | |
108 uip3 = uipanel('Title', 'Plot controls',... | |
109 'FontSize', fontSize-1,... | |
110 'BackgroundColor','white',... | |
111 'Tag', 'uipanel3',... | |
112 'Position',[.01 .15 .32 .44]); | |
113 | |
114 uicontrol('Style','text',... | |
115 'String', 'MIIR constructor string:',... | |
116 'HorizontalAlignment', 'left',... | |
117 'FontSize', fontSize+2,... | |
118 'FontWeight','bold',... | |
119 'ForeGroundColor','black',... | |
120 'backgroundColor','white',... | |
121 'Units','normalized',... | |
122 'Position', [.02 .115 .3 .03]) | |
123 | |
124 uicontrol('Style','edit',... | |
125 'Tag', 'filterStrEdit',... | |
126 'Max',10,... | |
127 'HorizontalAlignment', 'center',... | |
128 'FontSize', fontSize+2,... | |
129 'ForeGroundColor','black',... | |
130 'backgroundColor',[.94 .94 .94],... | |
131 'Units','normalized',... | |
132 'Position', [.02 .01 .96 .1]) | |
133 | |
134 %%%%%%%%%%%%%%%%%%%%%% | |
135 % First panel contents | |
136 %%%%%%%%%%%%%%%%%%%%%% | |
137 | |
138 axes('Parent',uip1,... | |
139 'Tag','phaseAxes',... | |
140 'Box','on',... | |
141 'Units','normalized',... | |
142 'Position', [.11 .08 .8 .35]); | |
143 | |
144 axes('Parent',uip1,... | |
145 'Tag','magAxes',... | |
146 'Box','on',... | |
147 'Units','normalized',... | |
148 'Position', [.11 .52 .8 .43]); | |
149 | |
150 %%%%%%%%%%%%%%%%%%%%%%% | |
151 % Second panel contents | |
152 %%%%%%%%%%%%%%%%%%%%%%% | |
153 | |
154 uicontrol('Parent',uip2, ... | |
155 'Style','edit',... | |
156 'Tag', 'pzEdit',... | |
157 'Max',1,... | |
158 'String', '1 0',... | |
159 'HorizontalAlignment', 'center',... | |
160 'FontSize', fontSize,... | |
161 'ForeGroundColor','black',... | |
162 'backgroundColor',[.92 .92 .92],... | |
163 'Units','normalized',... | |
164 'Position', [.1 .85 .35 .1]) | |
165 | |
166 uicontrol('Parent',uip2, ... | |
167 'Style','text',... | |
168 'String', 'Frequency [Hz] (Q)',... | |
169 'HorizontalAlignment', 'center',... | |
170 'FontSize', fontSize,... | |
171 'ForeGroundColor','black',... | |
172 'backgroundColor','w',... | |
173 'Units','normalized',... | |
174 'Position', [.45 .83 .5 .1]) | |
175 | |
176 uicontrol('Parent',uip2, ... | |
177 'Style','pushbutton',... | |
178 'String', 'Add pole',... | |
179 'HorizontalAlignment', 'center',... | |
180 'FontSize', fontSize,... | |
181 'ForeGroundColor','black',... | |
182 'backgroundColor','w',... | |
183 'Units','normalized',... | |
184 'Callback', @addPoleBtn_Callback,... | |
185 'Position', [.075 .75 .4 .08]) | |
186 | |
187 uicontrol('Parent',uip2, ... | |
188 'Style','pushbutton',... | |
189 'String', 'Add zero',... | |
190 'HorizontalAlignment', 'center',... | |
191 'FontSize', fontSize,... | |
192 'ForeGroundColor','black',... | |
193 'backgroundColor','w',... | |
194 'Units','normalized',... | |
195 'Callback', @addZeroBtn_Callback,... | |
196 'Position', [.525 .75 .4 .08]) | |
197 | |
198 uicontrol('Parent',uip2, ... | |
199 'Style','listbox',... | |
200 'Tag','poleList',... | |
201 'String', '-',... | |
202 'HorizontalAlignment', 'center',... | |
203 'FontSize', fontSize,... | |
204 'ForeGroundColor','black',... | |
205 'backgroundColor','w',... | |
206 'Units','normalized',... | |
207 ... 'Callback', @poleList_Callback,... | |
208 'Position', [.075 .25 .4 .45]) | |
209 | |
210 uicontrol('Parent',uip2, ... | |
211 'Style','listbox',... | |
212 'Tag','zeroList',... | |
213 'String', '-',... | |
214 'HorizontalAlignment', 'center',... | |
215 'FontSize', fontSize,... | |
216 'ForeGroundColor','black',... | |
217 'backgroundColor','w',... | |
218 'Units','normalized',... | |
219 ... 'Callback', @zeroList_Callback,... | |
220 'Position', [.525 .25 .4 .45]) | |
221 | |
222 uicontrol('Parent',uip2, ... | |
223 'Style','pushbutton',... | |
224 'String', 'Delete',... | |
225 'HorizontalAlignment', 'center',... | |
226 'FontSize', fontSize,... | |
227 'ForeGroundColor','black',... | |
228 'backgroundColor','w',... | |
229 'Units','normalized',... | |
230 'Callback', @deletePolesBtn_Callback,... | |
231 'Position', [.075 .15 .4 .08]) | |
232 | |
233 uicontrol('Parent',uip2, ... | |
234 'Style','pushbutton',... | |
235 'String', 'Delete',... | |
236 'HorizontalAlignment', 'center',... | |
237 'FontSize', fontSize,... | |
238 'ForeGroundColor','black',... | |
239 'backgroundColor','w',... | |
240 'Units','normalized',... | |
241 'Callback', @deleteZerosBtn_Callback,... | |
242 'Position', [.525 .15 .4 .08]) | |
243 | |
244 uicontrol('Parent',uip2, ... | |
245 'Style','pushbutton',... | |
246 'String', 'Clear lists',... | |
247 'HorizontalAlignment', 'center',... | |
248 'FontSize', fontSize,... | |
249 'ForeGroundColor','black',... | |
250 'backgroundColor','w',... | |
251 'Units','normalized',... | |
252 'Callback', @clearBtn_Callback,... | |
253 'Position', [.075 .04 .85 .08]) | |
254 | |
255 %%%%%%%%%%%%%%%%%%%%%% | |
256 % Third panel contents | |
257 %%%%%%%%%%%%%%%%%%%%%% | |
258 | |
259 uicontrol('Parent',uip3, ... | |
260 'Style','edit',... | |
261 'Tag', 'gainEdit',... | |
262 'Callback',@valueEdit_Callback, ... | |
263 'Max',1,... | |
264 'String', '1',... | |
265 'HorizontalAlignment', 'center',... | |
266 'FontSize', fontSize,... | |
267 'ForeGroundColor','black',... | |
268 'backgroundColor',[.92 .92 .92],... | |
269 'Units','normalized',... | |
270 'Position', [.1 .87 .3 .08]) | |
271 uicontrol('Parent',uip3, ... | |
272 'Style','text',... | |
273 'String', 'Gain',... | |
274 'HorizontalAlignment', 'left',... | |
275 'FontSize', fontSize,... | |
276 'ForeGroundColor','black',... | |
277 'backgroundColor','w',... | |
278 'Units','normalized',... | |
279 'Position', [.47 .855 .4 .08]) | |
280 | |
281 uicontrol('Parent',uip3, ... | |
282 'Style','edit',... | |
283 'Tag', 'fsEdit',... | |
284 'Callback',@valueEdit_Callback, ... | |
285 'Max',1,... | |
286 'String', '',... | |
287 'HorizontalAlignment', 'center',... | |
288 'FontSize', fontSize,... | |
289 'ForeGroundColor','black',... | |
290 'backgroundColor',[.92 .92 .92],... | |
291 'Units','normalized',... | |
292 'Position', [.1 .75 .3 .08]) | |
293 uicontrol('Parent',uip3, ... | |
294 'Style','text',... | |
295 'String', 'Sample rate',... | |
296 'HorizontalAlignment', 'left',... | |
297 'FontSize', fontSize,... | |
298 'ForeGroundColor','black',... | |
299 'backgroundColor','w',... | |
300 'Units','normalized',... | |
301 'Position', [.47 .735 .4 .08]) | |
302 | |
303 | |
304 uicontrol('Parent',uip3, ... | |
305 'Style','edit',... | |
306 'Tag', 'f1Edit',... | |
307 'Callback',@valueEdit_Callback, ... | |
308 'Max',1,... | |
309 'String', '',... | |
310 'HorizontalAlignment', 'center',... | |
311 'FontSize', fontSize,... | |
312 'ForeGroundColor','black',... | |
313 'backgroundColor',[.92 .92 .92],... | |
314 'Units','normalized',... | |
315 'Position', [.1 .63 .3 .08]) | |
316 uicontrol('Parent',uip3, ... | |
317 'Style','text',... | |
318 'String', 'f1',... | |
319 'HorizontalAlignment', 'left',... | |
320 'FontSize', fontSize,... | |
321 'ForeGroundColor','black',... | |
322 'backgroundColor','w',... | |
323 'Units','normalized',... | |
324 'Position', [.47 .615 .4 .08]) | |
325 | |
326 uicontrol('Parent',uip3, ... | |
327 'Style','edit',... | |
328 'Tag', 'f2Edit',... | |
329 'Callback',@valueEdit_Callback, ... | |
330 'Max',1,... | |
331 'String', '',... | |
332 'HorizontalAlignment', 'center',... | |
333 'FontSize', fontSize,... | |
334 'ForeGroundColor','black',... | |
335 'backgroundColor',[.92 .92 .92],... | |
336 'Units','normalized',... | |
337 'Position', [.1 .51 .3 .08]) | |
338 uicontrol('Parent',uip3, ... | |
339 'Style','text',... | |
340 'String', 'f2',... | |
341 'HorizontalAlignment', 'left',... | |
342 'FontSize', fontSize,... | |
343 'ForeGroundColor','black',... | |
344 'backgroundColor','w',... | |
345 'Units','normalized',... | |
346 'Position', [.47 .495 .4 .08]) | |
347 | |
348 uicontrol('Parent',uip3, ... | |
349 'Style','edit',... | |
350 'Tag', 'nfEdit',... | |
351 'Callback',@valueEdit_Callback, ... | |
352 'Max',1,... | |
353 'String', '',... | |
354 'HorizontalAlignment', 'center',... | |
355 'FontSize', fontSize,... | |
356 'ForeGroundColor','black',... | |
357 'backgroundColor',[.92 .92 .92],... | |
358 'Units','normalized',... | |
359 'Position', [.1 .39 .3 .08]) | |
360 uicontrol('Parent',uip3, ... | |
361 'Style','text',... | |
362 'String', 'Nf',... | |
363 'HorizontalAlignment', 'left',... | |
364 'FontSize', fontSize,... | |
365 'ForeGroundColor','black',... | |
366 'backgroundColor','w',... | |
367 'Units','normalized',... | |
368 'Position', [.47 .375 .4 .08]) | |
369 | |
370 uicontrol('Parent',uip3, ... | |
371 'Style','pushbutton',... | |
372 'Tag', 'replotBtn',... | |
373 'Callback', @replotBtn_Callback, ... | |
374 'Max',1,... | |
375 'String', 'Replot',... | |
376 'HorizontalAlignment', 'center',... | |
377 'FontSize', fontSize,... | |
378 'ForeGroundColor','black',... | |
379 'backgroundColor',[.92 .92 .92],... | |
380 'Units','normalized',... | |
381 'Position', [.1 .27 .8 .07]) | |
382 | |
383 uicontrol('Parent',uip3, ... | |
384 'Style','pushbutton',... | |
385 'Tag', 'figureBtn',... | |
386 'Callback', @figureBtn_Callback, ... | |
387 'Max',1,... | |
388 'String', 'Figure',... | |
389 'HorizontalAlignment', 'center',... | |
390 'FontSize', fontSize,... | |
391 'ForeGroundColor','black',... | |
392 'backgroundColor',[.92 .92 .92],... | |
393 'Units','normalized',... | |
394 'Position', [.1 .16 .8 .07]) | |
395 | |
396 uicontrol('Parent',uip3, ... | |
397 'Style','pushbutton',... | |
398 'Tag', 'saveAObtn',... | |
399 'Callback', @saveAObtn_Callback, ... | |
400 'Max',1,... | |
401 'String', 'Save as',... | |
402 'HorizontalAlignment', 'center',... | |
403 'FontSize', fontSize,... | |
404 'ForeGroundColor','black',... | |
405 'backgroundColor',[.92 .92 .92],... | |
406 'Units','normalized',... | |
407 'Position', [.1 .05 .8 .07]) | |
408 | |
409 | |
410 | |
411 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
412 %%%%%%%%%%%%%%%%%%%%%%%%%%% SUBFUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
414 | |
415 % --- Executes on button press in addPoleBtn. | |
416 function addPoleBtn_Callback(varargin) | |
417 % hObject handle to addPoleBtn (see GCBO) | |
418 % eventdata reserved - to be defined in a future version of MATLAB | |
419 | |
420 % get values from pzEdit | |
421 strVal = get(findobj(gcf,'Tag','pzEdit'), 'String'); | |
422 val = str2num(strVal); | |
423 f = val(1); | |
424 if length(val) == 2 | |
425 q = val(2); | |
426 p = pz(f,q); | |
427 else | |
428 p = pz(f); | |
429 end | |
430 | |
431 poles = getappdata(gcf, 'poles'); | |
432 poles = [poles p]; | |
433 setappdata(gcf, 'poles', poles); | |
434 | |
435 % update list | |
436 updatePolesList(); | |
437 | |
438 % update model | |
439 updateModelResp(); | |
440 | |
441 end | |
442 | |
443 % --- Executes on button press in addZeroBtn. | |
444 function addZeroBtn_Callback(varargin) | |
445 % hObject handle to addZeroBtn (see GCBO) | |
446 % eventdata reserved - to be defined in a future version of MATLAB | |
447 | |
448 % get values from pzEdit | |
449 strVal = get(findobj(gcf,'tag','pzEdit'), 'String'); | |
450 val = str2num(strVal); | |
451 f = val(1); | |
452 if length(val) == 2 | |
453 q = val(2); | |
454 z = pz(f,q); | |
455 else | |
456 z = pz(f); | |
457 end | |
458 | |
459 zeros = getappdata(gcf, 'zeros'); | |
460 zeros = [zeros z]; | |
461 setappdata(gcf, 'zeros', zeros); | |
462 | |
463 % update list | |
464 updateZerosList(); | |
465 | |
466 % update model | |
467 updateModelResp(); | |
468 | |
469 end | |
470 | |
471 %----------- Update Poles List ----------------------------- | |
472 function updatePolesList(varargin) | |
473 | |
474 poles = getappdata(gcf, 'poles'); | |
475 pstr = []; | |
476 for n=1:length(poles) | |
477 p = poles(n); | |
478 f = p.f; | |
479 q = p.q; | |
480 if q>0.5 | |
481 pstr = strvcat(pstr, sprintf('%2.2f Hz Q=%2.2f', f, q)); | |
482 else | |
483 pstr = strvcat(pstr, sprintf('%2.2f Hz', f)); | |
484 end | |
485 end | |
486 | |
487 if isempty(poles) | |
488 set(findobj(gcf,'tag','poleList'), 'String', ' '); | |
489 else | |
490 set(findobj(gcf,'tag','poleList'), 'String', pstr); | |
491 end | |
492 set(findobj(gcf,'tag','poleList'), 'Value', 1); | |
493 | |
494 end | |
495 | |
496 %----------- Update Zeros List ----------------------------- | |
497 function updateZerosList(varargin) | |
498 | |
499 zeros = getappdata(gcf, 'zeros'); | |
500 pstr = []; | |
501 for n=1:length(zeros) | |
502 p = zeros(n); | |
503 f = p.f; | |
504 q = p.q; | |
505 if q>0.5 | |
506 pstr = strvcat(pstr, sprintf('%2.2f Hz Q=%2.2f', f, q)); | |
507 else | |
508 pstr = strvcat(pstr, sprintf('%2.2f Hz', f)); | |
509 end | |
510 end | |
511 | |
512 if isempty(zeros) | |
513 set(findobj(gcf,'tag','zeroList'), 'String', ' '); | |
514 else | |
515 set(findobj(gcf,'tag','zeroList'), 'String', pstr); | |
516 end | |
517 set(findobj(gcf,'tag','zeroList'), 'Value', 1); | |
518 end | |
519 | |
520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
521 %----------- Update Model response ----------------------------- | |
522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
523 function updateModelResp(varargin) | |
524 | |
525 gain = str2double(get(findobj(gcf,'tag','gainEdit'), 'String')); | |
526 poles = getappdata(gcf, 'poles'); | |
527 zeros = getappdata(gcf, 'zeros'); | |
528 | |
529 pzm = pzmodel(gain, poles, zeros); | |
530 | |
531 f1s = get(findobj(gcf,'tag','f1Edit'), 'String'); | |
532 f2s = get(findobj(gcf,'tag','f2Edit'), 'String'); | |
533 nfs = get(findobj(gcf,'tag','nfEdit'), 'String'); | |
534 fss = get(findobj(gcf,'tag','fsEdit'), 'String'); | |
535 | |
536 if isempty(f1s) | |
537 f1 = getlowerFreq(pzm)/10; | |
538 else | |
539 f1 = str2double(f1s); | |
540 end | |
541 if isempty(f2s) | |
542 f2 = getupperFreq(pzm)*10; | |
543 else | |
544 f2 = str2double(f2s); | |
545 end | |
546 if isempty(nfs) | |
547 nf = 1000; | |
548 else | |
549 nf = str2double(nfs); | |
550 end | |
551 | |
552 if ~isempty(pzm.poles) || ~isempty(pzm.zeros) | |
553 | |
554 % make model response | |
555 a = resp(pzm, f1, f2, nf); | |
556 d = a.data; | |
557 mx = d.x; | |
558 my = d.y; | |
559 | |
560 % make IIR response | |
561 if isempty(fss) | |
562 filt = miir(plist([param('pzmodel', pzm)])); | |
563 else | |
564 filt = miir(plist([param('pzmodel', pzm) param('fs', str2double(fss))])); | |
565 end | |
566 setappdata(gcf, 'filt', filt); | |
567 set(findobj(gcf,'tag','filterStrEdit'), 'String', ['miir(' string(pzm) ')']); | |
568 | |
569 filtresp = resp(filt, plist(param('f', mx.'))); | |
570 d = filtresp.data; | |
571 fx = d.x; | |
572 fy = d.y; | |
573 | |
574 axes(findobj(gcf,'tag','magAxes')); % Select the proper axes | |
575 loglog(mx,abs(my), fx, abs(fy), 'r--') | |
576 grid on; | |
577 axis tight | |
578 xlabel(''); | |
579 ylabel('Magnitude'); | |
580 legend('Pole/Zero model', 'IIR','Location','SouthWest') | |
581 set(gca,'tag','magAxes') | |
582 | |
583 axes(findobj(gcf,'tag','phaseAxes')); % Select the proper axes | |
584 semilogx(mx, utils.math.phase(my), fx, utils.math.phase(fy), 'r--') | |
585 grid on; | |
586 axis tight | |
587 xlabel('Frequency [Hz]'); | |
588 ylabel('Phase [deg]'); | |
589 set(gca,'tag','phaseAxes') | |
590 else | |
591 axes(findobj(gcf,'tag','magAxes')); % Select the proper axes | |
592 cla | |
593 axes(findobj(gcf,'tag','phaseAxes')); % Select the proper axes | |
594 cla | |
595 end | |
596 | |
597 end | |
598 | |
599 function valueEdit_Callback(varargin) | |
600 updateModelResp() | |
601 end | |
602 | |
603 % --- Executes on button press in replotBtn. | |
604 function replotBtn_Callback(varargin) | |
605 updateModelResp() | |
606 end | |
607 | |
608 % --- Executes on button press in figureBtn. | |
609 function figureBtn_Callback(varargin) | |
610 | |
611 gain = str2double(get(findobj(gcf,'tag','gainEdit'), 'String')); | |
612 poles = getappdata(gcf, 'poles'); | |
613 zeros = getappdata(gcf, 'zeros'); | |
614 | |
615 pzm = pzmodel(gain, poles, zeros); | |
616 | |
617 f1s = get(findobj(gcf,'tag','f1Edit'), 'String'); | |
618 f2s = get(findobj(gcf,'tag','f2Edit'), 'String'); | |
619 nfs = get(findobj(gcf,'tag','nfEdit'), 'String'); | |
620 fss = get(findobj(gcf,'tag','fsEdit'), 'String'); | |
621 | |
622 if isempty(f1s) | |
623 f1 = getlowerFreq(pzm)/10; | |
624 else | |
625 f1 = str2double(f1s); | |
626 end | |
627 if isempty(f2s) | |
628 f2 = getupperFreq(pzm)*10; | |
629 else | |
630 f2 = str2double(f2s); | |
631 end | |
632 if isempty(nfs) | |
633 nf = 1000; | |
634 else | |
635 nf = str2double(nfs); | |
636 end | |
637 | |
638 % make model response | |
639 a = resp(pzm, f1, f2, nf); | |
640 a.setName('PZmodel'); | |
641 | |
642 % make IIR response | |
643 if isempty(fss) | |
644 filt = miir(plist([param('pzmodel', pzm)])); | |
645 else | |
646 filt = miir(plist([param('pzmodel', pzm) param('fs', str2double(fss))])); | |
647 end | |
648 | |
649 | |
650 filtresp = resp(filt, plist(param('f', a.data.getX))); | |
651 filtresp.setName('IIR filter'); | |
652 | |
653 iplot(a, filtresp) | |
654 end | |
655 | |
656 % --- Executes on button press in clearBtn. | |
657 function clearBtn_Callback(varargin) | |
658 | |
659 setappdata(gcf, 'poles', []); | |
660 setappdata(gcf, 'zeros', []); | |
661 | |
662 % update list | |
663 updateZerosList(); | |
664 updatePolesList(); | |
665 | |
666 % update model | |
667 updateModelResp(); | |
668 end | |
669 | |
670 | |
671 % --- Executes on button press in deletePolesBtn. | |
672 function deletePolesBtn_Callback(varargin) | |
673 | |
674 % get selection from list | |
675 values = get(findobj(gcf,'tag','poleList'), 'Value'); | |
676 % get poles | |
677 poles = getappdata(gcf, 'poles'); | |
678 po = []; | |
679 for j=1:length(poles) | |
680 if j~=values | |
681 po = [po poles(j)]; %#ok<AGROW> | |
682 end | |
683 end | |
684 setappdata(gcf, 'poles', po); | |
685 updatePolesList(); | |
686 % update model | |
687 updateModelResp(); | |
688 | |
689 end | |
690 | |
691 % --- Executes on button press in deleteZerosBtn. | |
692 function deleteZerosBtn_Callback(varargin) | |
693 | |
694 % get selection from list | |
695 values = get(findobj(gcf,'tag','zeroList'), 'Value'); | |
696 % get zeros | |
697 zeros = getappdata(gcf, 'zeros'); | |
698 zo = []; | |
699 for j=1:length(zeros) | |
700 if j~=values | |
701 zo = [zo zeros(j)]; %#ok<AGROW> | |
702 end | |
703 end | |
704 setappdata(gcf, 'zeros', zo); | |
705 updateZerosList(); | |
706 % update model | |
707 updateModelResp(); | |
708 end | |
709 | |
710 % --- Executes on button press in saveAObtn. | |
711 function saveAObtn_Callback(varargin) | |
712 | |
713 % get response | |
714 gain = str2double(get(findobj(gcf,'tag','gainEdit'), 'String')); | |
715 poles = getappdata(gcf, 'poles'); | |
716 zeros = getappdata(gcf, 'zeros'); | |
717 pzm = pzmodel(gain, poles, zeros); | |
718 | |
719 f1s = get(findobj(gcf,'tag','f1Edit'), 'String'); | |
720 f2s = get(findobj(gcf,'tag','f2Edit'), 'String'); | |
721 nfs = get(findobj(gcf,'tag','nfEdit'), 'String'); | |
722 fss = get(findobj(gcf,'tag','fsEdit'), 'String'); | |
723 | |
724 if isempty(f1s) | |
725 f1 = getlowerFreq(pzm)/10; | |
726 else | |
727 f1 = str2double(f1s); | |
728 end | |
729 if isempty(f2s) | |
730 f2 = getupperFreq(pzm)*10; | |
731 else | |
732 f2 = str2double(f2s); | |
733 end | |
734 if isempty(nfs) | |
735 nf = 1000; | |
736 else | |
737 nf = str2double(nfs); | |
738 end | |
739 | |
740 % make model response | |
741 a = resp(pzm, f1, f2, nf); | |
742 | |
743 % Get filename | |
744 [filename, pathname] = uiputfile('*.xml', 'LTPDA XML file (*.xml)', 'Save as'); | |
745 if isequal(filename,0) || isequal(pathname,0) | |
746 else | |
747 fname = fullfile(pathname, filename); | |
748 save(a, fname); | |
749 end | |
750 end | |
751 | |
752 | |
753 end |