comparison m-toolbox/test/test_ao_lscov.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_LSCOV tests the lscov method of the AO class.
2 %
3 % M Hueller 19-03-10
4 %
5 % $Id: test_ao_lscov.m,v 1.7 2010/03/19 11:25:36 mauro Exp $
6 %
7 % function test_ao_lscov()
8
9 %% 1) Determine the coefficients of a linear combination of noises:
10 %
11 % Make some data
12 fs = 10;
13 nsecs = 10;
14 B1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
15 B2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
16 B3 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
17 n = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
18 c = [ao(1,plist('yunits','m/T')) ao(2,plist('yunits','m/T')) ao(3,plist('yunits','m T^-1'))];
19 y = c(1)*B1 + c(2)*B2 + c(3)*B3 + n;
20 y.simplifyYunits;
21 % Get a fit for c
22 p_s = lscov(B1, B2, B3, y);
23 % do linear combination: using lincom
24 yfit1 = lincom(B1, B2, B3, p_s);
25 yfit1.simplifyYunits;
26 % do linear combination: using eval
27 yfit2 = p_s.eval(B1, B2, B3);
28
29 % Plot (compare data with fit)
30 iplot(y, yfit1, yfit2, plist('Linestyles', {'-','--'}))
31
32 %% 2) Determine the coefficients of a linear combination of noises:
33 %
34 % Make some data
35 fs = 10;
36 nsecs = 10;
37 x1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
38 x2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
39 x3 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'C'));
40 n = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
41 c = [ao(1,plist('yunits','m/T')) ao(2,plist('yunits','m/m')) ao(3,plist('yunits','m C^-1'))];
42 y = c(1)*x1 + c(2)*x2 + c(3)*x3 + n;
43 y.simplifyYunits;
44 % Get a fit for c
45 p_m = lscov(x1, x2, x3, y);
46 % do linear combination: using lincom
47 yfit1 = lincom(x1, x2, x3, p_m);
48 % do linear combination: using eval
49 pl_split = plist('times', [1 5]);
50 yfit2 = p_m.eval(plist('Xdata', {split(x1, pl_split), split(x2, pl_split), split(x3, pl_split)}));
51 % Plot (compare data with fit)
52 iplot(y, yfit1, yfit2, plist('Linestyles', {'-','--'}))