Mercurial > hg > ltpda
view 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 |
line wrap: on
line source
% UTP_PZMODEL_TOMIIR a set of UTPs for the pzmodel/tomiir method % % M Hewitson 06-08-08 % % $Id: utp_pzmodel_tomiir.m,v 1.4 2010/08/19 13:27:27 ingo Exp $ % % <MethodDescription> % % The tomiir method of the pzmodel class converts a pole/zero model to % an IIR filter using a bilinear transform. % % </MethodDescription> function results = utp_pzmodel_tomiir(varargin) % Check the inputs if nargin == 0 % Some keywords class = 'pzmodel'; mthd = 'tomiir'; results = []; disp('******************************************************'); disp(['**** Running UTPs for ' class '/' mthd]); disp('******************************************************'); % Test PZMODELs [pz1, pz2, pz3, pz4, pz5, pzv, pzm] = get_test_objects_pzmodel; % Exception list for the UTPs: [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); % Run the tests results = [results utp_01]; % getInfo call results = [results utp_02]; % Vector input results = [results utp_03]; % Matrix input results = [results utp_04]; % List input results = [results utp_05]; % Test with mixed input results = [results utp_06]; % Test history is working results = [results utp_07]; % Test the modify call works results = [results utp_08]; % Test with additional plist with the key 'axis' results = [results utp_09]; % Test output of the data results = [results utp_10]; % Test indirect the protected 'pzm2ab' method. two complex pole/zero pairs results = [results utp_11]; % Test indirect the protected 'pzm2ab' method. complex pole results = [results utp_12]; % Test indirect the protected 'pzm2ab' method. complex zero results = [results utp_13]; % Test indirect the protected 'pzm2ab' method. real pole results = [results utp_14]; % Test indirect the protected 'pzm2ab' method. real zero disp('Done.'); disp('******************************************************'); elseif nargin == 1 % Check for UTP functions if strcmp(varargin{1}, 'isutp') results = 1; else results = 0; end else error('### Incorrect inputs') end %% UTP_01 % <TestDescription> % % Tests that the getInfo call works for this method. % % </TestDescription> function result = utp_01 % <SyntaxDescription> % % Test that the getInfo call works for no sets, all sets, and each set % individually. % % </SyntaxDescription> try % <SyntaxCode> % Call for no sets io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); % Call for all sets io(2) = eval([class '.getInfo(''' mthd ''')']); % Call for each set for kk=1:numel(io(2).sets) io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); end % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that getInfo call returned an minfo object in all cases. % 2) Check that all plists have the correct parameters. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % check we have minfo objects if isa(io, 'minfo') %%% SET 'None' if ~isempty(io(1).sets), atest = false; end if ~isempty(io(1).plists), atest = false; end %%% Check all Sets if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end %%%%%%%%%% SET 'Default' if io(3).plists.nparams ~= 1, atest = false; end % Check key if ~io(3).plists.isparam('fs'), atest = false; end % Check default value if ~isequal(io(3).plists.find('fs'), 1), atest = false; end % Check options if ~isequal(io(3).plists.getOptionsForParam('fs'), {1}), atest = false; end end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_01 %% UTP_02 % <TestDescription> % % Tests that the tomiir method works with a vector of PZMODEL objects as input. % % </TestDescription> function result = utp_02 % <SyntaxDescription> % % Test that the tomiir method works for a vector of PZMODEL objects as input. % % </SyntaxDescription> try % <SyntaxCode> out = tomiir(pzv); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the number of elements in 'out' is the same as in 'pzv' % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check we have the correct number of outputs if ~isequal(size(out), size(pzv)), atest = false; end if ~isa(out, 'miir'), atest = false; end % Check the rebuilt object if ~eq(mout, out, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_02 %% UTP_03 % <TestDescription> % % Tests that the tomiir method works with a matrix of PZMODEL objects as input. % % </TestDescription> function result = utp_03 % <SyntaxDescription> % % Test that the tomiir method works for a matrix of PZMODEL objects as input. % % </SyntaxDescription> try % <SyntaxCode> out = tomiir(pzm); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the number of elements in 'out' is the same as in 'pzm' % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check we have the correct number of outputs if ~isequal(size(out), size(pzm)), atest = false; end if ~isa(out, 'miir'), atest = false; end % Check the rebuilt object for ii = 1:numel(out) if ~eq(mout(ii), out(ii), ple2), atest = false; end end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_03 %% UTP_04 % <TestDescription> % % Tests that the tomiir method works with a list of PZMODEL objects as input. % % </TestDescription> function result = utp_04 % <SyntaxDescription> % % Test that the tomiir method works for a list of PZMODEL objects as input. % % </SyntaxDescription> try % <SyntaxCode> out = tomiir(pz1,pz2,pz3); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the number of elements in 'out' is the same as in % input. % 2) Check that each output PZMODEL object contains the correct data. % % </AlgoDescription> atest = true; pzin = [pz1,pz2,pz3]; if stest % <AlgoCode> % Check we have the correct number of outputs if ~isequal(size(out), size(pzin)), atest = false; end if ~isa(out, 'miir'), atest = false; end % Check the rebuilt object if ~eq(mout, out, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_04 %% UTP_05 % <TestDescription> % % Tests that the tomiir method works with a mix of different shaped PZMODEL objects as % input. % % </TestDescription> function result = utp_05 % <SyntaxDescription> % % Test that the tomiir method works with an input of matrices and vectors % and single PZMODEL objects. % % </SyntaxDescription> try % <SyntaxCode> out = tomiir(pz1,pzv,pz2,pzm,pz3); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the number of elements in 'out' is the same as in % input. % 2) Check that each output PZMODEL object contains the correct data. % % </AlgoDescription> atest = true; pzin = [pz1,reshape(pzv,1,[]),pz2,reshape(pzm,1,[]),pz3]; if stest % <AlgoCode> % Check we have the correct number of outputs if ~isequal(size(out), size(pzin)), atest = false; end if ~isa(out, 'miir'), atest = false; end % Check the rebuilt object if ~eq(mout, out, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_05 %% UTP_06 % <TestDescription> % % Tests that the tomiir method properly applies history. % % </TestDescription> function result = utp_06 % <SyntaxDescription> % % Test that the result of applying the tomiir method can be processed back. % % </SyntaxDescription> try % <SyntaxCode> out = tomiir(pz5); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the last entry in the history of 'out' corresponds to % 'tomiir'. % 2) Check that re-built object is the same object as the input. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the last step in the history of 'out' if ~strcmp(out.hist.methodInfo.mname, 'tomiir'), atest = false; end % Run 'test.m' and check the result if ~eq(mout, out, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_06 %% UTP_07 % <TestDescription> % % Tests that the tomiir method can modify the input PZMODEL object. % % </TestDescription> function result = utp_07 % <SyntaxDescription> % % Test that the tomiir method can not modify the input PZMODEL object . % The method must throw an error for the modifier call. % % </SyntaxDescription> % <SyntaxCode> try ain.tomiir(); stest = false; catch err stest = true; end % </SyntaxCode> % <AlgoDescription> % % 1) Nothing to check. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_07 %% UTP_08 % <TestDescription> % % Control the method with a plist. % % </TestDescription> function result = utp_08 % <SyntaxDescription> % % Test that the tomiir method use the different values in a plist. % % </SyntaxDescription> try % <SyntaxCode> fs = 5; pl = plist('fs', fs); out = tomiir(pz5, pl); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check the re-built object % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the output if ~isa(out, 'miir'), atest = false; end if out.fs ~= fs, atest = false; end % Check the rebuilt object if ~eq(mout, out, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_08 %% UTP_09 % <TestDescription> % % Check that the tomiir method pass back the output objects to a list of % output variables or to a single variable. % % </TestDescription> function result = utp_09 % <SyntaxDescription> % % Call the method with a list of output variables and with a single output % variable. Additionaly check that the rebuild method works on the output. % % </SyntaxDescription> try % <SyntaxCode> [o1, o2] = tomiir(pz5, pz4); o3 = tomiir(pz5, pz4); mout1 = rebuild(o1); mout2 = rebuild(o2); mout3 = rebuild(o3); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the output contains the right number of objects % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the number of outputs if numel(o1) ~=1, atest = false; end if numel(o2) ~=1, atest = false; end if numel(o3) ~=2, atest = false; end % Check the rebuilding of the object if ~eq(o1, mout1, ple2), atest = false; end if ~eq(o2, mout2, ple2), atest = false; end if ~eq(o3, mout3, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_09 %% UTP_10 % <TestDescription> % % Check indirect the protected 'pzm2ab' method because tomiir uses this % method to get the a and b of the iir object. % % </TestDescription> function result = utp_10 % <SyntaxDescription> % % Create some special pole/zero models to test the 'pzm2ab' method % indirect with the tomiir method. Test with complex pole/zero pairs. % This UTP define a simple method to get the a-, and b-value from a % complex pole/zero pair. % It uses the following code: function [a,b] = utp_cpz2ab(pf, pq, zf, zq, fs) wp = pf*2*pi; wp2 = wp^2; wz = zf*2*pi; wz2 = wz^2; k = 4*fs*fs + 2*wp*fs/pq + wp2; a(1) = (4*fs*fs + 2*wz*fs/zq + wz2)/k; a(2) = (2*wz2 - 8*fs*fs)/k; a(3) = (4*fs*fs - 2*wz*fs/zq + wz2)/k; b(1) = 1; b(2) = (2*wp2 - 8*fs*fs)/k; b(3) = (wp2 + 4*fs*fs - 2*wp*fs/pq)/k; g = sum(a) / sum(b); a = a / g; end % </SyntaxDescription> try % <SyntaxCode> pzm1 = pzmodel(1, pz(1+2i), pz(1+5i)); pzm2 = pzmodel(1, [pz(1+2i) pz(2+2i)], [pz(1+5i) pz(2+5i)]); out1 = tomiir(pzm1); out2 = tomiir(pzm2); mout1 = rebuild(out1); mout2 = rebuild(out2); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the output class if ~isa(out1, 'miir'), atest = false; end if ~isa(out2, 'miir'), atest = false; end % Comput the a and b from a complex pole/zero pair [a,b] = utp_cpz2ab(pzm1.poles.f, pzm1.poles.q, pzm1.zeros.f, pzm1.zeros.q, 1); % Compute the cascade of the two different filters (necessary for pzm2): [a1,b1] = utp_cpz2ab(pzm2.poles(1).f, pzm2.poles(1).q, pzm2.zeros(1).f, pzm2.zeros(1).q, 1); [a2,b2] = utp_cpz2ab(pzm2.poles(2).f, pzm2.poles(2).q, pzm2.zeros(2).f, pzm2.zeros(2).q, 1); ca(1) = a1(1)*a2(1); ca(2) = a1(1)*a2(2) + a1(2)*a2(1); ca(3) = a1(1)*a2(3) + a1(2)*a2(2) + a1(3)*a2(1); ca(4) = a1(2)*a2(3) + a1(3)*a2(2); ca(5) = a1(3)*a2(3); cb(1) = b1(1)*b2(1); cb(2) = b1(1)*b2(2) + b1(2)*b2(1); cb(3) = b1(1)*b2(3) + b1(2)*b2(2) + b1(3)*b2(1); cb(4) = b1(2)*b2(3) + b1(3)*b2(2); cb(5) = b1(3)*b2(3); % Check a and b if ~isequal(a, out1.a), atest = false; end if ~isequal(b, out1.b), atest = false; end if ~isequal(ca, out2.a), atest = false; end if ~isequal(cb, out2.b), atest = false; end % Check the rebuilt object if ~eq(out1, mout1, ple2), atest = false; end if ~eq(out2, mout2, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_10 %% UTP_11 % <TestDescription> % % Check indirect the protected 'pzm2ab' method because tomiir uses this % method to get the a and b of the iir object. % % </TestDescription> function result = utp_11 % <SyntaxDescription> % % Create some special pole/zero models to test the 'pzm2ab' method indirect % with the tomiir method. Test with complex poles. % This UTPs define a simple method to get the a-, and b-value from a % complex pole. It uses the following code: function [a,b] = utp_cp2iir(pf, pq, fs) w0 = pf*2*pi; w02 = w0^2; k = (pq*w02 + 4*pq*fs*fs + 2*w0*fs) / (pq*w02); b(1) = 1; b(2) = (2*w02-8*fs*fs) / (k*w02); b(3) = (pq*w02 + 4*pq*fs*fs - 2*w0*fs) / (k*pq*w02); a(1) = 1/k; a(2) = -2/k; a(3) = -1/k; a = a*-2; end % </SyntaxDescription> try % <SyntaxCode> pzm1 = pzmodel(1, pz(1+2i), []); pzm2 = pzmodel(1, [pz(1+2i) pz(2+2i)], []); out1 = tomiir(pzm1); out2 = tomiir(pzm2); mout1 = rebuild(out1); mout2 = rebuild(out2); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the output class if ~isa(out1, 'miir'), atest = false; end if ~isa(out2, 'miir'), atest = false; end % Comput the a and b from a complex pole [a,b] = utp_cp2iir(pzm1.poles.f, pzm1.poles.q, 1); % Compute the cascade of the two different filters (necessary for pzm2): [a1,b1] = utp_cp2iir(pzm2.poles(1).f, pzm2.poles(1).q, 1); [a2,b2] = utp_cp2iir(pzm2.poles(2).f, pzm2.poles(2).q, 1); ca(1) = a1(1)*a2(1); ca(2) = a1(1)*a2(2) + a1(2)*a2(1); ca(3) = a1(1)*a2(3) + a1(2)*a2(2) + a1(3)*a2(1); ca(4) = a1(2)*a2(3) + a1(3)*a2(2); ca(5) = a1(3)*a2(3); cb(1) = b1(1)*b2(1); cb(2) = b1(1)*b2(2) + b1(2)*b2(1); cb(3) = b1(1)*b2(3) + b1(2)*b2(2) + b1(3)*b2(1); cb(4) = b1(2)*b2(3) + b1(3)*b2(2); cb(5) = b1(3)*b2(3); % Check a and b if ~isequal(a, out1.a), atest = false; end if ~isequal(b, out1.b), atest = false; end if ~isequal(ca, out2.a), atest = false; end if ~isequal(cb, out2.b), atest = false; end % Check the rebuilt object if ~eq(out1, mout1, ple2), atest = false; end if ~eq(out2, mout2, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_11 %% UTP_12 % <TestDescription> % % Check indirect the protected 'pzm2ab' method because tomiir uses this % method to get the a and b of the iir object. % % </TestDescription> function result = utp_12 % <SyntaxDescription> % % Create some special pole/zero models to test the 'pzm2ab' method indirect % with the tomiir method. Test with complex zeros. % This UTPs define a simple method to get the a-, and b-value from a % complex zero. It uses the following code: function [a,b] = utp_cz2iir(zf, zq, fs) w0 = zf*2*pi; w02 = w0^2; a(1) = (-zq*w02/2 - 2*zq*fs*fs - w0*fs) / (zq*w02); a(2) = (-w02+4*fs*fs) / w02; a(3) = (-zq*w02/2 - 2*zq*fs*fs + w0*fs) / (zq*w02); b(1) = 1; b(2) = -2; b(3) = -1; end % </SyntaxDescription> try % <SyntaxCode> pzm1 = pzmodel(1, [], pz(1+2i)); pzm2 = pzmodel(1, [], [pz(1+2i) pz(2+2i)]); out1 = tomiir(pzm1); out2 = tomiir(pzm2); mout1 = rebuild(out1); mout2 = rebuild(out2); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the output class if ~isa(out1, 'miir'), atest = false; end if ~isa(out2, 'miir'), atest = false; end % Comput the a and b from a complex zero [a,b] = utp_cz2iir(pzm1.zeros.f, pzm1.zeros.q, 1); % Compute the cascade of the two different filters (necessary for pzm2): [a1,b1] = utp_cz2iir(pzm2.zeros(1).f, pzm2.zeros(1).q, 1); [a2,b2] = utp_cz2iir(pzm2.zeros(2).f, pzm2.zeros(2).q, 1); ca(1) = a1(1)*a2(1); ca(2) = a1(1)*a2(2) + a1(2)*a2(1); ca(3) = a1(1)*a2(3) + a1(2)*a2(2) + a1(3)*a2(1); ca(4) = a1(2)*a2(3) + a1(3)*a2(2); ca(5) = a1(3)*a2(3); cb(1) = b1(1)*b2(1); cb(2) = b1(1)*b2(2) + b1(2)*b2(1); cb(3) = b1(1)*b2(3) + b1(2)*b2(2) + b1(3)*b2(1); cb(4) = b1(2)*b2(3) + b1(3)*b2(2); cb(5) = b1(3)*b2(3); % Check a and b if ~isequal(a, out1.a), atest = false; end if ~isequal(b, out1.b), atest = false; end if ~isequal(ca, out2.a), atest = false; end if ~isequal(cb, out2.b), atest = false; end % Check the rebuilt object if ~eq(out1, mout1, ple2), atest = false; end if ~eq(out2, mout2, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_12 %% UTP_13 % <TestDescription> % % Check indirect the protected 'pzm2ab' method because tomiir uses this % method to get the a and b of the iir object. % % </TestDescription> function result = utp_13 % <SyntaxDescription> % % Create some special pole/zero models to test the 'pzm2ab' method indirect % with the tomiir method. Test with real poles. % This UTPs define a simple method to get the a-, and b-value from a % real pole. It uses the following code: function [a,b] = utp_rp2iir(pf, fs) w0 = pf*2*pi; a(1) = w0 / (2*fs + w0); a(2) = a(1); b(1) = 1; b(2) = (w0-2*fs) / (w0+2*fs); end % </SyntaxDescription> try % <SyntaxCode> pzm1 = pzmodel(1, pz(1), []); pzm2 = pzmodel(1, [pz(1) pz(2)], []); out1 = tomiir(pzm1); out2 = tomiir(pzm2); mout1 = rebuild(out1); mout2 = rebuild(out2); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the output class if ~isa(out1, 'miir'), atest = false; end if ~isa(out2, 'miir'), atest = false; end % Comput the a and b from a real pole [a,b] = utp_rp2iir(pzm1.poles.f, 1); % Compute the cascade of the two different filters (necessary for pzm2): [a1,b1] = utp_rp2iir(pzm2.poles(1).f, 1); [a2,b2] = utp_rp2iir(pzm2.poles(2).f, 1); ca(1) = a1(1)*a2(1); ca(2) = a1(1)*a2(2) + a1(2)*a2(1); ca(3) = a1(2)*a2(2); cb(1) = b1(1)*b2(1); cb(2) = b1(1)*b2(2) + b1(2)*b2(1); cb(3) = b1(2)*b2(2); % Check a and b if ~isequal(a, out1.a), atest = false; end if ~isequal(b, out1.b), atest = false; end if ~isequal(ca, out2.a), atest = false; end if ~isequal(cb, out2.b), atest = false; end % Check the rebuilt object if ~eq(out1, mout1, ple2), atest = false; end if ~eq(out2, mout2, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_13 %% UTP_14 % <TestDescription> % % Check indirect the protected 'pzm2ab' method because tomiir uses this % method to get the a and b of the iir object. % % </TestDescription> function result = utp_14 % <SyntaxDescription> % % Create some special pole/zero models to test the 'pzm2ab' method indirect % with the tomiir method. Test with real zeros. % This UTPs define a simple method to get the a-, and b-value from a % real zero. It uses the following code: function [a,b] = utp_rp2iir(zf, fs) w0 = zf*2*pi; a(1) = (2*fs + w0) / w0; a(2) = (-2*fs + w0) / w0; b(1) = 1; b(2) = 1; end % </SyntaxDescription> try % <SyntaxCode> pzm1 = pzmodel(1, [], pz(1)); pzm2 = pzmodel(1, [], [pz(1) pz(2)]); out1 = tomiir(pzm1); out2 = tomiir(pzm2); mout1 = rebuild(out1); mout2 = rebuild(out2); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the output class if ~isa(out1, 'miir'), atest = false; end if ~isa(out2, 'miir'), atest = false; end % Comput the a and b from a real zero [a,b] = utp_rp2iir(pzm1.zeros.f, 1); % Compute the cascade of the two different filters (necessary for pzm2): [a1,b1] = utp_rp2iir(pzm2.zeros(1).f, 1); [a2,b2] = utp_rp2iir(pzm2.zeros(2).f, 1); ca(1) = a1(1)*a2(1); ca(2) = a1(1)*a2(2) + a1(2)*a2(1); ca(3) = a1(2)*a2(2); cb(1) = b1(1)*b2(1); cb(2) = b1(1)*b2(2) + b1(2)*b2(1); cb(3) = b1(2)*b2(2); % Check a and b if ~isequal(a, out1.a), atest = false; end if ~isequal(b, out1.b), atest = false; end if ~isequal(ca, out2.a), atest = false; end if ~isequal(cb, out2.b), atest = false; end % Check the rebuilt object if ~eq(out1, mout1, ple2), atest = false; end if ~eq(out2, mout2, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_14 end