comparison m-toolbox/test/test_matrix_linlsqsvd.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_MATRIX_LINLSQSVD tests the linlsqsvd method of the AO class.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % L Ferraioli 10-11-2010
4 %
5 % $Id: test_matrix_linlsqsvd.m,v 1.1 2011/02/18 17:07:35 luigi Exp $
6 %
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8
9 %% 1) Determine the coefficients of a linear combination of noises and
10 %% comapre with lscov:
11 %
12 % Make some data
13 fs = 10;
14 nsecs = 10;
15 B1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
16 B1.setName;
17 B2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
18 B2.setName;
19 B3 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
20 B3.setName;
21 B4 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
22 B4.setName;
23
24 C1 = matrix(B1,B2,plist('shape',[2,1]));
25 C1.setName;
26 C2 = matrix(B3,B4,plist('shape',[2,1]));
27 C2.setName;
28
29 C = matrix([B1 B3;B2 B4]);
30 C.setName;
31
32 n1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
33 n2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
34
35 n = matrix(n1,n2,plist('shape',[2,1]));
36 n.setName;
37
38 a = [ao(1,plist('yunits','m/T')) ao(2,plist('yunits','m/T'))];
39 A = matrix(a,plist('shape',[2,1]));
40
41 % assign output values
42 y = C*A + n;
43
44 %%% Get a fit with linlsqsvd
45 pobj1 = linlsqsvd(C1, C2, y);
46
47 % combine results
48 for ii=1:numel(pobj1.y)
49 prs(ii) = ao(cdata(pobj1.y(ii)));
50 prs(ii).setYunits(pobj1.yunits(ii));
51 end
52 Pars = matrix(prs,plist('shape',[numel(prs),1]));
53 yfit1 = C*Pars;
54
55 %%% do linear combination: using eval
56 yfit2 = pobj1.eval;
57
58 % Plot (compare data with fit)
59 iplot(y.objs(1), yfit1.objs(1), yfit2.objs(1))
60 iplot(y.objs(2), yfit1.objs(2), yfit2.objs(2))
61
62 %% 2) Determine the coefficients of a linear combination of noises:
63 %
64 % Make some data
65 fs = 10;
66 nsecs = 10;
67 x1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
68 x1.setName;
69 x2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
70 x2.setName;
71 x3 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'T'));
72 x3.setName;
73 x4 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
74 x4.setName;
75
76 C1 = matrix(x1,x3,plist('shape',[2,1]));
77 C1.setName;
78 C2 = matrix(x2,x4,plist('shape',[2,1]));
79 C2.setName;
80
81 C = matrix([x1 x2;x3 x4]);
82 C.setName;
83
84 n1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
85 n2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', nsecs, 'yunits', 'm'));
86 n = matrix(n1,n2,plist('shape',[2,1]));
87 n.setName;
88
89 a = [ao(1,plist('yunits','m/T')) ao(2,plist('yunits','m/m'))];
90 A = matrix(a,plist('shape',[2,1]));
91 A.setName;
92
93 y = C*A + n;
94
95 %%% Get a fit with linlsqsvd
96 pobj1 = linlsqsvd(C1, C2, y);
97
98
99 % combine results
100 for ii=1:numel(pobj1.y)
101 prs(ii) = ao(cdata(pobj1.y(ii)));
102 prs(ii).setYunits(pobj1.yunits(ii));
103 end
104 Pars = matrix(prs,plist('shape',[numel(prs),1]));
105 yfit1 = C*Pars;
106
107 %%% do linear combination: using eval
108 yfit2 = pobj1.eval;
109
110 % Plot (compare data with fit)
111 iplot(y.objs(1), yfit1.objs(1), yfit2.objs(1))
112 iplot(y.objs(2), yfit1.objs(2), yfit2.objs(2))
113
114