Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_filtfilt.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % Test script for ao/filter with matrix input | |
2 % | |
3 % L. Ferraioli 02-12-08 | |
4 % | |
5 % $Id: test_ao_filtfilt.m,v 1.3 2011/05/12 13:23:35 luigi Exp $ | |
6 | |
7 %% Test a filter matrix with a single filter object | |
8 | |
9 % get filter | |
10 pl = plist('type', 'lowpass', ... | |
11 'order', 2, ... | |
12 'gain', 1.0, ... | |
13 'fs', 10, ... | |
14 'fc', 0.2); | |
15 | |
16 filt = miir(pl); | |
17 fresp = resp(filt,plist('f',[logspace(-4,0,100)].')); | |
18 | |
19 % put filter into a matrix | |
20 mfilt = matrix(filt); | |
21 | |
22 % gen white noise data | |
23 b = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 1e4)); | |
24 | |
25 % do filtering with matrix | |
26 c = filter(b,mfilt); | |
27 sc = tfe(b,c); | |
28 sc.setName; | |
29 | |
30 % do filtering with matrix inside plist | |
31 d = filtfilt(b,plist('filter',mfilt)); | |
32 sd = tfe(b,d); | |
33 sd.setName; | |
34 | |
35 % test rebuild | |
36 g = rebuild(c); | |
37 sg = tfe(b,g); | |
38 sg.setName; | |
39 | |
40 h = rebuild(d); | |
41 sh = tfe(b,h); | |
42 sh.setName; | |
43 | |
44 % check | |
45 iplot(sc,sd,sg,sh,fresp) | |
46 | |
47 %% Test a filter with a single filterbank object | |
48 | |
49 % get filter and response | |
50 pl = plist('type', 'lowpass', ... | |
51 'order', 2, ... | |
52 'gain', 1.0, ... | |
53 'fs', 10, ... | |
54 'fc', 0.2); | |
55 | |
56 filt = miir(pl); | |
57 fresp = resp(filt,plist('f',[logspace(-4,0,100)].')); | |
58 | |
59 % generate a filterbank with zDomainFit | |
60 pl_fit = plist('FS',10,... | |
61 'AutoSearch','on',... | |
62 'StartPoles',[],... | |
63 'StartPolesOpt','clin',... | |
64 'maxiter',40,... | |
65 'minorder',3,... | |
66 'maxorder',25,... | |
67 'weights',[],... | |
68 'weightparam','abs',... | |
69 'CONDTYPE','MSE',... | |
70 'FITTOL',1e-4,... % check if MSE is lower than 1e-4 | |
71 'MSEVARTOL',1e-2,... | |
72 'Plot','off',... | |
73 'ForceStability','on',... | |
74 'CheckProgress','off'); | |
75 | |
76 % Do fit | |
77 fbk_filt = zDomainFit(fresp, pl_fit); | |
78 | |
79 % gen white noise data | |
80 b = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 1e4)); | |
81 | |
82 % do filtering with filterbank | |
83 c = filtfilt(b,fbk_filt); | |
84 sc = tfe(b,c); | |
85 sc.setName('direct filterbank') | |
86 | |
87 d = filter(b,fbk_filt); | |
88 sd = tfe(b,d); | |
89 sd.setName('direct filter') | |
90 | |
91 % % do filtering with filterbank inside plist | |
92 % d = filtfilt(b,plist('filter',fbk_filt)); | |
93 % sd = tfe(b,d); | |
94 % sd.setName('plist filterbank') | |
95 | |
96 | |
97 % check | |
98 iplot(abs(sc),abs(sd).^2,abs(fresp).^2) | |
99 | |
100 | |
101 %% test filter with 2dim matrix | |
102 | |
103 % test that filter trow an error when a N-dim matrix is input | |
104 pl1 = plist('type', 'lowpass', ... | |
105 'order', 2, ... | |
106 'gain', 1.0, ... | |
107 'fs', 10, ... | |
108 'fc', 0.2); | |
109 | |
110 pl2 = plist('type', 'lowpass', ... | |
111 'order', 1, ... | |
112 'gain', 1e-1, ... | |
113 'fs', 10, ... | |
114 'fc', 0.01); | |
115 | |
116 filt1 = miir(pl1); | |
117 fresp1 = resp(filt1,plist('f',[logspace(-4,0,100)].')); | |
118 filt2 = miir(pl2); | |
119 fresp2 = resp(filt2,plist('f',[logspace(-4,0,100)].')); | |
120 | |
121 mfilt = matrix(filt1,filt2); | |
122 | |
123 % gen white noise data | |
124 b = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 1e4)); | |
125 | |
126 % do filtering with matrix | |
127 try | |
128 c = filter(b,mfilt); | |
129 catch err | |
130 disp(err.message) | |
131 end | |
132 | |
133 try | |
134 c = filter(b,plist('filter',mfilt)); | |
135 catch err | |
136 disp(err.message) | |
137 end | |
138 | |
139 %% test filter with 2dim matrix | |
140 | |
141 % test that filter trow an error when a N-dim matrix is input | |
142 pl1 = plist('type', 'lowpass', ... | |
143 'order', 2, ... | |
144 'gain', 1.0, ... | |
145 'fs', 10, ... | |
146 'fc', 0.2); | |
147 | |
148 pl2 = plist('type', 'lowpass', ... | |
149 'order', 1, ... | |
150 'gain', 1e-1, ... | |
151 'fs', 10, ... | |
152 'fc', 0.01); | |
153 | |
154 filt1 = miir(pl1); | |
155 fresp1 = resp(filt1,plist('f',[logspace(-4,0,100)].')); | |
156 filt2 = miir(pl2); | |
157 fresp2 = resp(filt2,plist('f',[logspace(-4,0,100)].')); | |
158 | |
159 % Fitting parameter list | |
160 pl_fit = plist('FS',10,... | |
161 'AutoSearch','on',... | |
162 'StartPoles',[],... | |
163 'StartPolesOpt','clog',... | |
164 'maxiter',40,... | |
165 'minorder',3,... | |
166 'maxorder',25,... | |
167 'weights',[],... | |
168 'weightparam','abs',... | |
169 'CONDTYPE','MSE',... | |
170 'FITTOL',1e-4,... % check if MSE is lower than 1e-4 | |
171 'MSEVARTOL',1e-2,... | |
172 'Plot','off',... | |
173 'ForceStability','on',... | |
174 'CheckProgress','off'); | |
175 | |
176 % Do fit | |
177 mod = zDomainFit(fresp1,fresp2,pl_fit); | |
178 | |
179 b = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 1e4)); | |
180 | |
181 try | |
182 c = filter(b,mfilt); | |
183 catch err | |
184 disp(err.message) | |
185 end | |
186 | |
187 try | |
188 c = filter(b,plist('filter',mfilt)); | |
189 catch err | |
190 disp(err.message) | |
191 end | |
192 | |
193 |