Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/pzmodel/utp_pzmodel_tomiir.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_PZMODEL_TOMIIR a set of UTPs for the pzmodel/tomiir method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_pzmodel_tomiir.m,v 1.4 2010/08/19 13:27:27 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The tomiir method of the pzmodel class converts a pole/zero model to | |
11 % an IIR filter using a bilinear transform. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_pzmodel_tomiir(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'pzmodel'; | |
22 mthd = 'tomiir'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test PZMODELs | |
30 [pz1, pz2, pz3, pz4, pz5, pzv, pzm] = get_test_objects_pzmodel; | |
31 | |
32 % Exception list for the UTPs: | |
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
34 | |
35 % Run the tests | |
36 results = [results utp_01]; % getInfo call | |
37 results = [results utp_02]; % Vector input | |
38 results = [results utp_03]; % Matrix input | |
39 results = [results utp_04]; % List input | |
40 results = [results utp_05]; % Test with mixed input | |
41 results = [results utp_06]; % Test history is working | |
42 results = [results utp_07]; % Test the modify call works | |
43 results = [results utp_08]; % Test with additional plist with the key 'axis' | |
44 results = [results utp_09]; % Test output of the data | |
45 results = [results utp_10]; % Test indirect the protected 'pzm2ab' method. two complex pole/zero pairs | |
46 results = [results utp_11]; % Test indirect the protected 'pzm2ab' method. complex pole | |
47 results = [results utp_12]; % Test indirect the protected 'pzm2ab' method. complex zero | |
48 results = [results utp_13]; % Test indirect the protected 'pzm2ab' method. real pole | |
49 results = [results utp_14]; % Test indirect the protected 'pzm2ab' method. real zero | |
50 | |
51 disp('Done.'); | |
52 disp('******************************************************'); | |
53 | |
54 elseif nargin == 1 % Check for UTP functions | |
55 if strcmp(varargin{1}, 'isutp') | |
56 results = 1; | |
57 else | |
58 results = 0; | |
59 end | |
60 else | |
61 error('### Incorrect inputs') | |
62 end | |
63 | |
64 %% UTP_01 | |
65 | |
66 % <TestDescription> | |
67 % | |
68 % Tests that the getInfo call works for this method. | |
69 % | |
70 % </TestDescription> | |
71 function result = utp_01 | |
72 | |
73 | |
74 % <SyntaxDescription> | |
75 % | |
76 % Test that the getInfo call works for no sets, all sets, and each set | |
77 % individually. | |
78 % | |
79 % </SyntaxDescription> | |
80 | |
81 try | |
82 % <SyntaxCode> | |
83 % Call for no sets | |
84 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
85 % Call for all sets | |
86 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
87 % Call for each set | |
88 for kk=1:numel(io(2).sets) | |
89 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
90 end | |
91 % </SyntaxCode> | |
92 stest = true; | |
93 catch err | |
94 disp(err.message) | |
95 stest = false; | |
96 end | |
97 | |
98 % <AlgoDescription> | |
99 % | |
100 % 1) Check that getInfo call returned an minfo object in all cases. | |
101 % 2) Check that all plists have the correct parameters. | |
102 % | |
103 % </AlgoDescription> | |
104 | |
105 atest = true; | |
106 if stest | |
107 % <AlgoCode> | |
108 % check we have minfo objects | |
109 if isa(io, 'minfo') | |
110 %%% SET 'None' | |
111 if ~isempty(io(1).sets), atest = false; end | |
112 if ~isempty(io(1).plists), atest = false; end | |
113 %%% Check all Sets | |
114 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
115 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
116 %%%%%%%%%% SET 'Default' | |
117 if io(3).plists.nparams ~= 1, atest = false; end | |
118 % Check key | |
119 if ~io(3).plists.isparam('fs'), atest = false; end | |
120 % Check default value | |
121 if ~isequal(io(3).plists.find('fs'), 1), atest = false; end | |
122 % Check options | |
123 if ~isequal(io(3).plists.getOptionsForParam('fs'), {1}), atest = false; end | |
124 end | |
125 % </AlgoCode> | |
126 else | |
127 atest = false; | |
128 end | |
129 | |
130 % Return a result structure | |
131 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
132 end % END UTP_01 | |
133 | |
134 %% UTP_02 | |
135 | |
136 % <TestDescription> | |
137 % | |
138 % Tests that the tomiir method works with a vector of PZMODEL objects as input. | |
139 % | |
140 % </TestDescription> | |
141 function result = utp_02 | |
142 | |
143 % <SyntaxDescription> | |
144 % | |
145 % Test that the tomiir method works for a vector of PZMODEL objects as input. | |
146 % | |
147 % </SyntaxDescription> | |
148 | |
149 try | |
150 % <SyntaxCode> | |
151 out = tomiir(pzv); | |
152 mout = rebuild(out); | |
153 % </SyntaxCode> | |
154 stest = true; | |
155 catch err | |
156 disp(err.message) | |
157 stest = false; | |
158 end | |
159 | |
160 % <AlgoDescription> | |
161 % | |
162 % 1) Check that the number of elements in 'out' is the same as in 'pzv' | |
163 % | |
164 % </AlgoDescription> | |
165 | |
166 atest = true; | |
167 if stest | |
168 % <AlgoCode> | |
169 % Check we have the correct number of outputs | |
170 if ~isequal(size(out), size(pzv)), atest = false; end | |
171 if ~isa(out, 'miir'), atest = false; end | |
172 % Check the rebuilt object | |
173 if ~eq(mout, out, ple2), atest = false; end | |
174 % </AlgoCode> | |
175 else | |
176 atest = false; | |
177 end | |
178 | |
179 % Return a result structure | |
180 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
181 end % END UTP_02 | |
182 | |
183 %% UTP_03 | |
184 | |
185 % <TestDescription> | |
186 % | |
187 % Tests that the tomiir method works with a matrix of PZMODEL objects as input. | |
188 % | |
189 % </TestDescription> | |
190 function result = utp_03 | |
191 | |
192 % <SyntaxDescription> | |
193 % | |
194 % Test that the tomiir method works for a matrix of PZMODEL objects as input. | |
195 % | |
196 % </SyntaxDescription> | |
197 | |
198 try | |
199 % <SyntaxCode> | |
200 out = tomiir(pzm); | |
201 mout = rebuild(out); | |
202 % </SyntaxCode> | |
203 stest = true; | |
204 catch err | |
205 disp(err.message) | |
206 stest = false; | |
207 end | |
208 | |
209 % <AlgoDescription> | |
210 % | |
211 % 1) Check that the number of elements in 'out' is the same as in 'pzm' | |
212 % | |
213 % </AlgoDescription> | |
214 | |
215 atest = true; | |
216 if stest | |
217 % <AlgoCode> | |
218 % Check we have the correct number of outputs | |
219 if ~isequal(size(out), size(pzm)), atest = false; end | |
220 if ~isa(out, 'miir'), atest = false; end | |
221 % Check the rebuilt object | |
222 for ii = 1:numel(out) | |
223 if ~eq(mout(ii), out(ii), ple2), atest = false; end | |
224 end | |
225 % </AlgoCode> | |
226 else | |
227 atest = false; | |
228 end | |
229 | |
230 % Return a result structure | |
231 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
232 end % END UTP_03 | |
233 | |
234 %% UTP_04 | |
235 | |
236 % <TestDescription> | |
237 % | |
238 % Tests that the tomiir method works with a list of PZMODEL objects as input. | |
239 % | |
240 % </TestDescription> | |
241 function result = utp_04 | |
242 | |
243 % <SyntaxDescription> | |
244 % | |
245 % Test that the tomiir method works for a list of PZMODEL objects as input. | |
246 % | |
247 % </SyntaxDescription> | |
248 | |
249 try | |
250 % <SyntaxCode> | |
251 out = tomiir(pz1,pz2,pz3); | |
252 mout = rebuild(out); | |
253 % </SyntaxCode> | |
254 stest = true; | |
255 catch err | |
256 disp(err.message) | |
257 stest = false; | |
258 end | |
259 | |
260 % <AlgoDescription> | |
261 % | |
262 % 1) Check that the number of elements in 'out' is the same as in | |
263 % input. | |
264 % 2) Check that each output PZMODEL object contains the correct data. | |
265 % | |
266 % </AlgoDescription> | |
267 | |
268 atest = true; | |
269 pzin = [pz1,pz2,pz3]; | |
270 if stest | |
271 % <AlgoCode> | |
272 % Check we have the correct number of outputs | |
273 if ~isequal(size(out), size(pzin)), atest = false; end | |
274 if ~isa(out, 'miir'), atest = false; end | |
275 % Check the rebuilt object | |
276 if ~eq(mout, out, ple2), atest = false; end | |
277 % </AlgoCode> | |
278 else | |
279 atest = false; | |
280 end | |
281 | |
282 % Return a result structure | |
283 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
284 end % END UTP_04 | |
285 | |
286 %% UTP_05 | |
287 | |
288 % <TestDescription> | |
289 % | |
290 % Tests that the tomiir method works with a mix of different shaped PZMODEL objects as | |
291 % input. | |
292 % | |
293 % </TestDescription> | |
294 function result = utp_05 | |
295 | |
296 % <SyntaxDescription> | |
297 % | |
298 % Test that the tomiir method works with an input of matrices and vectors | |
299 % and single PZMODEL objects. | |
300 % | |
301 % </SyntaxDescription> | |
302 | |
303 try | |
304 % <SyntaxCode> | |
305 out = tomiir(pz1,pzv,pz2,pzm,pz3); | |
306 mout = rebuild(out); | |
307 % </SyntaxCode> | |
308 stest = true; | |
309 catch err | |
310 disp(err.message) | |
311 stest = false; | |
312 end | |
313 | |
314 % <AlgoDescription> | |
315 % | |
316 % 1) Check that the number of elements in 'out' is the same as in | |
317 % input. | |
318 % 2) Check that each output PZMODEL object contains the correct data. | |
319 % | |
320 % </AlgoDescription> | |
321 | |
322 atest = true; | |
323 pzin = [pz1,reshape(pzv,1,[]),pz2,reshape(pzm,1,[]),pz3]; | |
324 if stest | |
325 % <AlgoCode> | |
326 % Check we have the correct number of outputs | |
327 if ~isequal(size(out), size(pzin)), atest = false; end | |
328 if ~isa(out, 'miir'), atest = false; end | |
329 % Check the rebuilt object | |
330 if ~eq(mout, out, ple2), atest = false; end | |
331 % </AlgoCode> | |
332 else | |
333 atest = false; | |
334 end | |
335 | |
336 % Return a result structure | |
337 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
338 end % END UTP_05 | |
339 | |
340 %% UTP_06 | |
341 | |
342 % <TestDescription> | |
343 % | |
344 % Tests that the tomiir method properly applies history. | |
345 % | |
346 % </TestDescription> | |
347 function result = utp_06 | |
348 | |
349 % <SyntaxDescription> | |
350 % | |
351 % Test that the result of applying the tomiir method can be processed back. | |
352 % | |
353 % </SyntaxDescription> | |
354 | |
355 try | |
356 % <SyntaxCode> | |
357 out = tomiir(pz5); | |
358 mout = rebuild(out); | |
359 % </SyntaxCode> | |
360 stest = true; | |
361 catch err | |
362 disp(err.message) | |
363 stest = false; | |
364 end | |
365 | |
366 % <AlgoDescription> | |
367 % | |
368 % 1) Check that the last entry in the history of 'out' corresponds to | |
369 % 'tomiir'. | |
370 % 2) Check that re-built object is the same object as the input. | |
371 % | |
372 % </AlgoDescription> | |
373 | |
374 atest = true; | |
375 if stest | |
376 % <AlgoCode> | |
377 % Check the last step in the history of 'out' | |
378 if ~strcmp(out.hist.methodInfo.mname, 'tomiir'), atest = false; end | |
379 % Run 'test.m' and check the result | |
380 if ~eq(mout, out, ple2), atest = false; end | |
381 % </AlgoCode> | |
382 else | |
383 atest = false; | |
384 end | |
385 | |
386 % Return a result structure | |
387 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
388 end % END UTP_06 | |
389 | |
390 %% UTP_07 | |
391 | |
392 % <TestDescription> | |
393 % | |
394 % Tests that the tomiir method can modify the input PZMODEL object. | |
395 % | |
396 % </TestDescription> | |
397 function result = utp_07 | |
398 | |
399 % <SyntaxDescription> | |
400 % | |
401 % Test that the tomiir method can not modify the input PZMODEL object . | |
402 % The method must throw an error for the modifier call. | |
403 % | |
404 % </SyntaxDescription> | |
405 | |
406 % <SyntaxCode> | |
407 try | |
408 ain.tomiir(); | |
409 stest = false; | |
410 catch err | |
411 stest = true; | |
412 end | |
413 % </SyntaxCode> | |
414 | |
415 % <AlgoDescription> | |
416 % | |
417 % 1) Nothing to check. | |
418 % | |
419 % </AlgoDescription> | |
420 | |
421 atest = true; | |
422 if stest | |
423 % <AlgoCode> | |
424 % </AlgoCode> | |
425 else | |
426 atest = false; | |
427 end | |
428 | |
429 % Return a result structure | |
430 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
431 end % END UTP_07 | |
432 | |
433 %% UTP_08 | |
434 | |
435 % <TestDescription> | |
436 % | |
437 % Control the method with a plist. | |
438 % | |
439 % </TestDescription> | |
440 function result = utp_08 | |
441 | |
442 % <SyntaxDescription> | |
443 % | |
444 % Test that the tomiir method use the different values in a plist. | |
445 % | |
446 % </SyntaxDescription> | |
447 | |
448 try | |
449 % <SyntaxCode> | |
450 fs = 5; | |
451 pl = plist('fs', fs); | |
452 out = tomiir(pz5, pl); | |
453 mout = rebuild(out); | |
454 % </SyntaxCode> | |
455 stest = true; | |
456 catch err | |
457 disp(err.message) | |
458 stest = false; | |
459 end | |
460 | |
461 % <AlgoDescription> | |
462 % | |
463 % 1) Check the output | |
464 % 2) Check the re-built object | |
465 % | |
466 % </AlgoDescription> | |
467 | |
468 atest = true; | |
469 if stest | |
470 % <AlgoCode> | |
471 % Check the output | |
472 if ~isa(out, 'miir'), atest = false; end | |
473 if out.fs ~= fs, atest = false; end | |
474 % Check the rebuilt object | |
475 if ~eq(mout, out, ple2), atest = false; end | |
476 % </AlgoCode> | |
477 else | |
478 atest = false; | |
479 end | |
480 | |
481 % Return a result structure | |
482 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
483 end % END UTP_08 | |
484 | |
485 %% UTP_09 | |
486 | |
487 % <TestDescription> | |
488 % | |
489 % Check that the tomiir method pass back the output objects to a list of | |
490 % output variables or to a single variable. | |
491 % | |
492 % </TestDescription> | |
493 function result = utp_09 | |
494 | |
495 % <SyntaxDescription> | |
496 % | |
497 % Call the method with a list of output variables and with a single output | |
498 % variable. Additionaly check that the rebuild method works on the output. | |
499 % | |
500 % </SyntaxDescription> | |
501 | |
502 try | |
503 % <SyntaxCode> | |
504 [o1, o2] = tomiir(pz5, pz4); | |
505 o3 = tomiir(pz5, pz4); | |
506 mout1 = rebuild(o1); | |
507 mout2 = rebuild(o2); | |
508 mout3 = rebuild(o3); | |
509 % </SyntaxCode> | |
510 stest = true; | |
511 catch err | |
512 disp(err.message) | |
513 stest = false; | |
514 end | |
515 | |
516 % <AlgoDescription> | |
517 % | |
518 % 1) Check that the output contains the right number of objects | |
519 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
520 % | |
521 % </AlgoDescription> | |
522 | |
523 atest = true; | |
524 if stest | |
525 % <AlgoCode> | |
526 % Check the number of outputs | |
527 if numel(o1) ~=1, atest = false; end | |
528 if numel(o2) ~=1, atest = false; end | |
529 if numel(o3) ~=2, atest = false; end | |
530 % Check the rebuilding of the object | |
531 if ~eq(o1, mout1, ple2), atest = false; end | |
532 if ~eq(o2, mout2, ple2), atest = false; end | |
533 if ~eq(o3, mout3, ple2), atest = false; end | |
534 % </AlgoCode> | |
535 else | |
536 atest = false; | |
537 end | |
538 | |
539 % Return a result structure | |
540 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
541 end % END UTP_09 | |
542 | |
543 %% UTP_10 | |
544 | |
545 % <TestDescription> | |
546 % | |
547 % Check indirect the protected 'pzm2ab' method because tomiir uses this | |
548 % method to get the a and b of the iir object. | |
549 % | |
550 % </TestDescription> | |
551 function result = utp_10 | |
552 | |
553 % <SyntaxDescription> | |
554 % | |
555 % Create some special pole/zero models to test the 'pzm2ab' method | |
556 % indirect with the tomiir method. Test with complex pole/zero pairs. | |
557 % This UTP define a simple method to get the a-, and b-value from a | |
558 % complex pole/zero pair. | |
559 % It uses the following code: | |
560 function [a,b] = utp_cpz2ab(pf, pq, zf, zq, fs) | |
561 wp = pf*2*pi; | |
562 wp2 = wp^2; | |
563 wz = zf*2*pi; | |
564 wz2 = wz^2; | |
565 | |
566 k = 4*fs*fs + 2*wp*fs/pq + wp2; | |
567 | |
568 a(1) = (4*fs*fs + 2*wz*fs/zq + wz2)/k; | |
569 a(2) = (2*wz2 - 8*fs*fs)/k; | |
570 a(3) = (4*fs*fs - 2*wz*fs/zq + wz2)/k; | |
571 b(1) = 1; | |
572 b(2) = (2*wp2 - 8*fs*fs)/k; | |
573 b(3) = (wp2 + 4*fs*fs - 2*wp*fs/pq)/k; | |
574 | |
575 g = sum(a) / sum(b); | |
576 a = a / g; | |
577 end | |
578 % </SyntaxDescription> | |
579 | |
580 try | |
581 % <SyntaxCode> | |
582 pzm1 = pzmodel(1, pz(1+2i), pz(1+5i)); | |
583 pzm2 = pzmodel(1, [pz(1+2i) pz(2+2i)], [pz(1+5i) pz(2+5i)]); | |
584 out1 = tomiir(pzm1); | |
585 out2 = tomiir(pzm2); | |
586 | |
587 mout1 = rebuild(out1); | |
588 mout2 = rebuild(out2); | |
589 % </SyntaxCode> | |
590 stest = true; | |
591 catch err | |
592 disp(err.message) | |
593 stest = false; | |
594 end | |
595 | |
596 % <AlgoDescription> | |
597 % | |
598 % 1) Check the output | |
599 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
600 % | |
601 % </AlgoDescription> | |
602 | |
603 atest = true; | |
604 if stest | |
605 % <AlgoCode> | |
606 % Check the output class | |
607 if ~isa(out1, 'miir'), atest = false; end | |
608 if ~isa(out2, 'miir'), atest = false; end | |
609 % Comput the a and b from a complex pole/zero pair | |
610 [a,b] = utp_cpz2ab(pzm1.poles.f, pzm1.poles.q, pzm1.zeros.f, pzm1.zeros.q, 1); | |
611 % Compute the cascade of the two different filters (necessary for pzm2): | |
612 [a1,b1] = utp_cpz2ab(pzm2.poles(1).f, pzm2.poles(1).q, pzm2.zeros(1).f, pzm2.zeros(1).q, 1); | |
613 [a2,b2] = utp_cpz2ab(pzm2.poles(2).f, pzm2.poles(2).q, pzm2.zeros(2).f, pzm2.zeros(2).q, 1); | |
614 ca(1) = a1(1)*a2(1); | |
615 ca(2) = a1(1)*a2(2) + a1(2)*a2(1); | |
616 ca(3) = a1(1)*a2(3) + a1(2)*a2(2) + a1(3)*a2(1); | |
617 ca(4) = a1(2)*a2(3) + a1(3)*a2(2); | |
618 ca(5) = a1(3)*a2(3); | |
619 cb(1) = b1(1)*b2(1); | |
620 cb(2) = b1(1)*b2(2) + b1(2)*b2(1); | |
621 cb(3) = b1(1)*b2(3) + b1(2)*b2(2) + b1(3)*b2(1); | |
622 cb(4) = b1(2)*b2(3) + b1(3)*b2(2); | |
623 cb(5) = b1(3)*b2(3); | |
624 % Check a and b | |
625 if ~isequal(a, out1.a), atest = false; end | |
626 if ~isequal(b, out1.b), atest = false; end | |
627 if ~isequal(ca, out2.a), atest = false; end | |
628 if ~isequal(cb, out2.b), atest = false; end | |
629 % Check the rebuilt object | |
630 if ~eq(out1, mout1, ple2), atest = false; end | |
631 if ~eq(out2, mout2, ple2), atest = false; end | |
632 % </AlgoCode> | |
633 else | |
634 atest = false; | |
635 end | |
636 | |
637 % Return a result structure | |
638 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
639 end % END UTP_10 | |
640 | |
641 %% UTP_11 | |
642 | |
643 % <TestDescription> | |
644 % | |
645 % Check indirect the protected 'pzm2ab' method because tomiir uses this | |
646 % method to get the a and b of the iir object. | |
647 % | |
648 % </TestDescription> | |
649 function result = utp_11 | |
650 | |
651 % <SyntaxDescription> | |
652 % | |
653 % Create some special pole/zero models to test the 'pzm2ab' method indirect | |
654 % with the tomiir method. Test with complex poles. | |
655 % This UTPs define a simple method to get the a-, and b-value from a | |
656 % complex pole. It uses the following code: | |
657 function [a,b] = utp_cp2iir(pf, pq, fs) | |
658 w0 = pf*2*pi; | |
659 w02 = w0^2; | |
660 | |
661 k = (pq*w02 + 4*pq*fs*fs + 2*w0*fs) / (pq*w02); | |
662 | |
663 b(1) = 1; | |
664 b(2) = (2*w02-8*fs*fs) / (k*w02); | |
665 b(3) = (pq*w02 + 4*pq*fs*fs - 2*w0*fs) / (k*pq*w02); | |
666 | |
667 a(1) = 1/k; | |
668 a(2) = -2/k; | |
669 a(3) = -1/k; | |
670 a = a*-2; | |
671 end | |
672 % </SyntaxDescription> | |
673 | |
674 try | |
675 % <SyntaxCode> | |
676 pzm1 = pzmodel(1, pz(1+2i), []); | |
677 pzm2 = pzmodel(1, [pz(1+2i) pz(2+2i)], []); | |
678 out1 = tomiir(pzm1); | |
679 out2 = tomiir(pzm2); | |
680 | |
681 mout1 = rebuild(out1); | |
682 mout2 = rebuild(out2); | |
683 % </SyntaxCode> | |
684 stest = true; | |
685 catch err | |
686 disp(err.message) | |
687 stest = false; | |
688 end | |
689 | |
690 % <AlgoDescription> | |
691 % | |
692 % 1) Check the output | |
693 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
694 % | |
695 % </AlgoDescription> | |
696 | |
697 atest = true; | |
698 if stest | |
699 % <AlgoCode> | |
700 % Check the output class | |
701 if ~isa(out1, 'miir'), atest = false; end | |
702 if ~isa(out2, 'miir'), atest = false; end | |
703 % Comput the a and b from a complex pole | |
704 [a,b] = utp_cp2iir(pzm1.poles.f, pzm1.poles.q, 1); | |
705 % Compute the cascade of the two different filters (necessary for pzm2): | |
706 [a1,b1] = utp_cp2iir(pzm2.poles(1).f, pzm2.poles(1).q, 1); | |
707 [a2,b2] = utp_cp2iir(pzm2.poles(2).f, pzm2.poles(2).q, 1); | |
708 ca(1) = a1(1)*a2(1); | |
709 ca(2) = a1(1)*a2(2) + a1(2)*a2(1); | |
710 ca(3) = a1(1)*a2(3) + a1(2)*a2(2) + a1(3)*a2(1); | |
711 ca(4) = a1(2)*a2(3) + a1(3)*a2(2); | |
712 ca(5) = a1(3)*a2(3); | |
713 cb(1) = b1(1)*b2(1); | |
714 cb(2) = b1(1)*b2(2) + b1(2)*b2(1); | |
715 cb(3) = b1(1)*b2(3) + b1(2)*b2(2) + b1(3)*b2(1); | |
716 cb(4) = b1(2)*b2(3) + b1(3)*b2(2); | |
717 cb(5) = b1(3)*b2(3); | |
718 % Check a and b | |
719 if ~isequal(a, out1.a), atest = false; end | |
720 if ~isequal(b, out1.b), atest = false; end | |
721 if ~isequal(ca, out2.a), atest = false; end | |
722 if ~isequal(cb, out2.b), atest = false; end | |
723 % Check the rebuilt object | |
724 if ~eq(out1, mout1, ple2), atest = false; end | |
725 if ~eq(out2, mout2, ple2), atest = false; end | |
726 % </AlgoCode> | |
727 else | |
728 atest = false; | |
729 end | |
730 | |
731 % Return a result structure | |
732 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
733 end % END UTP_11 | |
734 | |
735 %% UTP_12 | |
736 | |
737 % <TestDescription> | |
738 % | |
739 % Check indirect the protected 'pzm2ab' method because tomiir uses this | |
740 % method to get the a and b of the iir object. | |
741 % | |
742 % </TestDescription> | |
743 function result = utp_12 | |
744 | |
745 % <SyntaxDescription> | |
746 % | |
747 % Create some special pole/zero models to test the 'pzm2ab' method indirect | |
748 % with the tomiir method. Test with complex zeros. | |
749 % This UTPs define a simple method to get the a-, and b-value from a | |
750 % complex zero. It uses the following code: | |
751 function [a,b] = utp_cz2iir(zf, zq, fs) | |
752 w0 = zf*2*pi; | |
753 w02 = w0^2; | |
754 | |
755 a(1) = (-zq*w02/2 - 2*zq*fs*fs - w0*fs) / (zq*w02); | |
756 a(2) = (-w02+4*fs*fs) / w02; | |
757 a(3) = (-zq*w02/2 - 2*zq*fs*fs + w0*fs) / (zq*w02); | |
758 | |
759 b(1) = 1; | |
760 b(2) = -2; | |
761 b(3) = -1; | |
762 end | |
763 % </SyntaxDescription> | |
764 | |
765 try | |
766 % <SyntaxCode> | |
767 pzm1 = pzmodel(1, [], pz(1+2i)); | |
768 pzm2 = pzmodel(1, [], [pz(1+2i) pz(2+2i)]); | |
769 out1 = tomiir(pzm1); | |
770 out2 = tomiir(pzm2); | |
771 | |
772 mout1 = rebuild(out1); | |
773 mout2 = rebuild(out2); | |
774 % </SyntaxCode> | |
775 stest = true; | |
776 catch err | |
777 disp(err.message) | |
778 stest = false; | |
779 end | |
780 | |
781 % <AlgoDescription> | |
782 % | |
783 % 1) Check the output | |
784 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
785 % | |
786 % </AlgoDescription> | |
787 | |
788 atest = true; | |
789 if stest | |
790 % <AlgoCode> | |
791 % Check the output class | |
792 if ~isa(out1, 'miir'), atest = false; end | |
793 if ~isa(out2, 'miir'), atest = false; end | |
794 % Comput the a and b from a complex zero | |
795 [a,b] = utp_cz2iir(pzm1.zeros.f, pzm1.zeros.q, 1); | |
796 % Compute the cascade of the two different filters (necessary for pzm2): | |
797 [a1,b1] = utp_cz2iir(pzm2.zeros(1).f, pzm2.zeros(1).q, 1); | |
798 [a2,b2] = utp_cz2iir(pzm2.zeros(2).f, pzm2.zeros(2).q, 1); | |
799 ca(1) = a1(1)*a2(1); | |
800 ca(2) = a1(1)*a2(2) + a1(2)*a2(1); | |
801 ca(3) = a1(1)*a2(3) + a1(2)*a2(2) + a1(3)*a2(1); | |
802 ca(4) = a1(2)*a2(3) + a1(3)*a2(2); | |
803 ca(5) = a1(3)*a2(3); | |
804 cb(1) = b1(1)*b2(1); | |
805 cb(2) = b1(1)*b2(2) + b1(2)*b2(1); | |
806 cb(3) = b1(1)*b2(3) + b1(2)*b2(2) + b1(3)*b2(1); | |
807 cb(4) = b1(2)*b2(3) + b1(3)*b2(2); | |
808 cb(5) = b1(3)*b2(3); | |
809 % Check a and b | |
810 if ~isequal(a, out1.a), atest = false; end | |
811 if ~isequal(b, out1.b), atest = false; end | |
812 if ~isequal(ca, out2.a), atest = false; end | |
813 if ~isequal(cb, out2.b), atest = false; end | |
814 % Check the rebuilt object | |
815 if ~eq(out1, mout1, ple2), atest = false; end | |
816 if ~eq(out2, mout2, ple2), atest = false; end | |
817 % </AlgoCode> | |
818 else | |
819 atest = false; | |
820 end | |
821 | |
822 % Return a result structure | |
823 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
824 end % END UTP_12 | |
825 | |
826 %% UTP_13 | |
827 | |
828 % <TestDescription> | |
829 % | |
830 % Check indirect the protected 'pzm2ab' method because tomiir uses this | |
831 % method to get the a and b of the iir object. | |
832 % | |
833 % </TestDescription> | |
834 function result = utp_13 | |
835 | |
836 % <SyntaxDescription> | |
837 % | |
838 % Create some special pole/zero models to test the 'pzm2ab' method indirect | |
839 % with the tomiir method. Test with real poles. | |
840 % This UTPs define a simple method to get the a-, and b-value from a | |
841 % real pole. It uses the following code: | |
842 function [a,b] = utp_rp2iir(pf, fs) | |
843 w0 = pf*2*pi; | |
844 a(1) = w0 / (2*fs + w0); | |
845 a(2) = a(1); | |
846 b(1) = 1; | |
847 b(2) = (w0-2*fs) / (w0+2*fs); | |
848 end | |
849 % </SyntaxDescription> | |
850 | |
851 try | |
852 % <SyntaxCode> | |
853 pzm1 = pzmodel(1, pz(1), []); | |
854 pzm2 = pzmodel(1, [pz(1) pz(2)], []); | |
855 out1 = tomiir(pzm1); | |
856 out2 = tomiir(pzm2); | |
857 | |
858 mout1 = rebuild(out1); | |
859 mout2 = rebuild(out2); | |
860 % </SyntaxCode> | |
861 stest = true; | |
862 catch err | |
863 disp(err.message) | |
864 stest = false; | |
865 end | |
866 | |
867 % <AlgoDescription> | |
868 % | |
869 % 1) Check the output | |
870 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
871 % | |
872 % </AlgoDescription> | |
873 | |
874 atest = true; | |
875 if stest | |
876 % <AlgoCode> | |
877 % Check the output class | |
878 if ~isa(out1, 'miir'), atest = false; end | |
879 if ~isa(out2, 'miir'), atest = false; end | |
880 % Comput the a and b from a real pole | |
881 [a,b] = utp_rp2iir(pzm1.poles.f, 1); | |
882 % Compute the cascade of the two different filters (necessary for pzm2): | |
883 [a1,b1] = utp_rp2iir(pzm2.poles(1).f, 1); | |
884 [a2,b2] = utp_rp2iir(pzm2.poles(2).f, 1); | |
885 ca(1) = a1(1)*a2(1); | |
886 ca(2) = a1(1)*a2(2) + a1(2)*a2(1); | |
887 ca(3) = a1(2)*a2(2); | |
888 cb(1) = b1(1)*b2(1); | |
889 cb(2) = b1(1)*b2(2) + b1(2)*b2(1); | |
890 cb(3) = b1(2)*b2(2); | |
891 % Check a and b | |
892 if ~isequal(a, out1.a), atest = false; end | |
893 if ~isequal(b, out1.b), atest = false; end | |
894 if ~isequal(ca, out2.a), atest = false; end | |
895 if ~isequal(cb, out2.b), atest = false; end | |
896 % Check the rebuilt object | |
897 if ~eq(out1, mout1, ple2), atest = false; end | |
898 if ~eq(out2, mout2, ple2), atest = false; end | |
899 % </AlgoCode> | |
900 else | |
901 atest = false; | |
902 end | |
903 | |
904 % Return a result structure | |
905 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
906 end % END UTP_13 | |
907 | |
908 %% UTP_14 | |
909 | |
910 % <TestDescription> | |
911 % | |
912 % Check indirect the protected 'pzm2ab' method because tomiir uses this | |
913 % method to get the a and b of the iir object. | |
914 % | |
915 % </TestDescription> | |
916 function result = utp_14 | |
917 | |
918 % <SyntaxDescription> | |
919 % | |
920 % Create some special pole/zero models to test the 'pzm2ab' method indirect | |
921 % with the tomiir method. Test with real zeros. | |
922 % This UTPs define a simple method to get the a-, and b-value from a | |
923 % real zero. It uses the following code: | |
924 function [a,b] = utp_rp2iir(zf, fs) | |
925 w0 = zf*2*pi; | |
926 a(1) = (2*fs + w0) / w0; | |
927 a(2) = (-2*fs + w0) / w0; | |
928 b(1) = 1; | |
929 b(2) = 1; | |
930 end | |
931 % </SyntaxDescription> | |
932 | |
933 try | |
934 % <SyntaxCode> | |
935 pzm1 = pzmodel(1, [], pz(1)); | |
936 pzm2 = pzmodel(1, [], [pz(1) pz(2)]); | |
937 out1 = tomiir(pzm1); | |
938 out2 = tomiir(pzm2); | |
939 | |
940 mout1 = rebuild(out1); | |
941 mout2 = rebuild(out2); | |
942 % </SyntaxCode> | |
943 stest = true; | |
944 catch err | |
945 disp(err.message) | |
946 stest = false; | |
947 end | |
948 | |
949 % <AlgoDescription> | |
950 % | |
951 % 1) Check the output | |
952 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
953 % | |
954 % </AlgoDescription> | |
955 | |
956 atest = true; | |
957 if stest | |
958 % <AlgoCode> | |
959 % Check the output class | |
960 if ~isa(out1, 'miir'), atest = false; end | |
961 if ~isa(out2, 'miir'), atest = false; end | |
962 % Comput the a and b from a real zero | |
963 [a,b] = utp_rp2iir(pzm1.zeros.f, 1); | |
964 % Compute the cascade of the two different filters (necessary for pzm2): | |
965 [a1,b1] = utp_rp2iir(pzm2.zeros(1).f, 1); | |
966 [a2,b2] = utp_rp2iir(pzm2.zeros(2).f, 1); | |
967 ca(1) = a1(1)*a2(1); | |
968 ca(2) = a1(1)*a2(2) + a1(2)*a2(1); | |
969 ca(3) = a1(2)*a2(2); | |
970 cb(1) = b1(1)*b2(1); | |
971 cb(2) = b1(1)*b2(2) + b1(2)*b2(1); | |
972 cb(3) = b1(2)*b2(2); | |
973 % Check a and b | |
974 if ~isequal(a, out1.a), atest = false; end | |
975 if ~isequal(b, out1.b), atest = false; end | |
976 if ~isequal(ca, out2.a), atest = false; end | |
977 if ~isequal(cb, out2.b), atest = false; end | |
978 % Check the rebuilt object | |
979 if ~eq(out1, mout1, ple2), atest = false; end | |
980 if ~eq(out2, mout2, ple2), atest = false; end | |
981 % </AlgoCode> | |
982 else | |
983 atest = false; | |
984 end | |
985 | |
986 % Return a result structure | |
987 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
988 end % END UTP_14 | |
989 | |
990 end |