?? wtfilter_tcase.m
字號(hào):
function tc = wtfilter_tcase% wtfilter_tcase -- munit test case to test wtfilter.%%****f* wmtsa.Tests.dwt/wtfilter_tcase%% NAME% wtfilter_tcase -- munit test case to test wtfilter.%% USAGE% run_tcase('wtfilter_tcase')%% INPUTS% (none)%% OUTPUTS% tc = tcase structure for wtfilter testcase.%% SIDE EFFECTS%%% DESCRIPTION%%% SEE ALSO% wtfilter% % AUTHOR% Charlie Cornish%% CREATION DATE% 2005-03-01%% COPYRIGHT% (c) Charles R. Cornish 2005%% CREDITS%%% REVISION% $Revision: 612 $%%***% $Id: wtfilter_tcase.m 612 2005-10-28 21:42:24Z ccornish $ tc = MU_tcase_new(mfilename);tc = MU_tcase_add_test(tc, @test_no_arg);tc = MU_tcase_add_test(tc, @test_arg_filter_list);tc = MU_tcase_add_test(tc, @test_arg_all_filters);tc = MU_tcase_add_test(tc, @test_verify_filter_coefs);tc = MU_tcase_add_test(tc, @test_validate_filter_coefs);returnfunction test_no_arg(mode) % Test Description: % Expected error: WMTSA:InvalidNumArguments try wtfilter; catch [errmsg, msg_id] = lasterr; MU_assert_error('MATLAB:nargchk:notEnoughInputs', msg_id); endreturnfunction test_arg_filter_list(mode) % Test Description: % Expected result: filter list wtfnames = wtfilter('list');returnfunction test_arg_all_filters(mode) % Test Description: % Expected error: wtfs = wtfilter('all', 'dwt'); wtfs = wtfilter('all', 'modwt'); try wtfnames = wtfilter('all'); catch [errmsg, msg_id] = lasterr; MU_assert_error('WMTSA:missingRequiredArgument', msg_id); end try wtfnames = wtfilter('all', 'xxx'); catch [errmsg, msg_id] = lasterr; MU_assert_error('WMTSA:invalidArgumentValue', msg_id); endreturnfunction test_verify_filter_coefs(mode) % Test Description: % Verify all implemented filters by: % - Check filter lengths (L) to length of filter coefficients. % - h = qmf(g), g = inverse_qmf(h) % - ht = h / sqrt(2), gt = g / sqrt(2) wtfnames = wtfilter('list'); for (i = 1:length(wtfnames)) wtfname = wtfnames{i}; if (MU_lookup_mode_num_by_name(mode) > 1) disp(['Examining wtfilter ', wtfname, '...']); end wtf_dwt = wtfilter(wtfname, 'dwt'); MU_assert_isequal(wtf_dwt.L, length(wtf_dwt.g)); MU_assert_isequal(wtf_dwt.L, length(wtf_dwt.h)); MU_assert_isequal(length(wtf_dwt.g), length(wtf_dwt.h)); MU_assert_isequal(wtf_dwt.g, wmtsa_qmf(wtf_dwt.h, 1)); MU_assert_isequal(wtf_dwt.h, wmtsa_qmf(wtf_dwt.g)); wtf_modwt = wtfilter(wtfname, 'modwt'); MU_assert_isequal(wtf_dwt.h ./ sqrt(2), wtf_modwt.h); MU_assert_isequal(wtf_dwt.g ./ sqrt(2), wtf_modwt.g); end returnfunction test_validate_filter_coefs(mode) % Test Description: % Validate DWT filters coefficients against numerical values: % - Check filter lengths (L) to length of filter coefficients. % - h and g's are equal wtfnames = wtfilter('list'); for (i = 1:length(wtfnames)) wtfname = wtfnames{i}; if (MU_lookup_mode_num_by_name(mode) > 1) disp(['Examining wtfilter ', wtfname, '...']); end wtf_dwt = wtfilter(wtfname, 'dwt'); [h, g, L] = get_dwt_filter_coefs(wtfname); MU_assert_isequal(wtf_dwt.L, L); MU_assert_isequal(wtf_dwt.g, g); MU_assert_isequal(wtf_dwt.h, h); end returnfunction [h, g, L] = get_dwt_filter_coefs(wtfname) % Lookup DWT filter coefficients (values from WMTSA website) switch lower(wtfname) % % Extremal phase filters % case 'haar' L = 2; g = [0.7071067811865475 0.7071067811865475]; h = [0.7071067811865475 -0.7071067811865475]; case 'd4' L = 4; g = [0.4829629131445341 0.8365163037378077 0.2241438680420134 ... -0.1294095225512603]; h = [-0.1294095225512603 -0.2241438680420134 0.8365163037378077 ... -0.4829629131445341]; case 'd6' L = 6; g = [0.3326705529500827 0.8068915093110928 0.4598775021184915 ... -0.1350110200102546 -0.0854412738820267 0.0352262918857096]; h = [0.0352262918857096 0.0854412738820267 -0.1350110200102546 ... -0.4598775021184915 0.8068915093110928 -0.3326705529500827]; case 'd8' L = 8; g = [0.2303778133074431 0.7148465705484058 0.6308807679358788 ... -0.0279837694166834 -0.1870348117179132 0.0308413818353661 ... 0.0328830116666778 -0.0105974017850021]; h = [-0.0105974017850021 -0.0328830116666778 0.0308413818353661 ... 0.1870348117179132 -0.0279837694166834 -0.6308807679358788 ... 0.7148465705484058 -0.2303778133074431]; case 'd10' L = 10; g = [0.1601023979741930 0.6038292697971898 0.7243085284377729 ... 0.1384281459013204 -0.2422948870663824 -0.0322448695846381 ... 0.0775714938400459 -0.0062414902127983 -0.0125807519990820 ... 0.0033357252854738]; h = [0.0033357252854738 0.0125807519990820 -0.0062414902127983 ... -0.0775714938400459 -0.0322448695846381 0.2422948870663824 ... 0.1384281459013204 -0.7243085284377729 0.6038292697971898 ... -0.1601023979741930]; case 'd12' L = 12; g = [0.1115407433501094 0.4946238903984530 0.7511339080210954 ... 0.3152503517091980 -0.2262646939654399 -0.1297668675672624 ... 0.0975016055873224 0.0275228655303053 -0.0315820393174862 ... 0.0005538422011614 0.0047772575109455 -0.0010773010853085]; h = [-0.0010773010853085 -0.0047772575109455 0.0005538422011614 ... 0.0315820393174862 0.0275228655303053 -0.0975016055873224 ... -0.1297668675672624 0.2262646939654399 0.3152503517091980 ... -0.7511339080210954 0.4946238903984530 -0.1115407433501094]; case 'd14' L = 14; g = [0.0778520540850081 0.3965393194819136 0.7291320908462368 ... 0.4697822874052154 -0.1439060039285293 -0.2240361849938538 ... 0.0713092192668312 0.0806126091510820 -0.0380299369350125 ... -0.0165745416306664 0.0125509985560993 0.0004295779729214 ... -0.0018016407040474 0.0003537137999745]; h = [0.0003537137999745 0.0018016407040474 0.0004295779729214 ... -0.0125509985560993 -0.0165745416306664 0.0380299369350125 ... 0.0806126091510820 -0.0713092192668312 -0.2240361849938538 ... 0.1439060039285293 0.4697822874052154 -0.7291320908462368 ... 0.3965393194819136 -0.0778520540850081]; case 'd16' L = 16; g = [0.0544158422431049 0.3128715909143031 0.6756307362972904 ... 0.5853546836541907 -0.0158291052563816 -0.2840155429615702 ... 0.0004724845739124 0.1287474266204837 -0.0173693010018083 ... -0.0440882539307952 0.0139810279173995 0.0087460940474061 ... -0.0048703529934518 -0.0003917403733770 0.0006754494064506 ... -0.0001174767841248]; h = [-0.0001174767841248 -0.0006754494064506 -0.0003917403733770 ... 0.0048703529934518 0.0087460940474061 -0.0139810279173995 ... -0.0440882539307952 0.0173693010018083 0.1287474266204837 ... -0.0004724845739124 -0.2840155429615702 0.0158291052563816 ... 0.5853546836541907 -0.6756307362972904 0.3128715909143031 ... -0.0544158422431049]; case 'd18' L = 18; g = [0.0380779473638791 0.2438346746125939 0.6048231236901156 ... 0.6572880780512955 0.1331973858249927 -0.2932737832791761 ... -0.0968407832229524 0.1485407493381306 0.0307256814793395 ... -0.0676328290613302 0.0002509471148340 0.0223616621236805 ...
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -