comparison m-toolbox/test/test_ao_cohere_variance_montecarlo.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_ao_cohere_variance_montecarlo
2 %
3 % Tests that the standard deviation returned by ao.dy in one
4 % frequency bin is equivalent to the matlab's std taking
5 % considering all realisations
6 %
7 % M Nofrarias 22-07-09
8 %
9 % $Id: test_ao_cohere_variance_montecarlo.m,v 1.1 2009/08/11 14:20:10 miquel Exp $
10
11 % function test_ao_cohere_variance_montecarlo()
12
13 clear
14
15 % data
16 nsecs = 200;
17 fs = 10;
18 pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'sin(2*pi*2*t) + randn(size(t))');
19
20
21 % Make a filter
22 f1 = miir(plist('type', 'highpass', 'fc', 4, 'fs', fs));
23
24 % Window
25 Nfft = 100;
26 win = specwin('Hanning', Nfft);
27 pl2 = plist('Nfft',Nfft, 'win',win,'Olap',0)
28
29 % loop
30 for i = 1:100
31 a1 = ao(pl);
32 a2 = filter(a1,plist('filter', f1));
33 c1(i) = cohere(a1,a2,plist('Nfft',100,'type','MS'));
34 % Do with MATLAB
35 [cxy, f] = mscohere(a1.data.y, a2.data.y, win.win, Nfft/2, Nfft, a1.data.fs);
36 c2(i) = ao(fsdata(f, cxy));
37 end
38
39 %% mean
40 index = 6;
41
42 % compare mean
43 mn = [mean(c1(:).y(index)) mean(c2(:).y(index))]
44 % error
45 err = std(c1(:).y(index))
46 % compare standard deviation
47 clear rel
48 for i =1:len(c1(1))
49 mn(i) = [mean(c1(:).y(i))]; % both means are equal
50 rel(:,i) = [std(c1(:).y(i)) mean(c1(:).dy(i))]/abs(mn(i));
51 end
52
53 figure
54 loglog(c1(1).x,rel')
55 figure
56 loglog(c1(1).x(:),100*abs(rel(2,:)-rel(1,:)))
57 ylabel('difference (%)')
58