Mercurial > hg > ltpda
view testing/utp_1.1/utps/mfir/utp_mfir_redesign.m @ 45:a59cdb8aaf31 database-connection-manager
Merge
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 19:07:22 +0100 |
parents | 409a22968d5e |
children |
line wrap: on
line source
% UTP_MFIR_REDESIGN a set of UTPs for the mfir/redesign method % % M Hewitson 06-08-08 % % $Id: utp_mfir_redesign.m,v 1.3 2011/04/17 15:47:28 ingo Exp $ % % <MethodDescription> % % The redesign method of the mfir class redesign the input filter to work for the % given sample rate. % % </MethodDescription> function results = utp_mfir_redesign(varargin) % Check the inputs if nargin == 0 % Some keywords class = 'mfir'; mthd = 'redesign'; results = []; disp('******************************************************'); disp(['**** Running UTPs for ' class '/' mthd]); disp('******************************************************'); % Test MFIR objects [firhp,firlp,firbp,firbr,firpzm,firao,firv,firm] = get_test_objects_mfir; % Exception list for the UTPs: [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); e = ple3.find('EXCEPTIONS'); ple3 = plist('EXCEPTIONS', [e {'iunits', 'ounits'}]); % 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 redesign from a standard type results = [results utp_08]; % Test redesign from a pzmodel type 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 ~= 0, atest = false; end % Check key % Check default value % Check options 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 redesign method works with a vector of MFIR objects as input. % % </TestDescription> function result = utp_02 % <SyntaxDescription> % % Test that the redesign method works for a vector of MFIR objects as input. % To keep this UTP simple use for the vector only one filter object. The % different filters will be tested in an other UTP. % % </SyntaxDescription> try % <SyntaxCode> hp = mfir(firhp); hp.setIunits('Hz'); hp.setOunits('m^-2/3'); firvec = [hp, hp, hp]; out1 = redesign(firvec, 123); out2 = redesign(firvec, plist('fs', 123)); % </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 'firvec' % 2) Check that each output MFIR contains the correct data. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check we have the correct number of outputs if ~isequal(size(out1), size(firvec)), atest = false; end if ~isequal(size(out2), size(firvec)), atest = false; end % Check each output against the redesign of the filter with the % new frequency firhp_123 = mfir(plist('type', 'highpass', 'fs', 123)); for kk=1:numel(firvec) if ~eq(out1(kk), firhp_123, ple3), atest = false; end % The following values must have the same as the input values if ~strcmp(out1(kk).name, hp.name), atest = false; end if ~eq(out1(kk).iunits, hp.iunits), atest = false; end if ~eq(out1(kk).ounits, hp.ounits), atest = false; end end % 'out1' must be the same as 'out2' if ~eq(out1, out2, ple1), 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 redesign method works with a matrix of MFIR objects as input. % % </TestDescription> function result = utp_03 % <SyntaxDescription> % % Test that the redesign method works for a matrix of MFIR objects as input. % To keep this UTP simple use for the matrix only one filter object. The % different filters will be tested in an other UTP. % % </SyntaxDescription> try % <SyntaxCode> hp = mfir(firhp); hp.setIunits('Hz'); hp.setOunits('m^-2/3'); firmat = [hp, hp, hp; hp, hp, hp]; out1 = redesign(firmat, 123); out2 = redesign(firmat, plist('fs', 123)); % </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 'firmat' % 2) Check that each output MFIR contains the correct data. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check we have the correct number of outputs if ~isequal(size(out1), size(firmat)), atest = false; end if ~isequal(size(out2), size(firmat)), atest = false; end % Check each output against the redesign of the filter with the % new frequency firhp_123 = mfir(plist('type', 'highpass', 'fs', 123)); for kk=1:numel(firmat) if ~eq(out1(kk), firhp_123, ple3), atest = false; end % The following values must have the same as the input values if ~strcmp(out1(kk).name, hp.name), atest = false; end if ~eq(out1(kk).iunits, hp.iunits), atest = false; end if ~eq(out1(kk).ounits, hp.ounits), atest = false; end end % 'out1' must be the same as 'out2' if ~eq(out1, out2, ple1), atest = false; 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 redesign method works with a list of MFIR objects as input. % % </TestDescription> function result = utp_04 % <SyntaxDescription> % % Test that the redesign method works for a list of MFIR objects as input. % To keep this UTP simple use for the list only one filter object. The % different filters will be tested in an other UTP. % % </SyntaxDescription> try % <SyntaxCode> hp = mfir(firhp); hp.setIunits('Hz'); hp.setOunits('m^-2/3'); out1 = redesign(hp, hp, hp, 123); out2 = redesign(hp, hp, hp, plist('fs', 123)); % </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 MFIR contains the correct data. % % </AlgoDescription> atest = true; firin = [hp, hp, hp]; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out1) ~= 3, atest = false; end if numel(out2) ~= 3, atest = false; end % Check each output against the redesign of the filter with the % new frequency firhp_123 = mfir(plist('type', 'highpass', 'fs', 123)); for kk=1:numel(firin) if ~eq(out1(kk), firhp_123, ple3), atest = false; end % The following values must have the same as the input values if ~strcmp(out1(kk).name, hp.name), atest = false; end if ~eq(out1(kk).iunits, hp.iunits), atest = false; end if ~eq(out1(kk).ounits, hp.ounits), atest = false; end end % 'out1' must be the same as 'out2' if ~eq(out1, out2, ple1), 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 redesign method works with a mix of different shaped % MFIR objects as input. % % </TestDescription> function result = utp_05 % <SyntaxDescription> % % Test that the redesign method works with an input of matrices and vectors % and single MFIR objects. % To keep this UTP simple use for the vector only one filter object. The % different filters will be tested in an other UTP. % % </SyntaxDescription> try % <SyntaxCode> hp = mfir(firhp); hp.setIunits('Hz'); hp.setOunits('m^-2/3'); out1 = redesign(hp,[hp hp],hp,[hp hp hp; hp hp hp],hp, 123); out2 = redesign(hp,[hp hp],hp,[hp hp hp; hp hp hp],hp, plist('fs', 123)); % </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 MFIR contains the correct data. % % </AlgoDescription> atest = true; firin = [hp hp hp hp hp hp hp hp hp hp hp]; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out1) ~= numel(firin), atest = false; end if numel(out2) ~= numel(firin), atest = false; end % Check each output against the redesign of the filter with the % new frequency firhp_123 = mfir(plist('type', 'highpass', 'fs', 123)); for kk=1:numel(firin) if ~eq(out1(kk), firhp_123, ple3), atest = false; end % The following values must have the same as the input values if ~strcmp(out1(kk).name, hp.name), atest = false; end if ~eq(out1(kk).iunits, hp.iunits), atest = false; end if ~eq(out1(kk).ounits, hp.ounits), atest = false; end end % 'out1' must be the same as 'out2' if ~eq(out1, out2, ple1), 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 redesign method properly applies history. % % </TestDescription> function result = utp_06 % <SyntaxDescription> % % Test that the result of applying the redesign method can be processed back. % % </SyntaxDescription> try % <SyntaxCode> hp = mfir(firhp); hp.setIunits('Hz'); hp.setOunits('m^-2/3'); out = redesign(hp, 123); 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 % 'redesign'. % 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, 'redesign'), 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 redesign method redesigns a standard filter type. % % </TestDescription> function result = utp_07 % <SyntaxDescription> % % Tests that the redesign method redesigns a standard filter type. % % </SyntaxDescription> try % <SyntaxCode> out1 = redesign(firhp, 123); out2 = redesign(firlp, 123); out3 = redesign(firbp, 123); out4 = redesign(firbr, 123); mout1 = rebuild(out1); mout2 = rebuild(out2); mout3 = rebuild(out3); mout4 = rebuild(out4); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check the rebuilt object % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check each output against the redesign of the filter with the new % frequency hp_123 = mfir(plist('type', 'highpass', 'fs', 123)); lp_123 = mfir(plist('type', 'lowpass', 'fs', 123)); bp_123 = mfir(plist('type', 'bandpass', 'fs', 123, 'fc', [0.01 0.1])); br_123 = mfir(plist('type', 'bandreject', 'fs', 123, 'fc', [0.01 0.1])); if ~eq(out1, hp_123, ple3), atest = false; end if ~eq(out2, lp_123, ple3), atest = false; end if ~eq(out3, bp_123, ple3), atest = false; end if ~eq(out4, br_123, ple3), atest = false; end % Run 'test[1..4].m' and check the result if ~eq(mout1, out1, ple2), atest = false; end if ~eq(mout2, out2, ple2), atest = false; end if ~eq(mout3, out3, ple2), atest = false; end if ~eq(mout4, out4, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_07 %% UTP_08 % <TestDescription> % % Tests that the redesign method redesigns a pzmodel filter type. % % </TestDescription> function result = utp_08 % <SyntaxDescription> % % Tests that the redesign method redesigns a pzmodel filter type. % % </SyntaxDescription> try % <SyntaxCode> pzm = pzmodel(1, [pz(1) pz(200)], pz(50)); pzm.setName(); pl = plist('pzmodel', pzm, 'fs', 1000); firpzm = mfir(pl); out = redesign(firpzm, 123); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check the rebuilt object % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check each output against the redesign of the filter with the new % frequency pzm_123 = mfir(plist('pzmodel', pzm, 'fs', 123)); if ~eq(out, pzm_123, ple3), atest = false; end % Check the result of 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 end