comparison testing/utp_1.1/utps/mfir/utp_mfir_resp.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents
children
comparison
equal deleted inserted replaced
43:bc767aaa99a8 44:409a22968d5e
1 % UTP_MFIR_RESP a set of UTPs for the mfir/resp method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_mfir_resp.m,v 1.6 2010/03/15 15:57:06 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The resp method of the mfir class Make a frequency response of the filter.
11 % For a command with no output variables plots the method the result into a
12 % diagram.
13 %
14 % </MethodDescription>
15
16 function results = utp_mfir_resp(varargin)
17
18 % Check the inputs
19 if nargin == 0
20
21 % Some keywords
22 class = 'mfir';
23 mthd = 'resp';
24
25 results = [];
26 disp('******************************************************');
27 disp(['**** Running UTPs for ' class '/' mthd]);
28 disp('******************************************************');
29
30 % Test MFIR objects
31 [fir1,fir2,fir3,fir4,fir5,fir6,firv,firm] = get_test_objects_mfir;
32
33 % Exception list for the UTPs:
34 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
35
36 % Run the tests
37 results = [results utp_01]; % getInfo call
38 results = [results utp_02]; % Vector input
39 results = [results utp_03]; % Matrix input
40 results = [results utp_04]; % List input
41 results = [results utp_05]; % Test with mixed input
42 results = [results utp_06]; % Test history is working
43 results = [results utp_07]; % Test the modify call works
44 results = [results utp_08]; % Test input data shape == output data shape
45 results = [results utp_09]; % Test output of the data
46 results = [results utp_10]; % Test with f = ao.y
47 results = [results utp_11]; % Test with f
48 results = [results utp_12]; % Test with f1, f2 and nf
49 results = [results utp_13]; % Test with f1, f2 and nf AND 'scale'
50 results = [results utp_14]; % Test serial bank
51 results = [results utp_15]; % Test parallel bank
52
53 % Make surethat all figures are closed
54 close all;
55
56 disp('Done.');
57 disp('******************************************************');
58
59 elseif nargin == 1 % Check for UTP functions
60 if strcmp(varargin{1}, 'isutp')
61 results = 1;
62 else
63 results = 0;
64 end
65 else
66 error('### Incorrect inputs')
67 end
68
69 %% UTP_01
70
71 % <TestDescription>
72 %
73 % Tests that the getInfo call works for this method.
74 %
75 % </TestDescription>
76 function result = utp_01
77
78
79 % <SyntaxDescription>
80 %
81 % Test that the getInfo call works for no sets, all sets, and each set
82 % individually.
83 %
84 % </SyntaxDescription>
85
86 try
87 % <SyntaxCode>
88 % Call for no sets
89 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
90 % Call for all sets
91 io(2) = eval([class '.getInfo(''' mthd ''')']);
92 % Call for each set
93 for kk=1:numel(io(2).sets)
94 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
95 end
96 % </SyntaxCode>
97 stest = true;
98 catch err
99 disp(err.message)
100 stest = false;
101 end
102
103 % <AlgoDescription>
104 %
105 % 1) Check that getInfo call returned an minfo object in all cases.
106 % 2) Check that all plists have the correct parameters.
107 %
108 % </AlgoDescription>
109
110 atest = true;
111 if stest
112 % <AlgoCode>
113 % check we have minfo objects
114 if isa(io, 'minfo')
115 %%% SET 'None'
116 if ~isempty(io(1).sets), atest = false; end
117 if ~isempty(io(1).plists), atest = false; end
118 %%% Check all Sets
119 if ~any(strcmpi(io(2).sets, 'List')), atest = false; end
120 if ~any(strcmpi(io(2).sets, 'Range')), atest = false; end
121 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
122 %%%%%%%%%% SET 'List'
123 if io(3).plists.nparams ~= 2, atest = false; end
124 % Check key
125 if ~io(3).plists.isparam('f'), atest = false; end
126 if ~io(3).plists.isparam('bank'), atest = false; end
127 % Check default value
128 if ~isEmptyDouble(io(3).plists.find('f')), atest = false; end
129 if ~isequal(io(3).plists.find('bank'), 'none'), atest = false; end
130 % Check options
131 if ~isequal(io(3).plists.getOptionsForParam('f'), {[]}), atest = false; end
132 if ~isequal(io(3).plists.getOptionsForParam('bank'), {'none', 'serial', 'parallel'}), atest = false; end
133 %%%%%%%%%% SET 'Range'
134 if io(4).plists.nparams ~= 5, atest = false; end
135 % Check key
136 if ~io(4).plists.isparam('f1'), atest = false; end
137 if ~io(4).plists.isparam('f2'), atest = false; end
138 if ~io(4).plists.isparam('nf'), atest = false; end
139 if ~io(4).plists.isparam('scale'), atest = false; end
140 if ~io(4).plists.isparam('bank'), atest = false; end
141 % Check default value
142 if ~isEmptyDouble(io(4).plists.find('f1')), atest = false; end
143 if ~isEmptyDouble(io(4).plists.find('f2')), atest = false; end
144 if ~isequal(io(4).plists.find('nf'), 1000), atest = false; end
145 if ~isequal(io(4).plists.find('scale'), 'log'), atest = false; end
146 if ~isequal(io(4).plists.find('bank'), 'none'), atest = false; end
147 % Check options
148 if ~isequal(io(4).plists.getOptionsForParam('f1'), {[]}), atest = false; end
149 if ~isequal(io(4).plists.getOptionsForParam('f2'), {[]}), atest = false; end
150 if ~isequal(io(4).plists.getOptionsForParam('nf'), {1000}), atest = false; end
151 if ~isequal(io(4).plists.getOptionsForParam('scale'), {'lin', 'log'}), atest = false; end
152 if ~isequal(io(4).plists.getOptionsForParam('bank'), {'none', 'serial', 'parallel'}), atest = false; end
153 end
154 % </AlgoCode>
155 else
156 atest = false;
157 end
158
159 % Return a result structure
160 result = utp_prepare_result(atest, stest, dbstack, mfilename);
161 end % END UTP_01
162
163 %% UTP_02
164
165 % <TestDescription>
166 %
167 % Tests that the resp method works with a vector of MFIR objects as input.
168 %
169 % </TestDescription>
170 function result = utp_02
171
172 % <SyntaxDescription>
173 %
174 % Test that the resp method works for a vector of MFIR objects as input.
175 % Test the method with an output and with no output (a diagram must appear)
176 %
177 % </SyntaxDescription>
178
179 try
180 % <SyntaxCode>
181 % Make sure that all figures are closed.
182 close all;
183 resp(firv);
184 out = resp(firv);
185 % </SyntaxCode>
186 stest = true;
187 catch err
188 disp(err.message)
189 stest = false;
190 end
191
192 % <AlgoDescription>
193 %
194 % 1) Test the right number of lines in the diagram.
195 % 2) Check that the number of elements in 'out' is the same as in 'firv'
196 % 3) Check that each output MFIR contains the correct data.
197 %
198 % </AlgoDescription>
199
200 THRESHOLD = 1e-12;
201 atest = true;
202 if stest
203 % <AlgoCode>
204 % Get the current figure.
205 fi = gcf;
206 % Get ALL axes including the legends.
207 ax = get(fi, 'Children');
208 % Select only the 'axes' with the lines
209 ax = ax(ismember(get(ax(:), 'Tag'), ''));
210 % Get the lines of both axes
211 lines = get(ax(:), 'Children');
212 % Check that the diagram have the same number of lines as the output
213 % object
214 if max(cellfun('size', lines, 1)) ~= numel(firv), atest = false; end
215 % Check the number of output objects.
216 if ~isequal(size(out), size(firv)), atest = false; end
217 % Check each output against the default values for f1, f2 and nf
218 for ii = 1:numel(out)
219 nf = find(mfir.getInfo('resp', 'Range').plists, 'nf');
220 % Default values always from the first filter
221 f1 = firv(ii).fs/1000;
222 f2 = firv(ii).fs/2-1/nf;
223 if ~isa(out(ii), 'ao'), atest = false; end
224 if ~strcmp(out(ii).hist.methodInfo.mname, 'resp'), atest = false; end
225 if out(ii).x(1) ~= f1, atest = false; end
226 if abs(out(ii).x(end)-f2)>THRESHOLD, atest = false; end
227 if numel(out(ii).x) ~= nf, atest = false; end
228 end
229 % </AlgoCode>
230 else
231 atest = false;
232 end
233
234 % Return a result structure
235 result = utp_prepare_result(atest, stest, dbstack, mfilename);
236 end % END UTP_02
237
238 %% UTP_03
239
240 % <TestDescription>
241 %
242 % Tests that the resp method works with a matrix of MFIR objects as input.
243 %
244 % </TestDescription>
245 function result = utp_03
246
247 % <SyntaxDescription>
248 %
249 % Test that the resp method works for a matrix of MFIR objects as input.
250 % Test the method with an output and with no output (a diagram must appear)
251 %
252 % </SyntaxDescription>
253
254 try
255 % <SyntaxCode>
256 % Make sure that all figures are closed.
257 close all;
258 firmat = [fir1, fir2, fir3; fir4, fir5, fir6];
259 resp(firmat);
260 out = resp(firmat);
261 % </SyntaxCode>
262 stest = true;
263 catch err
264 disp(err.message)
265 stest = false;
266 end
267
268 % <AlgoDescription>
269 %
270 % 1) Test the right number of lines in the diagram.
271 % 2) Check that the number of elements in 'out' is the same as in 'firmat'
272 % 3) Check that each output MFIR contains the correct data.
273 %
274 % </AlgoDescription>
275
276 atest = true;
277 THRESHOLD = 1e-12;
278 if stest
279 % <AlgoCode>
280 % Get the current figure.
281 fi = gcf;
282 % Get ALL axes including the legends.
283 ax = get(fi, 'Children');
284 % Select only the 'axes' with the lines
285 ax = ax(ismember(get(ax(:), 'Tag'), ''));
286 % Get the lines of both axes
287 lines = get(ax(:), 'Children');
288 % Check that the diagram have the same number of lines as the output
289 % object
290 if max(cellfun('size', lines, 1)) ~= numel(firmat), atest = false; end
291 % Check the number of output objects.
292 if ~isequal(size(out), size(firmat)), atest = false; end
293 % Check each output against the default values for f1, f2 and nf
294 for ii = 1:numel(out)
295 % Default values always from the first filter
296 nf = find(mfir.getInfo('resp', 'Range').plists, 'nf');
297 f1 = firmat(ii).fs/1000;
298 f2 = firmat(ii).fs/2-1/nf;
299 if ~isa(out(ii), 'ao'), atest = false; end
300 if ~strcmp(out(ii).hist.methodInfo.mname, 'resp'), atest = false; end
301 if out(ii).x(1) ~= f1, atest = false; end
302 if abs(out(ii).x(end)-f2)>THRESHOLD, atest = false; end
303 if numel(out(ii).x) ~= nf, atest = false; end
304 end
305 % </AlgoCode>
306 else
307 atest = false;
308 end
309
310 % Return a result structure
311 result = utp_prepare_result(atest, stest, dbstack, mfilename);
312 end % END UTP_03
313
314 %% UTP_04
315
316 % <TestDescription>
317 %
318 % Tests that the resp method works with a list of MFIR objects as input.
319 %
320 % </TestDescription>
321 function result = utp_04
322
323 % <SyntaxDescription>
324 %
325 % Test that the resp method works for a list of MFIR objects as input.
326 % Test the method with an output and with no output (a diagram must appear)
327 %
328 % </SyntaxDescription>
329
330 try
331 % <SyntaxCode>
332 close all;
333 resp(fir1,fir2,fir3);
334 out = resp(fir1,fir2,fir3);
335 % </SyntaxCode>
336 stest = true;
337 catch err
338 disp(err.message)
339 stest = false;
340 end
341
342 % <AlgoDescription>
343 %
344 % 1) Test the right number of lines in the diagram.
345 % 2) Check that the number of elements in 'out' is the same as in 'firmat'
346 % 3) Check that each output MFIR contains the correct data.
347 %
348 % </AlgoDescription>
349
350 atest = true;
351 firin = [fir1,fir2,fir3];
352 THRESHOLD = 1e-15;
353 if stest
354 % <AlgoCode>
355 % Get the current figure.
356 fi = gcf;
357 % Get ALL axes including the legends.
358 ax = get(fi, 'Children');
359 % Select only the 'axes' with the lines
360 ax = ax(ismember(get(ax(:), 'Tag'), ''));
361 % Get the lines of both axes
362 lines = get(ax(:), 'Children');
363 % Check that the diagram have the same number of lines as the output
364 % object
365 if max(cellfun('size', lines, 1)) ~= numel(firin), atest = false; end
366 % Check the number of output objects.
367 if ~isequal(size(out), size(firin)), atest = false; end
368 % Check each output against the default values for f1, f2 and nf
369 for ii = 1:numel(out)
370 % Default values always from the first filter
371 nf = find(mfir.getInfo('resp', 'Range').plists, 'nf');
372 f1 = firin(ii).fs/1000;
373 f2 = firin(ii).fs/2-1/nf;
374 if ~isa(out(ii), 'ao'), atest = false; end
375 if ~strcmp(out(ii).hist.methodInfo.mname, 'resp'), atest = false; end
376 if out(ii).x(1) ~= f1, atest = false; end
377 if abs(out(ii).x(end)-f2)>THRESHOLD, atest = false; end
378 if numel(out(ii).x) ~= nf, atest = false; end
379 end
380 % </AlgoCode>
381 else
382 atest = false;
383 end
384
385 % Return a result structure
386 result = utp_prepare_result(atest, stest, dbstack, mfilename);
387 end % END UTP_04
388
389 %% UTP_05
390
391 % <TestDescription>
392 %
393 % Tests that the resp method works with a mix of different shaped MFIR
394 % objects as input.
395 %
396 % </TestDescription>
397 function result = utp_05
398
399 % <SyntaxDescription>
400 %
401 % Test that the resp method works with an input of matrices and vectors
402 % and single MFIR objects. Test the method with an output and with no
403 % output (a diagram must appear)
404 %
405 % </SyntaxDescription>
406
407 try
408 % <SyntaxCode>
409 close all;
410 firmat = [fir5, fir3, fir2; fir1, fir5, fir3];
411 resp(fir1,firv,fir2,firmat,fir3);
412 out = resp(fir1,firv,fir2,firmat,fir3);
413 % </SyntaxCode>
414 stest = true;
415 catch err
416 disp(err.message)
417 stest = false;
418 end
419
420 % <AlgoDescription>
421 %
422 % 1) Test the right number of lines in the diagram.
423 % 2) Check that the number of elements in 'out' is the same as in 'firmat'
424 % 3) Check that each output MFIR contains the correct data.
425 %
426 % </AlgoDescription>
427
428 atest = true;
429 firin = [fir1,reshape(firv,1,[]),fir2,reshape(firmat,1,[]),fir3];
430 THRESHOLD = 1e-12;
431 if stest
432 % <AlgoCode>
433 % Get the current figure.
434 fi = gcf;
435 % Get ALL axes including the legends.
436 ax = get(fi, 'Children');
437 % Select only the 'axes' with the lines
438 ax = ax(ismember(get(ax(:), 'Tag'), ''));
439 % Get the lines of both axes
440 lines = get(ax(:), 'Children');
441 % Check that the diagram have the same number of lines as the output
442 % object
443 if max(cellfun('size', lines, 1)) ~= numel(firin), atest = false; end
444 % Check the number of output objects.
445 if ~isequal(size(out), size(firin)), atest = false; end
446 % Check each output against the default values for f1, f2 and nf
447 for ii = 1:numel(out)
448 % Default values always from the first filter
449 nf = find(mfir.getInfo('resp', 'Range').plists, 'nf');
450 f1 = firin(ii).fs/1000;
451 f2 = firin(ii).fs/2-1/nf;
452 if ~isa(out(ii), 'ao'), atest = false; end
453 if ~strcmp(out(ii).hist.methodInfo.mname, 'resp'), atest = false; end
454 if out(ii).x(1) ~= f1, atest = false; end
455 if abs(out(ii).x(end)-f2)>THRESHOLD, atest = false; end
456 if numel(out(ii).x) ~= nf, atest = false; end
457 end
458 % </AlgoCode>
459 else
460 atest = false;
461 end
462
463 % Return a result structure
464 result = utp_prepare_result(atest, stest, dbstack, mfilename);
465 end % END UTP_05
466
467 %% UTP_06
468
469 % <TestDescription>
470 %
471 % Tests that the resp method properly applies history.
472 %
473 % </TestDescription>
474 function result = utp_06
475
476 % <SyntaxDescription>
477 %
478 % Test that the result of applying the resp method can be processed back.
479 %
480 % </SyntaxDescription>
481
482 try
483 % <SyntaxCode>
484 close all;
485 resp(fir5);
486 out = resp(fir5);
487 mout = rebuild(out);
488 % </SyntaxCode>
489 stest = true;
490 catch err
491 disp(err.message)
492 stest = false;
493 end
494
495 % <AlgoDescription>
496 %
497 % 1) Check that the last entry in the history of 'out' corresponds to
498 % 'resp'.
499 % 2) Check that re-built object is the same object as the input.
500 %
501 % </AlgoDescription>
502
503 atest = true;
504 if stest
505 % <AlgoCode>
506 % Get the current figure.
507 fi = gcf;
508 % Get ALL axes including the legends.
509 ax = get(fi, 'Children');
510 % Select only the 'axes' with the lines
511 ax = ax(ismember(get(ax(:), 'Tag'), ''));
512 % Get the lines of both axes
513 lines = get(ax(:), 'Children');
514 x = get(lines{1}, 'XData');
515 y1 = get(lines{1}, 'YData');
516 y2 = get(lines{2}, 'YData');
517 if ~isequal(x, out.x.'), atest = false; end
518 if ~isequal(y2, abs(out.y)'), atest = false; end
519 if ~isequal(y1, utils.math.phase(out.y)'), atest = false; end
520 % Check the last step in the history of 'out'
521 if ~strcmp(out.hist.methodInfo.mname, 'resp'), atest = false; end
522 % Run 'test.m' and check the result
523 if ~eq(mout, out, ple2), atest = false; end
524 % </AlgoCode>
525 else
526 atest = false;
527 end
528
529 % Return a result structure
530 result = utp_prepare_result(atest, stest, dbstack, mfilename);
531 end % END UTP_06
532
533 %% UTP_07
534
535 % <TestDescription>
536 %
537 % Tests that modify command plots the response into a diagram.
538 %
539 % </TestDescription>
540 function result = utp_07
541
542 % <SyntaxDescription>
543 %
544 % Tests that modify command plots the response into a diagram.
545 %
546 % </SyntaxDescription>
547
548 try
549 % <SyntaxCode>
550 close all;
551 fir5.resp();
552 % </SyntaxCode>
553 stest = true;
554 catch err
555 disp(err.message)
556 stest = false;
557 end
558
559 % <AlgoDescription>
560 %
561 % 1) Check the response diagram.
562 %
563 % </AlgoDescription>
564
565 atest = true;
566 THRESHOLD = 1e-12;
567 if stest
568 % <AlgoCode>
569 % Get the current figure.
570 fi = gcf;
571 % Get ALL axes including the legends.
572 ax = get(fi, 'Children');
573 % Select only the 'axes' with the lines
574 ax = ax(ismember(get(ax(:), 'Tag'), ''));
575 % Get the lines of both axes
576 lines = get(ax(:), 'Children');
577 x = get(lines{1}, 'XData');
578 % Default values always from the first filter
579 nf = find(mfir.getInfo('resp', 'Range').plists, 'nf');
580 f1 = fir5(1).fs/1000;
581 f2 = fir5(1).fs/2-1/nf;
582 if x(1) ~= f1, atest = false; end
583 if abs(x(end)-f2)>THRESHOLD, atest = false; end
584 if numel(x) ~= nf, atest = false; end
585 % </AlgoCode>
586 else
587 atest = false;
588 end
589
590 % Return a result structure
591 result = utp_prepare_result(atest, stest, dbstack, mfilename);
592 end % END UTP_07
593
594 %% UTP_08
595
596 % <TestDescription>
597 %
598 % Test the shape of the output.
599 %
600 % </TestDescription>
601 function result = utp_08
602
603 % <SyntaxDescription>
604 %
605 % Test that the output AO of the resp method keeps the shape of the used
606 % input f vector.
607 %
608 % </SyntaxDescription>
609
610 try
611 % <SyntaxCode>
612 close all;
613 arow = ao(1:100, linspace(.1, 5, 100));
614 acol = arow.';
615 f = linspace(.1, 5, 100);
616 out1 = resp(fir5, plist('f', arow));
617 out2 = resp(fir5, plist('f', acol));
618 out3 = resp(fir5, plist('f', f));
619 % </SyntaxCode>
620 stest = true;
621 catch err
622 disp(err.message)
623 stest = false;
624 end
625
626 % <AlgoDescription>
627 %
628 % 1) Check that the shape of the data doesn't change.
629 %
630 % </AlgoDescription>
631
632 atest = true;
633 if stest
634 % <AlgoCode>
635 % Check the shape of the output data
636 if size(out1.data.y,1) ~= 1, atest = false; end
637 if size(out1.data.y,2) == 1, atest = false; end
638 if size(out2.data.y,1) == 1, atest = false; end
639 if size(out2.data.y,2) ~= 1, atest = false; end
640 if size(out3.data.y,1) ~= 1, atest = false; end
641 if size(out3.data.y,2) == 1, atest = false; end
642 % </AlgoCode>
643 else
644 atest = false;
645 end
646
647 % Return a result structure
648 result = utp_prepare_result(atest, stest, dbstack, mfilename);
649 end % END UTP_08
650
651 %% UTP_09
652
653 % <TestDescription>
654 %
655 % Check that the resp method pass back the output objects to a list of
656 % output variables or to a single variable.
657 %
658 % </TestDescription>
659 function result = utp_09
660
661 % <SyntaxDescription>
662 %
663 % Call the method with a list of output variables and with a single output
664 % variable. Additionaly check that the rebuild method works on the output.
665 %
666 % </SyntaxDescription>
667
668 try
669 % <SyntaxCode>
670 [o1, o2] = resp(fir5, fir3);
671 o3 = resp(fir5, fir3);
672 mout1 = rebuild(o1);
673 mout2 = rebuild(o2);
674 mout3 = rebuild(o3);
675 % </SyntaxCode>
676 stest = true;
677 catch err
678 disp(err.message)
679 stest = false;
680 end
681
682 % <AlgoDescription>
683 %
684 % 1) Check that the output contains the right number of objects
685 % 2) Check that the 'rebuild' method produces the same object as 'out'.
686 %
687 % </AlgoDescription>
688
689 atest = true;
690 if stest
691 % <AlgoCode>
692 % Check the number of outputs
693 if numel(o1) ~=1, atest = false; end
694 if numel(o2) ~=1, atest = false; end
695 if numel(o3) ~=2, atest = false; end
696 % Check the rebuilding of the object
697 if ~eq(o1, mout1, ple2), atest = false; end
698 if ~eq(o2, mout2, ple2), atest = false; end
699 if ~eq(o3, mout3, ple2), atest = false; end
700 % </AlgoCode>
701 else
702 atest = false;
703 end
704
705 % Return a result structure
706 result = utp_prepare_result(atest, stest, dbstack, mfilename);
707 end % END UTP_09
708
709 %% UTP_10
710
711 % <TestDescription>
712 %
713 % Check that the resp method uses the x-data of an input AO for f-vector.
714 %
715 % </TestDescription>
716 function result = utp_10
717
718 % <SyntaxDescription>
719 %
720 % Call the method with different method to pass an AO in.
721 %
722 % </SyntaxDescription>
723
724 try
725 % <SyntaxCode>
726 f1 = .1;
727 f2 = 5;
728 nf = 100;
729 axy = ao(linspace(f1, f2, nf), randn(100,1));
730 afs = ao(linspace(f1, f2, nf), randn(100,1), plist('type', 'fsdata'));
731 out1 = resp(fir5, plist('f', axy));
732 out2 = resp(fir5, plist('f', afs));
733
734 mout1 = rebuild(out1);
735 mout2 = rebuild(out2);
736 % </SyntaxCode>
737 stest = true;
738 catch err
739 disp(err.message)
740 stest = false;
741 end
742
743 % <AlgoDescription>
744 %
745 % 1) Check the output
746 % 2) Check that the 'rebuild' method produces the same object as 'out'.
747 %
748 % </AlgoDescription>
749
750 atest = true;
751 if stest
752 % <AlgoCode>
753 % Check the output
754 if ~isa(out1, 'ao'), atest = false; end
755 if ~isa(out2, 'ao'), atest = false; end
756 if out1.x(1) ~= f1, atest = false; end
757 if out1.x(end) ~= f2, atest = false; end
758 if numel(out1.x) ~= nf, atest = false; end
759 if out2.x(1) ~= f1, atest = false; end
760 if out2.x(end) ~= f2, atest = false; end
761 if numel(out2.x) ~= nf, atest = false; end
762 % Check the rebuilding of the object
763 if ~eq(out1, mout1, ple2), atest = false; end
764 if ~eq(out2, mout2, ple2), atest = false; end
765 % </AlgoCode>
766 else
767 atest = false;
768 end
769
770 % Return a result structure
771 result = utp_prepare_result(atest, stest, dbstack, mfilename);
772 end % END UTP_10
773
774 %% UTP_11
775
776 % <TestDescription>
777 %
778 % Check that the resp method uses the specified f-vector to compute the response.
779 %
780 % </TestDescription>
781 function result = utp_11
782
783 % <SyntaxDescription>
784 %
785 % Call the method with different method to pass an f-vector in.
786 %
787 % </SyntaxDescription>
788
789 try
790 % <SyntaxCode>
791 f1 = .1;
792 f2 = 5;
793 nf = 100;
794 f = linspace(f1, f2, nf);
795 out1 = resp(fir5, plist('f', f));
796
797 mout1 = rebuild(out1);
798 % </SyntaxCode>
799 stest = true;
800 catch err
801 disp(err.message)
802 stest = false;
803 end
804
805 % <AlgoDescription>
806 %
807 % 1) Check the output
808 % 2) Check that the 'rebuild' method produces the same object as 'out'.
809 %
810 % </AlgoDescription>
811
812 atest = true;
813 if stest
814 % <AlgoCode>
815 % Check the output
816 if ~isa(out1, 'ao'), atest = false; end
817 if out1.x(1) ~= f1, atest = false; end
818 if out1.x(end) ~= f2, atest = false; end
819 if numel(out1.x) ~= nf, atest = false; end
820 % Check the rebuilding of the object
821 if ~eq(out1, mout1, ple2), atest = false; end
822 % </AlgoCode>
823 else
824 atest = false;
825 end
826
827 % Return a result structure
828 result = utp_prepare_result(atest, stest, dbstack, mfilename);
829 end % END UTP_11
830
831 %% UTP_12
832
833 % <TestDescription>
834 %
835 % Check that the resp method uses the specified f1, f2, and nf to compute the response.
836 %
837 % </TestDescription>
838 function result = utp_12
839
840 % <SyntaxDescription>
841 %
842 % Call the method with different method to pass f1, f2, and nf in.
843 %
844 % </SyntaxDescription>
845
846 try
847 % <SyntaxCode>
848 f1 = .1;
849 f2 = 5;
850 nf = 100;
851 nf2 = 123;
852 out3 = resp(fir5, plist('f1', f1, 'f2', f2, 'nf', nf));
853 out4 = resp(fir5, plist('f1', f1, 'nf', nf2));
854 out5 = resp(fir5, plist('f2', f2));
855
856 mout3 = rebuild(out3);
857 mout4 = rebuild(out4);
858 mout5 = rebuild(out5);
859 % </SyntaxCode>
860 stest = true;
861 catch err
862 disp(err.message)
863 stest = false;
864 end
865
866 % <AlgoDescription>
867 %
868 % 1) Check the output
869 % 2) Check that the 'rebuild' method produces the same object as 'out'.
870 %
871 % </AlgoDescription>
872
873 atest = true;
874 T = 1e-12;
875 if stest
876 % <AlgoCode>
877 % Check the output
878 nfd = find(mfir.getInfo('resp', 'Range').plists, 'nf');
879 f1d = fir5.fs/1000;
880 f2d = fir5.fs/2-1/nf;
881 f2d2 = fir5.fs/2-1/nf2;
882 if ~isa(out3, 'ao'), atest = false; end
883 if ~isa(out4, 'ao'), atest = false; end
884 if ~isa(out5, 'ao'), atest = false; end
885 if out3.x(1) ~= f1, atest = false; end
886 if abs(out3.x(end)-f2)>T, atest = false; end
887 if numel(out3.x) ~= nf, atest = false; end
888 if out4.x(1) ~= f1, atest = false; end
889 if abs(out4.x(end)-f2d2)>T, atest = false; end % Default values
890 if numel(out4.x) ~= nf2, atest = false; end
891 if out5.x(1) ~= f1d, atest = false; end % Default values
892 if abs(out5.x(end)-f2)>T, atest = false; end
893 if numel(out5.x) ~= nfd, atest = false; end % Default values
894 % Check the rebuilding of the object
895 if ~eq(out3, mout3, ple2), atest = false; end
896 if ~eq(out4, mout4, ple2), atest = false; end
897 if ~eq(out5, mout5, ple2), atest = false; end
898 % </AlgoCode>
899 else
900 atest = false;
901 end
902
903 % Return a result structure
904 result = utp_prepare_result(atest, stest, dbstack, mfilename);
905 end % END UTP_12
906
907 %% UTP_13
908
909 % <TestDescription>
910 %
911 % Check that the resp method uses the specified f1, f2, and nf to compute the response.
912 %
913 % </TestDescription>
914 function result = utp_13
915
916 % <SyntaxDescription>
917 %
918 % Call the method with different method to pass f1, f2, and nf in.
919 %
920 % </SyntaxDescription>
921
922 try
923 % <SyntaxCode>
924 f1 = .1;
925 f2 = 5;
926 nf = 123;
927 out1 = resp(fir5, plist('f1', f1, 'f2', f2, 'nf', nf, 'scale', 'lin'));
928 out2 = resp(fir5, plist('f1', f1, 'f2', f2, 'nf', nf, 'scale', 'log'));
929 out3 = resp(fir5, plist('scale', 'lin'));
930 out4 = resp(fir5, plist('scale', 'log'));
931
932 mout1 = rebuild(out1);
933 mout2 = rebuild(out2);
934 mout3 = rebuild(out3);
935 mout4 = rebuild(out4);
936 % </SyntaxCode>
937 stest = true;
938 catch err
939 disp(err.message)
940 stest = false;
941 end
942
943 % <AlgoDescription>
944 %
945 % 1) Check the output
946 % 2) Check that the 'rebuild' method produces the same object as 'out'.
947 %
948 % </AlgoDescription>
949
950 atest = true;
951 T = 10e-12;
952 if stest
953 % <AlgoCode>
954 % Check the output
955 nfd = find(mfir.getInfo('resp', 'Range').plists, 'nf');
956 f1d = fir5.fs/1000;
957 f2d = fir5.fs/2-1/nfd;
958 if ~isa(out1, 'ao'), atest = false; end
959 if ~isa(out2, 'ao'), atest = false; end
960 if ~isa(out3, 'ao'), atest = false; end
961 if ~isa(out4, 'ao'), atest = false; end
962 xlin1 = linspace(f1, f2, nf);
963 xlin2 = linspace(f1d, f2d, nfd);
964 xlog1 = logspace(log10(f1), log10(f2), nf);
965 xlog2 = logspace(log10(f1d), log10(f2d), nfd);
966 if ~isequal(xlin1, out1.x'), atest = false; end
967 if ~isequal(xlin2, out3.x'), atest = false; end
968 if ~isequal(xlog1, out2.x'), atest = false; end
969 if ~isequal(xlog2, out4.x'), atest = false; end
970
971 % Check the rebuilding of the object
972 if ~eq(out1, mout1, ple2), atest = false; end
973 if ~eq(out2, mout2, ple2), atest = false; end
974 if ~eq(out3, mout3, ple2), atest = false; end
975 if ~eq(out4, mout4, ple2), atest = false; end
976 % </AlgoCode>
977 else
978 atest = false;
979 end
980
981 % Return a result structure
982 result = utp_prepare_result(atest, stest, dbstack, mfilename);
983 end % END UTP_13
984
985 %% UTP_14
986
987 % <TestDescription>
988 %
989 % Check that the resp method the response of a serial filter bank.
990 %
991 % </TestDescription>
992 function result = utp_14
993
994 % <SyntaxDescription>
995 %
996 % Check that the resp method the response of a serial filter bank.
997 %
998 % </SyntaxDescription>
999
1000 try
1001 % <SyntaxCode>
1002 out = resp(fir1, fir2, plist('bank', 'serial'));
1003
1004 mout = rebuild(out);
1005 % </SyntaxCode>
1006 stest = true;
1007 catch err
1008 disp(err.message)
1009 stest = false;
1010 end
1011
1012 % <AlgoDescription>
1013 %
1014 % 1) Check the output
1015 % 2) Check that the 'rebuild' method produces the same object as 'out'.
1016 %
1017 % </AlgoDescription>
1018
1019 atest = true;
1020 if stest
1021 % <AlgoCode>
1022 % Check the output
1023 if ~isa(out, 'ao'), atest = false; end
1024 if numel(out) ~= 1, atest = false; end
1025 s1 = resp(fir1);
1026 s2 = resp(fir2);
1027 stot = s1 .* s2;
1028 if ~isequal(stot.x, out.x), atest = false; end
1029 if ~isequal(stot.y, out.y), atest = false; end
1030 % Check the rebuilding of the object
1031 if ~eq(out, mout, ple2), atest = false; end
1032 % </AlgoCode>
1033 else
1034 atest = false;
1035 end
1036
1037 % Return a result structure
1038 result = utp_prepare_result(atest, stest, dbstack, mfilename);
1039 end % END UTP_14
1040
1041 %% UTP_15
1042
1043 % <TestDescription>
1044 %
1045 % Check that the resp method the response of a parallel filter bank.
1046 %
1047 % </TestDescription>
1048 function result = utp_15
1049
1050 % <SyntaxDescription>
1051 %
1052 % Check that the resp method the response of a parallel filter bank.
1053 %
1054 % </SyntaxDescription>
1055
1056 try
1057 % <SyntaxCode>
1058 out = resp(fir1, fir2, plist('bank', 'parallel'));
1059
1060 mout = rebuild(out);
1061 % </SyntaxCode>
1062 stest = true;
1063 catch err
1064 disp(err.message)
1065 stest = false;
1066 end
1067
1068 % <AlgoDescription>
1069 %
1070 % 1) Check the output
1071 % 2) Check that the 'rebuild' method produces the same object as 'out'.
1072 %
1073 % </AlgoDescription>
1074
1075 atest = true;
1076 T = 10e-12;
1077 if stest
1078 % <AlgoCode>
1079 % Check the output
1080 if ~isa(out, 'ao'), atest = false; end
1081 if numel(out) ~= 1, atest = false; end
1082 s1 = resp(fir1);
1083 s2 = resp(fir2);
1084 stot = s1 + s2;
1085 if ~isequal(stot.x, out.x), atest = false; end
1086 if ~isequal(stot.y, out.y), atest = false; end
1087 % Check the rebuilding of the object
1088 if ~eq(out, mout, ple2), atest = false; end
1089 % </AlgoCode>
1090 else
1091 atest = false;
1092 end
1093
1094 % Return a result structure
1095 result = utp_prepare_result(atest, stest, dbstack, mfilename);
1096 end % END UTP_15
1097
1098 end