Mercurial > hg > ltpda
diff m-toolbox/test/test_ao_cpsd.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/test/test_ao_cpsd.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,54 @@ +% Test ao/cpsd functionality. +% +% M Hewitson 08-05-08 +% +% $Id: test_ao_cpsd.m,v 1.6 2009/03/26 09:04:05 miquel Exp $ +% + function test_ao_cpsd() + + % Make test AOs + + nsecs = 10; + fs = 1000; + + pl = plist(); + pl.append('nsecs', nsecs); + pl.append('fs', fs); + pl.append('tsfcn', 'sin(2*pi*7.433*t) + randn(size(t))'); + + a1 = ao(pl); + a2 = ao(pl); + + % Filter one time-series + + % Make a filter + pl = plist('type', 'bandpass', 'fs', 1000, 'order', 3, 'fc', [50 250]); + f2 = miir(pl); + + % filter the input data + [a3, f2] = filter(a1,plist('filter', f2)); + + % make some cross-power + a4 = 10.*a3+a2; + + % Make CPSD from a6 to a7 + Nfft = 1000; + win = specwin('Hanning', Nfft); + pl = plist('Nfft', Nfft, 'Win', win, 'order', 2); + a8 = cpsd(a1, a4, pl); + + % Use matlab + [pxy, f] = cpsd(a1.data.y, a4.data.y, win.win, Nfft/2, Nfft, a1.data.fs); + a9 = ao(fsdata(f.', pxy.')); + + % Plot + iplot(a8, a9, plist('LineStyles', {'', '--'})) + iplot(a8 ./ a9) + + % Test cpsd(a1,a1) = psd(a1) + a10 = cpsd(a1, a1, pl); + a11 = psd(a1, pl); + + iplot(a10,a11) + + end