Mercurial > hg > ltpda
comparison m-toolbox/sltpda/getBlockCommands.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 cmds = getBlockCommands(blocks) | |
2 | |
3 % GETBLOCKCOMMANDS get a set of commands from a set of sLTPDA blocks. | |
4 % | |
5 % M Hewitson 27-03-07 | |
6 % | |
7 | |
8 | |
9 disp(' + compiling block list'); | |
10 | |
11 cmds = []; | |
12 | |
13 for j=1:length(blocks) | |
14 b = blocks(j); | |
15 blocktype = get(b, 'BlockType'); | |
16 maskType = get(b, 'MaskType'); | |
17 name = get(b, 'Name'); | |
18 if ~strcmp(name, 'variable') | |
19 parent = get(b, 'Parent'); | |
20 name = [parent '_' name]; | |
21 name = sltpda_reduceVarName(name); | |
22 | |
23 if ~strcmp(blocktype, 'Outport') && ~strcmp(blocktype, 'Inport') && ~strcmp(maskType, 'loop') | |
24 fcn = getFcnName(b); | |
25 if ~isempty(fcn) | |
26 | |
27 % Get my inputs and outputs | |
28 [inames, onames] = getIOnames(get(b, 'PortHandles'), name); | |
29 | |
30 % Get my parameters | |
31 [params, pl] = getParameters(b); | |
32 | |
33 % Form command | |
34 % cmd = buildCmd(inames, onames, params, fcn); | |
35 cmd = sltpda_buildCmd(inames, onames, params, fcn); | |
36 | |
37 % store info | |
38 info.fcn = fcn; | |
39 info.params = params; | |
40 info.plist = pl; | |
41 info.ins = inames; | |
42 info.outs = onames; | |
43 info.outsUsed = []; | |
44 info.cmd = cmd; | |
45 info.name = get(b, 'Name'); | |
46 info.handle = get(b, 'Handle'); | |
47 info.ranges = []; | |
48 | |
49 cmds = [cmds info]; | |
50 end | |
51 end | |
52 end | |
53 end | |
54 | |
55 | |
56 %-------------------------------------------------------------------------- | |
57 % Get parameters from block mask | |
58 % | |
59 % MaskPromptString, MaskVariables, MaskValueString | |
60 % | |
61 function [params, pl] = getParameters(block) | |
62 | |
63 params = []; | |
64 pl = plist(); | |
65 try | |
66 maskType = get(block, 'MaskType'); | |
67 end | |
68 | |
69 if ~isempty(maskType) | |
70 switch maskType | |
71 | |
72 case 'ltpda_tfe' | |
73 [params, pl] = get_ltpda_tfe_params(block); | |
74 case 'ltpda_pwelch' | |
75 [params, pl] = get_ltpda_pwelch_params(block); | |
76 case 'plot' | |
77 [params, pl] = get_plot_params(block); | |
78 case 'ao' | |
79 [params, pl] = get_ao_params(block); | |
80 case 'filter' | |
81 [params, pl] = get_filter_params(block); | |
82 case 'get' | |
83 [params, pl] = get_get_params(block); | |
84 case 'rdivide' | |
85 [params, pl] = get_mrdivide_params(block); | |
86 case 'minus' | |
87 [params, pl] = get_minus_params(block); | |
88 case 'plus' | |
89 [params, pl] = get_plus_params(block); | |
90 case 'times' | |
91 [params, pl] = get_mtimes_params(block); | |
92 case 'sqrt' | |
93 [params, pl] = get_sqrt_params(block); | |
94 case 'abs' | |
95 [params, pl] = get_abs_params(block); | |
96 case 'split' | |
97 [params, pl] = get_split_params(block); | |
98 case 'demux' | |
99 [params, pl] = get_demux_params(block); | |
100 case 'ltpda_timedomainfit' | |
101 [params, pl] = get_ltpda_timedomainfit_params(block); | |
102 case 'ltpda_lincom' | |
103 [params, pl] = get_ltpda_lincom_params(block); | |
104 case 'ltpda_polydetrend' | |
105 [params, pl] = get_ltpda_polydetrend_params(block); | |
106 case 'ltpda_lpsd' | |
107 [params, pl] = get_ltpda_lpsd_params(block); | |
108 case 'save' | |
109 [params, pl] = get_save_params(block); | |
110 case 'resample' | |
111 [params, pl] = get_resample_params(block); | |
112 case 'pzmresp' | |
113 [params, pl] = get_pzmresp_params(block); | |
114 case 'convert' | |
115 [params, pl] = get_convert_params(block); | |
116 case 'param' | |
117 [params, pl] = get_param_params(block); | |
118 case 'iparam' | |
119 [params, pl] = get_iparam_params(block); | |
120 case 'specwin' | |
121 [params, pl] = get_specwin_params(block); | |
122 case 'plist' | |
123 [params, pl] = get_plist_params(block); | |
124 case 'display' | |
125 pl = []; | |
126 params = ''; | |
127 case 'pole' | |
128 [params, pl] = get_pole_params(block); | |
129 case 'zero' | |
130 [params, pl] = get_zero_params(block); | |
131 case 'pzmodel' | |
132 [params, pl] = get_pzmodel_params(block); | |
133 case 'resp' | |
134 [params, pl] = get_resp_params(block); | |
135 case 'miir' | |
136 [params, pl] = get_miir_params(block); | |
137 case 'iirResp' | |
138 [params, pl] = get_iirResp_params(block); | |
139 otherwise | |
140 warning(['### unknown mask type ' maskType]); | |
141 end | |
142 else | |
143 pl = plist(); | |
144 params = []; | |
145 end | |
146 | |
147 %-------------------------------------------------------------------------- | |
148 % Get parameters for abs block. | |
149 % | |
150 function [params, pl] = get_abs_params(block) | |
151 | |
152 % build output | |
153 pl = plist(); | |
154 params = ''; | |
155 | |
156 %-------------------------------------------------------------------------- | |
157 % Get parameters for iirResp block. | |
158 % | |
159 function [params, pl] = get_iirResp_params(block) | |
160 | |
161 f1 = get(block, 'f1'); | |
162 f2 = get(block, 'f2'); | |
163 nf = get(block, 'nf'); | |
164 | |
165 if isempty(f1) | |
166 f1 = '[]'; | |
167 end | |
168 if isempty(f2) | |
169 f2 = '[]'; | |
170 end | |
171 if isempty(nf) | |
172 nf = '[]'; | |
173 end | |
174 % build output | |
175 pl = plist( [param('f1', eval(f1)) param('f2', eval(f2)) param('nf', eval(nf))] ); | |
176 params = string(pl); | |
177 | |
178 %-------------------------------------------------------------------------- | |
179 % Get parameters for miir block. | |
180 % | |
181 function [params, pl] = get_miir_params(block) | |
182 | |
183 fs = get(block, 'fs'); | |
184 | |
185 if isempty(fs) | |
186 fs = '[]'; | |
187 end | |
188 % build output | |
189 pl = plist( param('fs', eval(fs)) ); | |
190 params = string(pl); | |
191 | |
192 %-------------------------------------------------------------------------- | |
193 % Get parameters for resp block. | |
194 % | |
195 function [params, pl] = get_resp_params(block) | |
196 | |
197 f1 = get(block, 'f1'); | |
198 f2 = get(block, 'f2'); | |
199 nf = get(block, 'nf'); | |
200 scale = get(block, 'scale'); | |
201 | |
202 if isempty(f1) | |
203 f1 = '[]'; | |
204 end | |
205 if isempty(f2) | |
206 f2 = '[]'; | |
207 end | |
208 if isempty(nf) | |
209 nf = '[]'; | |
210 end | |
211 % build output | |
212 pl = plist( [param('f1', eval(f1)) param('f2', eval(f2)) param('nf', eval(nf)) param('scale', scale)] ); | |
213 params = string(pl); | |
214 | |
215 | |
216 %-------------------------------------------------------------------------- | |
217 % Get parameters for pzmodel block. | |
218 % | |
219 function [params, pl] = get_pzmodel_params(block) | |
220 | |
221 % build output | |
222 pl = plist(); | |
223 params = ''; | |
224 | |
225 %-------------------------------------------------------------------------- | |
226 % Get parameters for zero block. | |
227 % | |
228 function [params, pl] = get_zero_params(block) | |
229 | |
230 f = get(block, 'zerof'); | |
231 q = get(block, 'zeroQ'); | |
232 if isempty(q) | |
233 q = '0'; | |
234 end | |
235 | |
236 % build output | |
237 pl = plist( [param('f', eval(f)) param('q', eval(q))] ); | |
238 params = string(pl); | |
239 | |
240 | |
241 %-------------------------------------------------------------------------- | |
242 % Get parameters for pole block. | |
243 % | |
244 function [params, pl] = get_pole_params(block) | |
245 | |
246 f = get(block, 'polef'); | |
247 q = get(block, 'poleQ'); | |
248 if isempty(q) | |
249 q = '0'; | |
250 end | |
251 | |
252 % build output | |
253 pl = plist( [param('f', eval(f)) param('q', eval(q))] ); | |
254 params = string(pl); | |
255 | |
256 | |
257 %-------------------------------------------------------------------------- | |
258 % Get parameters for plist block. | |
259 % | |
260 function [params, pl] = get_plist_params(block) | |
261 | |
262 % build output | |
263 pl = plist(); | |
264 params = ''; | |
265 | |
266 %-------------------------------------------------------------------------- | |
267 % Get parameters for iparam block. | |
268 % | |
269 function [params, pl] = get_iparam_params(block) | |
270 | |
271 key = get(block, 'key'); | |
272 | |
273 | |
274 % build output | |
275 pl = plist(param(key, -1)); | |
276 params = string(pl); | |
277 | |
278 | |
279 %-------------------------------------------------------------------------- | |
280 % Get parameters for specwin block. | |
281 % | |
282 function [params, pl] = get_specwin_params(block) | |
283 | |
284 name = get(block, 'wname'); | |
285 N = get(block, 'wlen'); | |
286 psll = get(block, 'psll'); | |
287 | |
288 % check what value is | |
289 | |
290 | |
291 % build output | |
292 pl = plist([param('Name', name) param('N', eval(N)) param('PSLL', eval(psll))]); | |
293 params = string(pl); | |
294 | |
295 %-------------------------------------------------------------------------- | |
296 % Get parameters for param block. | |
297 % | |
298 function [params, pl] = get_param_params(block) | |
299 | |
300 key = get(block, 'key'); | |
301 val = get(block, 'val'); | |
302 | |
303 | |
304 % build output | |
305 pl = plist([param('key', key) param('val', eval(val))]); | |
306 params = string(pl); | |
307 | |
308 %-------------------------------------------------------------------------- | |
309 % Get parameters for convert block. | |
310 % | |
311 function [params, pl] = get_convert_params(block) | |
312 | |
313 pl = plist(); | |
314 params = ''; | |
315 | |
316 %-------------------------------------------------------------------------- | |
317 % Get parameters for pzmresp block. | |
318 % | |
319 function [params, pl] = get_pzmresp_params(block) | |
320 | |
321 f1 = get(block, 'f1'); | |
322 f2 = get(block, 'f2'); | |
323 nf = get(block, 'nf'); | |
324 pzm = get(block, 'pzm'); | |
325 | |
326 pl = plist(); | |
327 if ~isempty(f1) | |
328 pl = append(pl, param('f1', str2double(f1))); | |
329 end | |
330 if ~isempty(f2) | |
331 pl = append(pl, param('f2', str2double(f2))); | |
332 end | |
333 if ~isempty(nf) | |
334 pl = append(pl, param('nf', str2double(nf))); | |
335 end | |
336 if ~isempty(pzm) | |
337 pl = append(pl, param('pzmodel', eval(pzm))); | |
338 else | |
339 error('### pole/zero constructor is empty.'); | |
340 end | |
341 params = string(pl); | |
342 | |
343 | |
344 %-------------------------------------------------------------------------- | |
345 % Get parameters for resample block. | |
346 % | |
347 function [params, pl] = get_resample_params(block) | |
348 | |
349 fsout = get(block, 'fsout'); | |
350 pl = plist(); | |
351 pl = append(pl, param('fsout', str2double(fsout))); | |
352 params = string(pl); | |
353 | |
354 %-------------------------------------------------------------------------- | |
355 % Get parameters for save block. | |
356 % | |
357 function [params, pl] = get_save_params(block) | |
358 | |
359 fname = get(block, 'fname'); | |
360 pl = plist(); | |
361 pl = append(pl, param('filename', fname)); | |
362 params = string(pl); | |
363 | |
364 | |
365 %-------------------------------------------------------------------------- | |
366 % Get parameters for ltpda_lpsd block. | |
367 % | |
368 function [params, pl] = get_ltpda_lpsd_params(block) | |
369 | |
370 Kdes = str2double(get(block, 'Kdes')); | |
371 Kmin = str2double(get(block, 'Kmin')); | |
372 Jdes = str2double(get(block, 'Jdes')); | |
373 Win = get(block, 'win'); | |
374 nolap = str2double(get(block, 'olap')); | |
375 psll = str2double(get(block, 'psll')); | |
376 | |
377 params = []; | |
378 pl = plist(param('Kdes', Kdes)); | |
379 pl = append(pl, param('Kmin', Kmin)); | |
380 pl = append(pl, param('Jdes', Jdes)); | |
381 | |
382 nfft = 10; | |
383 switch Win | |
384 case 'Kaiser' | |
385 if psll <=0 | |
386 error('### ltpda_lpsd block: please specify PSLL for Kaiser window.') | |
387 end | |
388 p = sprintf('specwin(''Kaiser'', %f, %f)', nfft, psll); | |
389 case 'Hanning' | |
390 p = sprintf('specwin(''Hanning'', %f)', nfft); | |
391 otherwise | |
392 error('### ltpda_lpsd block: Unknown window name.'); | |
393 end | |
394 | |
395 pl = append(pl, param('win', eval(p))); | |
396 if nolap > 0 | |
397 pl = append(pl, param('Olap', nolap)); | |
398 end | |
399 | |
400 params = string(pl); | |
401 | |
402 | |
403 %-------------------------------------------------------------------------- | |
404 % Get parameters for ltpda_polydetrend block. | |
405 % | |
406 function [params, pl] = get_ltpda_polydetrend_params(block) | |
407 | |
408 N = get(block, 'degree'); | |
409 | |
410 params = []; | |
411 pl = plist(param('N', N)); | |
412 params = string(pl); | |
413 | |
414 | |
415 | |
416 %-------------------------------------------------------------------------- | |
417 % Get parameters for ltpda_lincom block. | |
418 % | |
419 function [params, pl] = get_ltpda_lincom_params(block) | |
420 | |
421 | |
422 coeffs = get(block, 'coeffs'); | |
423 | |
424 params = []; | |
425 pl = plist(param('coeffs', coeffs)); | |
426 params = string(pl); | |
427 | |
428 | |
429 %-------------------------------------------------------------------------- | |
430 % Get parameters for ltpda_timedomainfit block. | |
431 % | |
432 function [params, pl] = get_ltpda_timedomainfit_params(block) | |
433 | |
434 params = []; | |
435 pl = plist(); | |
436 | |
437 | |
438 %-------------------------------------------------------------------------- | |
439 % Get parameters for demux block. | |
440 % | |
441 function [params, pl] = get_demux_params(block) | |
442 | |
443 params = []; | |
444 pl = plist(); | |
445 | |
446 %-------------------------------------------------------------------------- | |
447 % Get parameters for sqrt block. | |
448 % | |
449 function [params, pl] = get_split_params(block) | |
450 | |
451 method = get(block, 'method'); | |
452 splits = get(block, 'splits'); | |
453 | |
454 pl = plist(); | |
455 pl = append(pl, param(method, str2num(splits) )); | |
456 params = string(pl); | |
457 | |
458 | |
459 %-------------------------------------------------------------------------- | |
460 % Get parameters for sqrt block. | |
461 % | |
462 function [params, pl] = get_sqrt_params(block) | |
463 | |
464 pl = plist(); | |
465 params = []; | |
466 | |
467 %-------------------------------------------------------------------------- | |
468 % Get parameters for mrdivide block. | |
469 % | |
470 function [params, pl] = get_mrdivide_params(block) | |
471 | |
472 pl = plist(); | |
473 params = []; | |
474 | |
475 %-------------------------------------------------------------------------- | |
476 % Get parameters for mtimes block. | |
477 % | |
478 function [params, pl] = get_mtimes_params(block) | |
479 | |
480 pl = plist(); | |
481 params = []; | |
482 | |
483 %-------------------------------------------------------------------------- | |
484 % Get parameters for minus block. | |
485 % | |
486 function [params, pl] = get_minus_params(block) | |
487 | |
488 pl = plist(); | |
489 params = []; | |
490 | |
491 %-------------------------------------------------------------------------- | |
492 % Get parameters for plus block. | |
493 % | |
494 function [params, pl] = get_plus_params(block) | |
495 | |
496 pl = plist(); | |
497 params = []; | |
498 | |
499 %-------------------------------------------------------------------------- | |
500 % Get parameters for get block. | |
501 % | |
502 function [params, pl] = get_get_params(block) | |
503 | |
504 pl = plist(); | |
505 params = ['''' get(block, 'param') '''']; | |
506 | |
507 %-------------------------------------------------------------------------- | |
508 % Get parameters for filter block. | |
509 % | |
510 function [params, pl] = get_filter_params(block) | |
511 | |
512 | |
513 % first we try for a standard filter | |
514 fname = []; | |
515 ftype = []; | |
516 try | |
517 ftype = get(block, 'ftype'); | |
518 fgain = get(block, 'fgain'); | |
519 ffc = get(block, 'ffc'); | |
520 forder = get(block, 'forder'); | |
521 % we design for 4*ffc and adjust later when | |
522 % we know the fs of the input data | |
523 fc = str2num(ffc); | |
524 ffs = 4*fc(end); | |
525 catch | |
526 try | |
527 fname = get(block, 'fname'); | |
528 catch | |
529 end | |
530 end | |
531 | |
532 | |
533 % start plist | |
534 pl = plist(); | |
535 if isempty(fname) | |
536 | |
537 % if not a standard filter, then a pole/zero filter | |
538 if isempty(ftype) | |
539 | |
540 miirstr = get(block, 'miirstr'); | |
541 eval(['pzm = ' miirstr ';']); | |
542 pl = plist(param('filter', miir(plist(param('pzmodel', pzm))))); | |
543 params = string(pl); | |
544 | |
545 % else a standard filter | |
546 else | |
547 | |
548 % build standard filter | |
549 if strcmp(ftype, 'bandpass') || strcmp(ftype, 'bandreject') | |
550 if length(str2num(ffc)) ~= 2 | |
551 error('### supply upper and lower frequency for bandpass and bandreject filters.'); | |
552 end | |
553 end | |
554 | |
555 fpl = plist(); | |
556 fpl = append(fpl, param('type', ftype)); | |
557 fpl = append(fpl, param('gain', str2double(fgain))); | |
558 % fpl = append(fpl, param('fs', (ffs))); | |
559 fpl = append(fpl, param('fc', [str2num(ffc)])); | |
560 fpl = append(fpl, param('order', [str2num(forder)])); | |
561 | |
562 pl = plist(param('filter', miir(fpl))); | |
563 params = string(pl); | |
564 end | |
565 else | |
566 pl = plist(param('filter', miir(fname))); | |
567 params = string(pl); | |
568 end | |
569 | |
570 %-------------------------------------------------------------------------- | |
571 % Get parameters for ao block. | |
572 % | |
573 function [params, pl] = get_ao_params(block) | |
574 | |
575 fname = []; | |
576 vals = []; | |
577 fcn = []; | |
578 tsfcn = []; | |
579 waveform = []; | |
580 try fname = get(block, 'fname'); end; | |
581 try vals = get(block, 'vals'); end; | |
582 try fcn = get(block, 'fcn'); end; | |
583 try tsfcn = get(block, 'tsfcn'); end; | |
584 try waveform = get(block, 'waveform'); end; | |
585 | |
586 % execute | |
587 if ~isempty(fname) | |
588 pl = plist(); | |
589 pl = append(pl, param('filename', fname)); | |
590 params = string(pl); | |
591 elseif ~isempty(vals) | |
592 pl = plist(param('vals', str2num(vals))); | |
593 params = string(pl); | |
594 elseif ~isempty(fcn) | |
595 pl = plist(param('fcn', fcn)); | |
596 params = string(pl); | |
597 elseif ~isempty(tsfcn) | |
598 nsecs = sltpda_getvar(block, 'nsecs'); | |
599 fs = sltpda_getvar(block, 'fs'); | |
600 pl = plist(); | |
601 pl = append(pl, param('nsecs', nsecs)); | |
602 pl = append(pl, param('fs', fs)); | |
603 pl = append(pl, param('tsfcn', tsfcn)); | |
604 params = string(pl); | |
605 elseif ~isempty(waveform) | |
606 | |
607 switch waveform | |
608 %------------ Sine Wave | |
609 case 'sine wave' | |
610 freq = get(block, 'freq'); | |
611 phi = get(block, 'phi'); | |
612 tsfcn = sprintf('sin(2*pi*%f*t + %f*pi/180)', eval(freq), eval(phi)); | |
613 %------------ Noise | |
614 case 'noise' | |
615 ntype = get(block, 'ntype'); | |
616 switch ntype | |
617 case 'Normal' | |
618 tsfcn = 'randn(size(t))'; | |
619 case 'Uniform' | |
620 tsfcn = 'rand(size(t))'; | |
621 end | |
622 %------------ Chirp | |
623 case 'chirp' | |
624 f0 = get(block, 'chirp_f0'); | |
625 fe = get(block, 'chirp_fe'); | |
626 te = get(block, 'chirp_te'); | |
627 tsfcn = sprintf('chirp(t,%f,%f,%f)', eval(f0), eval(fe), eval(te)) | |
628 %------------ Gaussian pulse | |
629 case 'Gaussian pulse' | |
630 fc = get(block, 'gp_f0'); | |
631 bw = get(block, 'gp_bw'); | |
632 tsfcn = sprintf('gauspuls(t,%f,%f)', eval(fc), eval(bw)); | |
633 case 'Square wave' | |
634 freq = get(block, 'freq'); | |
635 duty = get(block, 'square_duty'); | |
636 tsfcn = sprintf('square(2*pi*%f*t,%f)', eval(freq), eval(duty)); | |
637 case 'Sawtooth' | |
638 freq = get(block, 'freq'); | |
639 width = get(block, 'sawtooth_width'); | |
640 tsfcn = sprintf('sawtooth(2*pi*%f*t,%f)', eval(freq), eval(width)); | |
641 end | |
642 pl = plist(); | |
643 pl = append(pl, param('tsfcn', tsfcn)); | |
644 params = string(pl); | |
645 else | |
646 error('### unknown parameter method for AO construction.'); | |
647 end | |
648 | |
649 %-------------------------------------------------------------------------- | |
650 % Get parameters for plot block. | |
651 % | |
652 function [params, pl] = get_plot_params(block) | |
653 | |
654 pl = plist(); | |
655 | |
656 xscale = get(block, 'xscale'); | |
657 yscale = get(block, 'yscale'); | |
658 | |
659 params = []; | |
660 | |
661 | |
662 %-------------------------------------------------------------------------- | |
663 % Get parameters for ltpda_pwelch block. | |
664 % | |
665 function [params, pl] = get_ltpda_pwelch_params(block) | |
666 | |
667 pl = plist(); | |
668 | |
669 nfft = get(block, 'Nfft'); | |
670 nolap = get(block, 'Nolap'); | |
671 | |
672 if isempty(nfft) | |
673 nfft = 0; | |
674 else | |
675 nfft = str2double(nfft); | |
676 end | |
677 if isempty(nolap) | |
678 nolap = 0; | |
679 else | |
680 nolap = str2double(nolap); | |
681 end | |
682 | |
683 pl = plist(); | |
684 if nfft > 0 | |
685 pl = append(pl, param('Nfft', nfft)); | |
686 end | |
687 if nolap > 0 | |
688 pl = append(pl, param('Nolap', nolap)); | |
689 end | |
690 params = string(pl); | |
691 | |
692 %-------------------------------------------------------------------------- | |
693 % Get parameters for ltpda_tfe block. | |
694 % | |
695 function [params, pl] = get_ltpda_tfe_params(block) | |
696 | |
697 winname = get(block, 'win'); | |
698 nfft = get(block, 'nfft'); | |
699 nolap = get(block, 'nolap'); | |
700 psll = get(block, 'psll'); | |
701 | |
702 if isempty(nfft) | |
703 nfft = 0; | |
704 else | |
705 nfft = str2double(nfft); | |
706 end | |
707 if isempty(nolap) | |
708 nolap = 0; | |
709 else | |
710 nolap = str2double(nolap); | |
711 end | |
712 if isempty(psll) | |
713 psll = 0; | |
714 else | |
715 psll = str2double(psll); | |
716 end | |
717 | |
718 switch winname | |
719 case 'Kaiser' | |
720 if psll <=0 | |
721 error('### ltpda_tfe block: please specify PSLL for Kaiser window.') | |
722 end | |
723 p = sprintf('specwin(''Kaiser'', %f, %f)', nfft, psll); | |
724 case 'Hanning' | |
725 p = sprintf('specwin(''Hanning'', %f)', nfft); | |
726 otherwise | |
727 error('### ltpda_tfe block: Unknown window name.'); | |
728 end | |
729 | |
730 pl = plist(); | |
731 pl = append(pl, param('Nfft', nfft)); | |
732 pl = append(pl, param('Win', eval(p))); | |
733 if nolap > 0 | |
734 pl = append(pl, param('Nolap', nolap)); | |
735 end | |
736 params = string(pl); | |
737 | |
738 %-------------------------------------------------------------------------- | |
739 % Build command string | |
740 % | |
741 function cmd = buildCmd(inames, onames, params, fcn) | |
742 | |
743 cmd = ''; | |
744 | |
745 % add outputs | |
746 if ~isempty(onames) | |
747 cmd = [cmd '[']; | |
748 for k=1:length(onames) | |
749 cmd = [cmd onames{k} ',']; | |
750 end | |
751 cmd = [cmd(1:end-1) ']']; | |
752 cmd = [cmd ' = ']; | |
753 end | |
754 | |
755 % add fcn name | |
756 cmd = [cmd fcn]; | |
757 | |
758 % add inputs | |
759 cmd = [cmd '(']; | |
760 if ~isempty(inames) | |
761 for k=1:length(inames) | |
762 cmd = [cmd inames{k} ',']; | |
763 end | |
764 end | |
765 | |
766 % add parameters | |
767 if ~isempty(params) | |
768 cmd = [cmd params]; | |
769 else | |
770 cmd = cmd(1:end-1); | |
771 end | |
772 | |
773 cmd = [cmd ')']; | |
774 cmd = [cmd ';']; | |
775 | |
776 %-------------------------------------------------------------------------- | |
777 % get function name from block handle | |
778 function fcn = getFcnName(b) | |
779 | |
780 blocktype = get(b, 'blocktype'); | |
781 if ~strcmp(blocktype, 'Outport') && ~ strcmp(blocktype, 'Inport') | |
782 name = get(b, 'Name'); | |
783 masktype = get(b, 'MaskType'); | |
784 | |
785 if isempty(masktype) && ~strcmp(blocktype, 'SubSystem') | |
786 fcn = name; | |
787 else | |
788 fcn = masktype; | |
789 end | |
790 | |
791 % Some overrides to this | |
792 switch blocktype | |
793 case 'Sum' | |
794 fcn = 'plus'; | |
795 case 'Mux' | |
796 fcn = 'mux'; | |
797 case 'Demux'; | |
798 fcn = 'demux'; | |
799 end | |
800 | |
801 % Some function replacements | |
802 switch fcn | |
803 case 'plot' | |
804 fcn = 'figure,plot'; | |
805 case 'filter' | |
806 fcn = get(b, 'method'); | |
807 case 'convert' | |
808 fcn = get(b, 'fcn'); | |
809 case 'iparam' | |
810 fcn = 'param'; | |
811 end | |
812 fcn = sltpda_fixvar(fcn); | |
813 end | |
814 | |
815 %-------------------------------------------------------------------------- | |
816 function [inames, onames] = getIOnames(myports, name) | |
817 | |
818 % Get my inputs | |
819 inames = []; | |
820 | |
821 ins = myports.Inport; | |
822 % get name of each input | |
823 for k=1:length(ins) | |
824 ip = ins(k); | |
825 lineState = get(ip, 'Line'); | |
826 pn = get(ip, 'PortNumber'); | |
827 if lineState == -1 | |
828 inames = [inames cellstr('[]')]; | |
829 else | |
830 pstr = strrep([name '_in_' num2str(pn)], ' ', '_'); | |
831 pstr = sltpda_fixvar(pstr); | |
832 inames = [inames cellstr(pstr)]; | |
833 end | |
834 end | |
835 | |
836 % Get my outputs | |
837 onames = []; | |
838 outs = myports.Outport; | |
839 % get name of each output | |
840 for k=1:length(outs) | |
841 op = outs(k); | |
842 pn = get(op, 'PortNumber'); | |
843 pstr = strrep([name '_out_' num2str(pn)], ' ', '_'); | |
844 pstr = sltpda_fixvar(pstr); | |
845 onames = [onames cellstr(pstr)]; | |
846 end | |
847 | |
848 |