comparison testing/utp_1.1/utps/miir/utp_miir_redesign.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_MIIR_REDESIGN a set of UTPs for the miir/redesign method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_miir_redesign.m,v 1.3 2011/04/17 15:47:40 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The redesign method of the miir class redesign the input filter to work for the
11 % given sample rate.
12 %
13 % </MethodDescription>
14
15 function results = utp_miir_redesign(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'miir';
22 mthd = 'redesign';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 % Test MIIR objects
30 [iirhp,iirlp,iirbp,iirbr,iirpzm,iirab,iirv,iirm] = get_test_objects_miir;
31
32 % Exception list for the UTPs:
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
34
35 e = ple3.find('EXCEPTIONS');
36 ple3 = plist('EXCEPTIONS', [e {'iunits', 'ounits'}]);
37
38 % Run the tests
39 results = [results utp_01]; % getInfo call
40 results = [results utp_02]; % Vector input
41 results = [results utp_03]; % Matrix input
42 results = [results utp_04]; % List input
43 results = [results utp_05]; % Test with mixed input
44 results = [results utp_06]; % Test history is working
45 results = [results utp_07]; % Test redesign from a standard type
46 results = [results utp_08]; % Test redesign from a pzmodel type
47 results = [results utp_09]; % Test redesign from a parfrac type
48
49 disp('Done.');
50 disp('******************************************************');
51
52 elseif nargin == 1 % Check for UTP functions
53 if strcmp(varargin{1}, 'isutp')
54 results = 1;
55 else
56 results = 0;
57 end
58 else
59 error('### Incorrect inputs')
60 end
61
62 %% UTP_01
63
64 % <TestDescription>
65 %
66 % Tests that the getInfo call works for this method.
67 %
68 % </TestDescription>
69 function result = utp_01
70
71
72 % <SyntaxDescription>
73 %
74 % Test that the getInfo call works for no sets, all sets, and each set
75 % individually.
76 %
77 % </SyntaxDescription>
78
79 try
80 % <SyntaxCode>
81 % Call for no sets
82 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
83 % Call for all sets
84 io(2) = eval([class '.getInfo(''' mthd ''')']);
85 % Call for each set
86 for kk=1:numel(io(2).sets)
87 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
88 end
89 % </SyntaxCode>
90 stest = true;
91 catch err
92 disp(err.message)
93 stest = false;
94 end
95
96 % <AlgoDescription>
97 %
98 % 1) Check that getInfo call returned an minfo object in all cases.
99 % 2) Check that all plists have the correct parameters.
100 %
101 % </AlgoDescription>
102
103 atest = true;
104 if stest
105 % <AlgoCode>
106 % check we have minfo objects
107 if isa(io, 'minfo')
108 % SET 'None'
109 if ~isempty(io(1).sets), atest = false; end
110 if ~isempty(io(1).plists), atest = false; end
111 % Check all Sets
112 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
113 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
114 % SET 'Default'
115 if io(3).plists.nparams ~= 0, atest = false; end
116 % Check key
117 % Check default value
118 % Check options
119 end
120 % </AlgoCode>
121 else
122 atest = false;
123 end
124
125 % Return a result structure
126 result = utp_prepare_result(atest, stest, dbstack, mfilename);
127 end % END UTP_01
128
129 %% UTP_02
130
131 % <TestDescription>
132 %
133 % Tests that the redesign method works with a vector of MIIR objects as input.
134 %
135 % </TestDescription>
136 function result = utp_02
137
138 % <SyntaxDescription>
139 %
140 % Test that the redesign method works for a vector of MIIR objects as input.
141 % To keep this UTP simple use for the vector only one filter object. The
142 % different filters will be tested in an other UTP.
143 %
144 % </SyntaxDescription>
145
146 try
147 % <SyntaxCode>
148 hp = miir(iirhp);
149 hp.setIunits('Hz');
150 hp.setOunits('m^-2/3');
151 iirvec = [hp, hp, hp];
152 out1 = redesign(iirvec, 123);
153 out2 = redesign(iirvec, plist('fs', 123));
154 % </SyntaxCode>
155 stest = true;
156 catch err
157 disp(err.message)
158 stest = false;
159 end
160
161 % <AlgoDescription>
162 %
163 % 1) Check that the number of elements in 'out' is the same as in 'iirvec'
164 % 2) Check that each output MIIR contains the correct data.
165 %
166 % </AlgoDescription>
167
168 atest = true;
169 if stest
170 % <AlgoCode>
171 % Check we have the correct number of outputs
172 if ~isequal(size(out1), size(iirvec)), atest = false; end
173 if ~isequal(size(out2), size(iirvec)), atest = false; end
174 % Check each output against the redesign of the filter with the
175 % new frequency
176 iirhp_123 = miir(plist('type', 'highpass', 'fs', 123));
177 for kk=1:numel(iirvec)
178 if ~eq(out1(kk), iirhp_123, ple3), atest = false; end
179 % The following values must have the same as the input values
180 if ~strcmp(out1(kk).name, hp.name), atest = false; end
181 if ~eq(out1(kk).iunits, hp.iunits), atest = false; end
182 if ~eq(out1(kk).ounits, hp.ounits), atest = false; end
183 end
184 % 'out1' must be the same as 'out2'
185 if ~eq(out1, out2, ple1), atest = false; end
186 % </AlgoCode>
187 else
188 atest = false;
189 end
190
191 % Return a result structure
192 result = utp_prepare_result(atest, stest, dbstack, mfilename);
193 end % END UTP_02
194
195 %% UTP_03
196
197 % <TestDescription>
198 %
199 % Tests that the redesign method works with a matrix of MIIR objects as input.
200 %
201 % </TestDescription>
202 function result = utp_03
203
204 % <SyntaxDescription>
205 %
206 % Test that the redesign method works for a matrix of MIIR objects as input.
207 % To keep this UTP simple use for the matrix only one filter object. The
208 % different filters will be tested in an other UTP.
209 %
210 % </SyntaxDescription>
211
212 try
213 % <SyntaxCode>
214 hp = miir(iirhp);
215 hp.setIunits('Hz');
216 hp.setOunits('m^-2/3');
217 iirmat = [hp, hp, hp; hp, hp, hp];
218 out1 = redesign(iirmat, 123);
219 out2 = redesign(iirmat, plist('fs', 123));
220 % </SyntaxCode>
221 stest = true;
222 catch err
223 disp(err.message)
224 stest = false;
225 end
226
227 % <AlgoDescription>
228 %
229 % 1) Check that the number of elements in 'out' is the same as in 'iirmat'
230 % 2) Check that each output MIIR contains the correct data.
231 %
232 % </AlgoDescription>
233
234 atest = true;
235 if stest
236 % <AlgoCode>
237 % Check we have the correct number of outputs
238 if ~isequal(size(out1), size(iirmat)), atest = false; end
239 if ~isequal(size(out2), size(iirmat)), atest = false; end
240 % Check each output against the redesign of the filter with the
241 % new frequency
242 iirhp_123 = miir(plist('type', 'highpass', 'fs', 123));
243 for kk=1:numel(iirmat)
244 if ~eq(out1(kk), iirhp_123, ple3), atest = false; end
245 % The following values must have the same as the input values
246 if ~strcmp(out1(kk).name, hp.name), atest = false; end
247 if ~eq(out1(kk).iunits, hp.iunits), atest = false; end
248 if ~eq(out1(kk).ounits, hp.ounits), atest = false; end
249 end
250 % 'out1' must be the same as 'out2'
251 if ~eq(out1, out2, ple1), atest = false; end
252 % </AlgoCode>
253 else
254 atest = false;
255 end
256
257 % Return a result structure
258 result = utp_prepare_result(atest, stest, dbstack, mfilename);
259 end % END UTP_03
260
261 %% UTP_04
262
263 % <TestDescription>
264 %
265 % Tests that the redesign method works with a list of MIIR objects as input.
266 %
267 % </TestDescription>
268 function result = utp_04
269
270 % <SyntaxDescription>
271 %
272 % Test that the redesign method works for a list of MIIR objects as input.
273 % To keep this UTP simple use for the list only one filter object. The
274 % different filters will be tested in an other UTP.
275 %
276 % </SyntaxDescription>
277
278 try
279 % <SyntaxCode>
280 hp = miir(iirhp);
281 hp.setIunits('Hz');
282 hp.setOunits('m^-2/3');
283 out1 = redesign(hp, hp, hp, 123);
284 out2 = redesign(hp, hp, hp, plist('fs', 123));
285 % </SyntaxCode>
286 stest = true;
287 catch err
288 disp(err.message)
289 stest = false;
290 end
291
292 % <AlgoDescription>
293 %
294 % 1) Check that the number of elements in 'out' is the same as in
295 % input.
296 % 2) Check that each output MIIR contains the correct data.
297 %
298 % </AlgoDescription>
299
300 atest = true;
301 iirin = [hp, hp, hp];
302 if stest
303 % <AlgoCode>
304 % Check we have the correct number of outputs
305 if numel(out1) ~= 3, atest = false; end
306 if numel(out2) ~= 3, atest = false; end
307 % Check each output against the redesign of the filter with the
308 % new frequency
309 iirhp_123 = miir(plist('type', 'highpass', 'fs', 123));
310 for kk=1:numel(iirin)
311 if ~eq(out1(kk), iirhp_123, ple3), atest = false; end
312 % The following values must have the same as the input values
313 if ~strcmp(out1(kk).name, hp.name), atest = false; end
314 if ~eq(out1(kk).iunits, hp.iunits), atest = false; end
315 if ~eq(out1(kk).ounits, hp.ounits), atest = false; end
316 end
317 % 'out1' must be the same as 'out2'
318 if ~eq(out1, out2, ple1), atest = false; end
319 % </AlgoCode>
320 else
321 atest = false;
322 end
323
324 % Return a result structure
325 result = utp_prepare_result(atest, stest, dbstack, mfilename);
326 end % END UTP_04
327
328 %% UTP_05
329
330 % <TestDescription>
331 %
332 % Tests that the redesign method works with a mix of different shaped
333 % MIIR objects as input.
334 %
335 % </TestDescription>
336 function result = utp_05
337
338 % <SyntaxDescription>
339 %
340 % Test that the redesign method works with an input of matrices and vectors
341 % and single MIIR objects.
342 % To keep this UTP simple use for the vector only one filter object. The
343 % different filters will be tested in an other UTP.
344 %
345 % </SyntaxDescription>
346
347 try
348 % <SyntaxCode>
349 hp = miir(iirhp);
350 hp.setIunits('Hz');
351 hp.setOunits('m^-2/3');
352 out1 = redesign(hp,[hp hp],hp,[hp hp hp; hp hp hp],hp, 123);
353 out2 = redesign(hp,[hp hp],hp,[hp hp hp; hp hp hp],hp, plist('fs', 123));
354 % </SyntaxCode>
355 stest = true;
356 catch err
357 disp(err.message)
358 stest = false;
359 end
360
361 % <AlgoDescription>
362 %
363 % 1) Check that the number of elements in 'out' is the same as in
364 % input.
365 % 2) Check that each output MIIR contains the correct data.
366 %
367 % </AlgoDescription>
368
369 atest = true;
370 iirin = [hp hp hp hp hp hp hp hp hp hp hp];
371 if stest
372 % <AlgoCode>
373 % Check we have the correct number of outputs
374 if numel(out1) ~= numel(iirin), atest = false; end
375 if numel(out2) ~= numel(iirin), atest = false; end
376 % Check each output against the redesign of the filter with the
377 % new frequency
378 iirhp_123 = miir(plist('type', 'highpass', 'fs', 123));
379 for kk=1:numel(iirin)
380 if ~eq(out1(kk), iirhp_123, ple3), atest = false; end
381 % The following values must have the same as the input values
382 if ~strcmp(out1(kk).name, hp.name), atest = false; end
383 if ~eq(out1(kk).iunits, hp.iunits), atest = false; end
384 if ~eq(out1(kk).ounits, hp.ounits), atest = false; end
385 end
386 % 'out1' must be the same as 'out2'
387 if ~eq(out1, out2, ple1), atest = false; end
388 % </AlgoCode>
389 else
390 atest = false;
391 end
392
393 % Return a result structure
394 result = utp_prepare_result(atest, stest, dbstack, mfilename);
395 end % END UTP_05
396
397 %% UTP_06
398
399 % <TestDescription>
400 %
401 % Tests that the redesign method properly applies history.
402 %
403 % </TestDescription>
404 function result = utp_06
405
406 % <SyntaxDescription>
407 %
408 % Test that the result of applying the redesign method can be processed back.
409 %
410 % </SyntaxDescription>
411
412 try
413 % <SyntaxCode>
414 hp = miir(iirhp);
415 hp.setIunits('Hz');
416 hp.setOunits('m^-2/3');
417 out = redesign(hp, 123);
418 mout = rebuild(out);
419 % </SyntaxCode>
420 stest = true;
421 catch err
422 disp(err.message)
423 stest = false;
424 end
425
426 % <AlgoDescription>
427 %
428 % 1) Check that the last entry in the history of 'out' corresponds to
429 % 'redesign'.
430 % 2) Check that re-built object is the same object as the input.
431 %
432 % </AlgoDescription>
433
434 atest = true;
435 if stest
436 % <AlgoCode>
437 % Check the last step in the history of 'out'
438 if ~strcmp(out.hist.methodInfo.mname, 'redesign'), atest = false; end
439 % Run 'test.m' and check the result
440 if ~eq(mout, out, ple2), atest = false; end
441 % </AlgoCode>
442 else
443 atest = false;
444 end
445
446 % Return a result structure
447 result = utp_prepare_result(atest, stest, dbstack, mfilename);
448 end % END UTP_06
449
450 %% UTP_07
451
452 % <TestDescription>
453 %
454 % Tests that the redesign method redesigns a standard filter type.
455 %
456 % </TestDescription>
457 function result = utp_07
458
459 % <SyntaxDescription>
460 %
461 % Tests that the redesign method redesigns a standard filter type.
462 %
463 % </SyntaxDescription>
464
465 try
466 % <SyntaxCode>
467 out1 = redesign(iirhp, 123);
468 out2 = redesign(iirlp, 123);
469 out3 = redesign(iirbp, 123);
470 out4 = redesign(iirbr, 123);
471
472 mout1 = rebuild(out1);
473 mout2 = rebuild(out2);
474 mout3 = rebuild(out3);
475 mout4 = rebuild(out4);
476 % </SyntaxCode>
477 stest = true;
478 catch err
479 disp(err.message)
480 stest = false;
481 end
482
483 % <AlgoDescription>
484 %
485 % 1) Check the output
486 % 2) Check the rebuilt object
487 %
488 % </AlgoDescription>
489
490 atest = true;
491 if stest
492 % <AlgoCode>
493 % Check each output against the redesign of the filter with the new
494 % frequency
495 hp_123 = miir(plist('type', 'highpass', 'fs', 123));
496 lp_123 = miir(plist('type', 'lowpass', 'fs', 123));
497 bp_123 = miir(plist('type', 'bandpass', 'fs', 123, 'fc', [0.01 0.1]));
498 br_123 = miir(plist('type', 'bandreject', 'fs', 123, 'fc', [0.01 0.1]));
499 if ~eq(out1, hp_123, ple3), atest = false; end
500 if ~eq(out2, lp_123, ple3), atest = false; end
501 if ~eq(out3, bp_123, ple3), atest = false; end
502 if ~eq(out4, br_123, ple3), atest = false; end
503 % Run 'test[1..4].m' and check the result
504 if ~eq(mout1, out1, ple2), atest = false; end
505 if ~eq(mout2, out2, ple2), atest = false; end
506 if ~eq(mout3, out3, ple2), atest = false; end
507 if ~eq(mout4, out4, ple2), atest = false; end
508 % </AlgoCode>
509 else
510 atest = false;
511 end
512
513 % Return a result structure
514 result = utp_prepare_result(atest, stest, dbstack, mfilename);
515 end % END UTP_07
516
517 %% UTP_08
518
519 % <TestDescription>
520 %
521 % Tests that the redesign method redesigns a pzmodel filter type.
522 %
523 % </TestDescription>
524 function result = utp_08
525
526 % <SyntaxDescription>
527 %
528 % Tests that the redesign method redesigns a pzmodel filter type.
529 %
530 % </SyntaxDescription>
531
532 try
533 % <SyntaxCode>
534 pzm = pzmodel(1, [pz(1) pz(200)], pz(50));
535 pzm.setName();
536 pl = plist('pzmodel', pzm, 'fs', 1000);
537 iirpzm = miir(pl);
538 out = redesign(iirpzm, 123);
539
540 mout = rebuild(out);
541 % </SyntaxCode>
542 stest = true;
543 catch err
544 disp(err.message)
545 stest = false;
546 end
547
548 % <AlgoDescription>
549 %
550 % 1) Check the output
551 % 2) Check the rebuilt object
552 %
553 % </AlgoDescription>
554
555 atest = true;
556 if stest
557 % <AlgoCode>
558 % Check each output against the redesign of the filter with the new
559 % frequency
560 pzm_123 = miir(plist('pzmodel', pzm, 'fs', 123));
561 if ~eq(out, pzm_123, ple3), atest = false; end
562 % Check the result of the rebuilt object.
563 if ~eq(mout, out, ple2), atest = false; end
564 % </AlgoCode>
565 else
566 atest = false;
567 end
568
569 % Return a result structure
570 result = utp_prepare_result(atest, stest, dbstack, mfilename);
571 end % END UTP_08
572
573 %% UTP_09
574
575 % <TestDescription>
576 %
577 % Tests that the redesign method redesigns a parfrac filter type.
578 %
579 % </TestDescription>
580 function result = utp_09
581
582 % <SyntaxDescription>
583 %
584 % Tests that the redesign method redesigns a parfrac filter type.
585 %
586 % </SyntaxDescription>
587
588 try
589 % <SyntaxCode>
590 pfrac = parfrac([1 2], {4, 6+2i}, 1, 'my par frac', unit('V'), unit('Hz'));
591 pl = plist('parfrac', pfrac, 'fs', 1000);
592 iirpf = miir(pl);
593 out = redesign(iirpf, 123);
594
595 o1 = out.index(1);
596 o2 = out.index(2);
597 mo1 = rebuild(o1);
598 mo2 = rebuild(o2);
599 % </SyntaxCode>
600 stest = true;
601 catch err
602 disp(err.message)
603 stest = false;
604 end
605
606 % <AlgoDescription>
607 %
608 % 1) Check the output
609 % 2) Check the rebuilt object
610 %
611 % </AlgoDescription>
612
613 atest = true;
614 if stest
615 % <AlgoCode>
616 % Check each output against the redesign of the filter with the new
617 % frequency
618 pf_123 = miir(plist('parfrac', pfrac, 'fs', 123));
619 if ~eq(out, pf_123, ple3), atest = false; end
620 % Check the result of the rebuilt object.
621 if ~eq(mo1, o1, ple2), atest = false; end
622 if ~eq(mo2, o2, ple2), atest = false; end
623 % </AlgoCode>
624 else
625 atest = false;
626 end
627
628 % Return a result structure
629 result = utp_prepare_result(atest, stest, dbstack, mfilename);
630 end % END UTP_09
631
632 end