comparison m-toolbox/test/test_ao_fftfilt.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/fftfilt
2 %
3 % L Ferraioli 09-10-08
4 %
5 % $Id: test_ao_cov.m,v 1.2 2008/12/11 08:25:15 hewitson Exp $
6 %
7
8 s = ao(plist('tsfcn', '3.*sin(2.*pi.*0.01.*t) + randn(size(t))', 'fs', 10, 'nsecs', 1e4));
9
10 %% Test with a miir filter
11
12 % get a miir filter
13 plf = plist('type','lowpass',...
14 'order',4,...
15 'fs',10,...
16 'fc',1);
17 filt = miir(plf);
18
19 % do classical fitering
20 fs1 = filter(s,filt);
21 iplot(s,fs1)
22
23 % do fftfilt
24 fs2 = fftfilt(s,filt);
25
26 % compare results
27 iplot(fs1,fs2)
28 iplot(fs1./fs2)
29 iplot(fs1-fs2)
30
31 %% Test with a miir filter
32
33 % get a miir filter
34 plf = plist('type','lowpass',...
35 'order',4,...
36 'fs',10,...
37 'fc',1);
38 filt = miir(plf);
39
40 % do classical fitering
41 fs1 = filter(s,filt);
42 iplot(s,fs1)
43
44 % do fftfilt
45 plfft = plist('Npad',5.*length(s.data.y));
46 fs2 = fftfilt(s,filt);
47
48 % compare results
49 iplot(fs1,fs2)
50 iplot(fs1./fs2)
51 iplot(fs1-fs2)
52
53 %%
54
55 % imp = zeros(10000,1);
56 % imp(1) = 1;
57 %
58 % imp_resp = filter(num,den,imp);
59 %
60 %
61 % fs1 = filter(num,den,s.y);
62 % fs2 = conv(s.y,imp_resp);
63 % X = fft([s.y;zeros(length(imp_resp)-1,1)]);
64 % Y = fft([imp_resp;zeros(length(s.y)-1,1)]);
65 % fs3 = ifft(X.*Y);
66
67 %% Test pzmodel fftfilt
68
69 poles = [pz(1e-3,2) pz(1e-2)];
70 zeros = [pz(3e-3,3) pz(5e-2)];
71 pzm = pzmodel(10, poles, zeros);
72
73 % do fftfilt
74 plfft = plist('Npad',5.*length(s.data.y));
75 fs = fftfilt(s,pzm);
76
77 tf = tfe(s,fs,plist('navs',2));
78 rsp = resp(pzm,plist('f',logspace(-4,log10(5))));
79 iplot(tf,rsp)
80
81 %% Test smodel
82
83 str = 'a.*(2.*i.*pi.*f).^2 + b.*2.*i.*pi.*f + c';
84 mod = smodel(str);
85 mod.setParams({'a','b','c'},{1,2,3});
86 mod.setXvar('f');
87
88 freq = logspace(-5,log10(5),100);
89 mod.setXvals(freq);
90 mod.setXunits('Hz');
91 mod.setYunits('kg m s^-2');
92
93 % eval smodel
94 em = eval(mod,plist('output x',freq,'type','fsdata'));
95
96 % make a time series
97 dt = ao.randn(10000,10);
98
99 % do fftfilt
100 sdt = fftfilt(dt,mod);
101
102 % test output
103 tdt = tfe(dt,sdt);
104 iplot(em,tdt)
105
106 %% Test initial conditions
107
108 str = 'a.*(2.*i.*pi.*f).^2 + b.*2.*i.*pi.*f + c';
109 mod = smodel(str);
110 mod.setParams({'a','b','c'},{1,2,3});
111 mod.setXvar('f');
112
113 freq = logspace(-5,log10(5),100);
114 mod.setXvals(freq);
115 mod.setXunits('Hz');
116 mod.setYunits('kg m s^-2');
117
118 % eval smodel
119 em = eval(mod,plist('output x',freq,'type','fsdata'));
120
121 % make a time series
122 dt = ao.randn(10000,10);
123
124 % do fftfilt
125 sdt = fftfilt(dt,mod);
126
127 % do fftfilt with initial conditions assuming a 2nd order equation
128 sdt_inCond = fftfilt(dt,mod,plist('initial conditions',[2000,1000]));
129
130 % test output
131 iplot(sdt_inCond,sdt)
132 iplot(sdt_inCond-sdt,plist('yscales',{'all','log'}))
133
134
135
136
137
138
139