Mercurial > hg > ltpda
comparison m-toolbox/test/test_iir_serial_parallel.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 mc | |
2 | |
3 | |
4 %% Make test AOs | |
5 | |
6 nsecs = 10000; | |
7 fs = 10; | |
8 | |
9 pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'sin(2*pi*7.433*t) + randn(size(t))'); | |
10 | |
11 a1 = ao(pl); | |
12 a1.setName('a1'); | |
13 | |
14 %% Make two filters | |
15 | |
16 lp = miir(plist('type', 'lowpass', 'fs', fs, 'fc', 0.1, 'order', 5)); | |
17 hp = miir(plist('type', 'highpass', 'fs', fs, 'fc', 1, 'order', 2)); | |
18 | |
19 %% Serial | |
20 | |
21 a1lp = filter(a1, lp); | |
22 a1lphp = filter(a1lp, hp); | |
23 | |
24 a1f = filter(a1, [lp hp], plist('bank', 'serial')); | |
25 | |
26 iplot(a1lphp.psd, a1f.psd, plist('LineStyles', {'', '--'})) | |
27 | |
28 %% Parallel | |
29 | |
30 a1lp = filter(a1, lp); | |
31 a1lphp = a1lp + filter(a1, hp); | |
32 | |
33 a1f = filter(a1, [lp hp]); | |
34 | |
35 iplot(a1lphp.psd, a1f.psd, plist('LineStyles', {'', '--'})) | |
36 | |
37 %% Test filter history serial | |
38 | |
39 nsecs = 100; | |
40 fs = 10; | |
41 | |
42 pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'sin(2*pi*0.433*t)'); | |
43 | |
44 a1 = ao(pl); | |
45 a1.setName('a1'); | |
46 | |
47 segs = split(a1, plist('split_type', 'chunks', 'n', 2)); | |
48 | |
49 filts = [lp hp]; | |
50 | |
51 % full | |
52 [a1lps, filts] = filter(a1, filts, plist('bank', 'serial')); | |
53 | |
54 % segement 1 | |
55 [a1lps1, filts] = filter(segs(1), filts, plist('bank', 'serial')); | |
56 | |
57 % segement 2 | |
58 a1lps2 = filter(segs(2), filts, plist('bank', 'serial')); | |
59 | |
60 iplot(a1lps1, a1lps2, a1lps, plist('Xranges', [49 51], 'markers', {'o', 'o', ''})) | |
61 | |
62 %% Test filter history parallel | |
63 | |
64 nsecs = 100; | |
65 fs = 10; | |
66 | |
67 pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'sin(2*pi*0.433*t)'); | |
68 | |
69 a1 = ao(pl); | |
70 a1.setName('a1'); | |
71 | |
72 segs = split(a1, plist('split_type', 'chunks', 'n', 2)); | |
73 | |
74 filts = [lp hp]; | |
75 | |
76 % full | |
77 [a1lps, filts] = filter(a1, filts); | |
78 | |
79 % segement 1 | |
80 [a1lps1, filts] = filter(segs(1), filts); | |
81 | |
82 % segement 2 | |
83 a1lps2 = filter(segs(2), filts); | |
84 | |
85 iplot(a1lps1, a1lps2, a1lps, plist('Xranges', [49 51], 'markers', {'o', 'o', ''})) | |
86 | |
87 %% Test Serial with different units | |
88 | |
89 a1.setYunits('m'); | |
90 | |
91 % This should output N | |
92 iunits1 = unit('m'); | |
93 ounits1 = unit('V'); | |
94 iunits2 = unit('V'); | |
95 ounits2 = unit('N'); | |
96 | |
97 lp = miir(plist('type', 'lowpass', 'fs', fs, 'fc', 0.1, 'order', 5,'iunits', iunits1, 'ounits', ounits1)); | |
98 hp = miir(plist('type', 'highpass', 'fs', fs, 'fc', 1, 'order', 2,'iunits', iunits2, 'ounits', ounits2)); | |
99 | |
100 a1f = filter(a1, [lp hp], plist('bank', 'serial')); | |
101 | |
102 %% Test Parallel with different units | |
103 | |
104 % This must not to be allowed | |
105 iunits1 = unit('m'); | |
106 ounits1 = unit('V'); | |
107 iunits2 = unit('m'); | |
108 ounits2 = unit('V'); | |
109 | |
110 lp = miir(plist('type', 'lowpass', 'fs', fs, 'fc', 0.1, 'order', 5,'iunits', iunits1, 'ounits', ounits1)); | |
111 hp = miir(plist('type', 'highpass', 'fs', fs, 'fc', 1, 'order', 2,'iunits', iunits2, 'ounits', ounits2)); | |
112 | |
113 a1f = filter(a1, [lp hp], plist('bank', 'parallel')); | |
114 | |
115 |