Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_confint.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/confint | |
2 % | |
3 % L Ferraioli 20-03-09 | |
4 % | |
5 % $Id: test_ao_confint.m,v 1.4 2011/04/29 14:03:08 luigi Exp $ | |
6 | |
7 %% params | |
8 | |
9 fs = 1; % Hz | |
10 | |
11 %% Set the model | |
12 | |
13 d = [1 -1.1 0.5]; | |
14 h11 = miir([1 -0.5],d,fs); | |
15 h12 = miir([0 -0.5],d,fs); | |
16 h21 = miir([0 0.4],d,fs); | |
17 h22 = miir([1 -0.6],d,fs); | |
18 | |
19 %% Theoretical sectra | |
20 | |
21 f = logspace(-5,log10(0.5),300); | |
22 f = f.'; | |
23 | |
24 plresp = plist('f',f); | |
25 | |
26 rh11 = resp(h11,plresp); | |
27 rh12 = resp(h12,plresp); | |
28 rh21 = resp(h21,plresp); | |
29 rh22 = resp(h22,plresp); | |
30 | |
31 % psd11 | |
32 G11 = rh11.y.*conj(rh11.y) + rh12.y.*conj(rh12.y); | |
33 G11 = ao(plist('xvals', f, 'yvals', G11, 'fs', fs, 'type', 'fsdata', 'yunits', unit('m^2').*unit('Hz^-1'))); | |
34 G11.setName; | |
35 | |
36 % psd 22 | |
37 G22 = rh21.y.*conj(rh21.y) + rh22.y.*conj(rh22.y); | |
38 G22 = ao(plist('xvals', f, 'yvals', G22, 'fs', fs, 'type', 'fsdata', 'yunits', unit('m^2').*unit('Hz^-1'))); | |
39 G22.setName; | |
40 | |
41 % cpsd | |
42 G12 = conj(rh11.y).*rh21.y + conj(rh12.y).*rh22.y; | |
43 G12 = ao(plist('xvals', f, 'yvals', G12, 'fs', fs, 'type', 'fsdata', 'yunits', unit('m^2').*unit('Hz^-1'))); | |
44 G12.setName; | |
45 | |
46 % mscohere | |
47 sK12 = (G12.y.*conj(G12.y))./(G11.y.*G22.y); | |
48 sK12 = ao(plist('xvals', f, 'yvals', sK12, 'fs', fs, 'type', 'fsdata')); | |
49 sK12.setName; | |
50 | |
51 %% Noise generation | |
52 | |
53 w1 = ao(plist('tsfcn','randn(size(t))','fs',1,'nsecs',1e5,'yunits','m')); | |
54 w2 = ao(plist('tsfcn','randn(size(t))','fs',1,'nsecs',1e5,'yunits','m')); | |
55 | |
56 x11 = filter(w1,h11); | |
57 x12 = filter(w2,h12); | |
58 x21 = filter(w1,h21); | |
59 x22 = filter(w2,h22); | |
60 | |
61 x1 = x11 + x12; | |
62 x2 = x21 + x22; | |
63 | |
64 %% mslcohere | |
65 | |
66 sk12log = lcohere(x1,x2,plist('type','MS')); | |
67 if numel(sk12log)>1 | |
68 sk12log = sk12log(1,2); | |
69 end | |
70 | |
71 % iplot(sK12,sk12log,plist('Yscales',{'All','linear'})) | |
72 | |
73 out = confint(sk12log,plist('method','mslcohere')); | |
74 lc = out.getObjectAtIndex(1); | |
75 uc = out.getObjectAtIndex(2); | |
76 var = out.getObjectAtIndex(3); | |
77 | |
78 iplot(sK12,sk12log,lc,uc,plist('Yscales',{'All','linear'})) | |
79 | |
80 dof = getdof(sk12log,plist('method','mslcohere')); | |
81 | |
82 %% shaded plot | |
83 | |
84 x = lc.data.x; | |
85 y1 = lc.data.y; | |
86 y2 = uc.data.y; | |
87 mod = sK12; | |
88 | |
89 figure | |
90 y = [y1 (y2-y1)]; % y1 and y2 are columns | |
91 ha = area(x, y); | |
92 set(ha(1), 'FaceColor', 'none') % this makes the bottom area invisible | |
93 set(ha(2), 'FaceColor', 'r') | |
94 set(ha, 'LineStyle', 'none') | |
95 grid on | |
96 | |
97 % plot the line edges | |
98 hold on | |
99 hb = plot(x, y1, 'LineWidth', 1, 'Color', 'r'); | |
100 hc = plot(x, y2, 'LineWidth', 1, 'Color', 'r'); | |
101 hd = plot(mod.data.x, mod.data.y); | |
102 hf = plot(sk12log.data.x,sk12log.data.y,'Color', 'g'); | |
103 | |
104 set(gca,'xscale','log','yscale','lin'); | |
105 % set(gca,'Layer','top') | |
106 ylabel('Magnitude Squared Coherence'); | |
107 xlabel('Frequency [Hz]'); | |
108 legend([hd hf ha(2)],{'Model MSC','Sample MSC','95% Conf. level'}); | |
109 | |
110 %% lpsd | |
111 | |
112 g11lpsd = lpsd(x1); | |
113 | |
114 % iplot(2.*G11,g11lpsd) | |
115 | |
116 outlpsd = confint(g11lpsd,plist('method','lpsd')); | |
117 lclpsd = outlpsd.getObjectAtIndex(1); | |
118 uclpsd = outlpsd.getObjectAtIndex(2); | |
119 varlpsd = outlpsd.getObjectAtIndex(3); | |
120 | |
121 iplot(2.*G11,g11lpsd,lclpsd,uclpsd) | |
122 | |
123 doflpsd = getdof(g11lpsd,plist('method','lpsd')); | |
124 | |
125 %% shaded plot | |
126 | |
127 x = lclpsd.data.x; | |
128 y1 = lclpsd.data.y; | |
129 y2 = uclpsd.data.y; | |
130 mod = 2.*G11; | |
131 | |
132 figure | |
133 y = [y1 (y2-y1)]; % y1 and y2 are columns | |
134 ha = area(x, y); | |
135 set(ha(1), 'FaceColor', 'none') % this makes the bottom area invisible | |
136 set(ha(2), 'FaceColor', 'r') | |
137 set(ha, 'LineStyle', 'none') | |
138 grid on | |
139 | |
140 % plot the line edges | |
141 hold on | |
142 hb = plot(x, y1, 'LineWidth', 1, 'Color', 'r'); | |
143 hc = plot(x, y2, 'LineWidth', 1, 'Color', 'r'); | |
144 hd = plot(mod.data.x, mod.data.y); | |
145 hf = plot(g11lpsd.data.x,g11lpsd.data.y,'Color', 'g'); | |
146 | |
147 set(gca,'xscale','log','yscale','log'); | |
148 % set(gca,'Layer','top') | |
149 ylabel('Power Spectral Density [m^{2} / Hz]'); | |
150 xlabel('Frequency [Hz]'); | |
151 legend([hd hf ha(2)],{'Model Spectrum','Sample Spectrum','95% Conf. level'}); | |
152 | |
153 %% mscohere | |
154 | |
155 sk12lin = cohere(x1,x2,plist('Nfft',1e3,'type','MS')); | |
156 if numel(sk12lin)>1 | |
157 sk12lin = sk12lin(1,2); | |
158 end | |
159 | |
160 iplot(sK12,sk12lin,plist('Yscales',{'All','linear'})) | |
161 | |
162 outlin = confint(sk12lin,plist('method','mscohere')); | |
163 lclin = outlin.getObjectAtIndex(1); | |
164 uclin = outlin.getObjectAtIndex(2); | |
165 varlin = outlin.getObjectAtIndex(3); | |
166 | |
167 iplot(sK12,sk12lin,lclin,uclin,plist('Yscales',{'All','linear'})) | |
168 | |
169 doflin = getdof(sk12lin,plist('method','mscohere')); | |
170 | |
171 %% shaded plot | |
172 | |
173 x = lclin.data.x; | |
174 y1 = lclin.data.y; | |
175 y2 = uclin.data.y; | |
176 mod = sK12; | |
177 | |
178 figure | |
179 y = [y1 (y2-y1)]; % y1 and y2 are columns | |
180 ha = area(x, y); | |
181 set(ha(1), 'FaceColor', 'none') % this makes the bottom area invisible | |
182 set(ha(2), 'FaceColor', 'r') | |
183 set(ha, 'LineStyle', 'none') | |
184 grid on | |
185 | |
186 % plot the line edges | |
187 hold on | |
188 hb = plot(x, y1, 'LineWidth', 1, 'Color', 'r'); | |
189 hc = plot(x, y2, 'LineWidth', 1, 'Color', 'r'); | |
190 hd = plot(mod.data.x, mod.data.y); | |
191 hf = plot(sk12lin.data.x,sk12lin.data.y,'Color', 'g'); | |
192 | |
193 set(gca,'xscale','log','yscale','lin'); | |
194 % set(gca,'Layer','top') | |
195 ylabel('Magnitude Squared Coherence'); | |
196 xlabel('Frequency [Hz]'); | |
197 legend([hd hf ha(2)],{'Model MSC','Sample MSC','95% Conf. level'}); | |
198 | |
199 %% psd | |
200 | |
201 g11psd = psd(x1,plist('Nfft',1e4)); | |
202 | |
203 iplot(2.*G11,g11psd) | |
204 | |
205 outpsd = confint(g11psd,plist('method','psd')); | |
206 lcpsd = outpsd.getObjectAtIndex(1); | |
207 ucpsd = outpsd.getObjectAtIndex(2); | |
208 varpsd = outpsd.getObjectAtIndex(3); | |
209 | |
210 iplot(2.*G11,g11psd,lcpsd,ucpsd) | |
211 | |
212 dofpsd = getdof(g11psd,plist('method','psd')); | |
213 | |
214 %% shaded plot | |
215 | |
216 x = lcpsd.data.x; | |
217 y1 = lcpsd.data.y; | |
218 y2 = ucpsd.data.y; | |
219 mod = 2.*G11; | |
220 | |
221 figure | |
222 y = [y1 (y2-y1)]; % y1 and y2 are columns | |
223 ha = area(x, y); | |
224 set(ha(1), 'FaceColor', 'none') % this makes the bottom area invisible | |
225 set(ha(2), 'FaceColor', 'r') | |
226 set(ha, 'LineStyle', 'none') | |
227 grid on | |
228 | |
229 % plot the line edges | |
230 hold on | |
231 hb = plot(x, y1, 'LineWidth', 1, 'Color', 'r'); | |
232 hc = plot(x, y2, 'LineWidth', 1, 'Color', 'r'); | |
233 hd = plot(mod.data.x, mod.data.y); | |
234 hf = plot(g11psd.data.x,g11psd.data.y,'Color', 'g'); | |
235 | |
236 set(gca,'xscale','log','yscale','log'); | |
237 % set(gca,'Layer','top') | |
238 ylabel('Power Spectral Density [m^{2} / Hz]'); | |
239 xlabel('Frequency [Hz]'); | |
240 legend([hd hf ha(2)],{'Model Spectrum','Sample Spectrum','95% Conf. level'}); | |
241 | |
242 %% Shaded plot 2 | |
243 | |
244 x = [lcpsd.data.x; flipud(lcpsd.data.x)]; | |
245 y = [ucpsd.data.y; flipud(lcpsd.data.y)]; | |
246 mod = 2.*G11; | |
247 | |
248 figure | |
249 ha = fill(x,y,'r'); | |
250 set(ha,'EdgeColor','r'); | |
251 | |
252 grid on | |
253 hold on | |
254 | |
255 hd = plot(mod.data.x, mod.data.y); | |
256 hf = plot(g11psd.data.x,g11psd.data.y,'Color','g'); | |
257 | |
258 set(gca,'xscale','log','yscale','log'); | |
259 % set(gca,'Layer','top') | |
260 ylabel('Power Spectral Density [m^{2} / Hz]'); | |
261 xlabel('Frequency [Hz]'); | |
262 legend([hd hf ha],{'Model Spectrum','Sample Spectrum','95% Conf. level'}); | |
263 | |
264 %% Test it is working also with processed data | |
265 | |
266 g11psd = psd(x1,plist('Nfft',1e4)); | |
267 | |
268 g11psd.setName('psd'); | |
269 | |
270 plsp = plist('samples',[5 numel(g11psd.x)]); | |
271 g11psds = split(g11psd,plsp); | |
272 | |
273 outpsd = confint(g11psds,plist('method','psd')); | |
274 lcpsd = outpsd.getObjectAtIndex(1); | |
275 ucpsd = outpsd.getObjectAtIndex(2); | |
276 varpsd = outpsd.getObjectAtIndex(3); | |
277 | |
278 iplot(2.*G11,g11psds,lcpsd,ucpsd) | |
279 | |
280 dofpsd = getdof(g11psd,plist('method','psd')); | |
281 |