0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % TEST_AO_LINFIT tests the linfit method of the AO class.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % M Hueller 02-03-10
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % $Id: test_ao_linfit.m,v 1.6 2011/05/15 22:52:57 mauro Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % function test_ao_linfit()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 %% Make fake AO from polyval
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 nsecs = 100;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 fs = 10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 u1 = unit(cell2mat(utils.math.randelement(unit_list,1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 u2 = unit(cell2mat(utils.math.randelement(unit_list,1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 pl1 = plist('nsecs', nsecs, 'fs', fs, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 'tsfcn', 'polyval([10 1], t) + randn(size(t))', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 'xunits', 's', 'yunits', u1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 pl2 = plist('nsecs', nsecs, 'fs', fs, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 'tsfcn', 'polyval([-5 0.2], t) + randn(size(t))', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 'xunits', 's', 'yunits', u2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 a1 = ao(pl1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 a2 = ao(pl2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 a = scatterData(a1, a2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 %% Fit with a straight line
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 p11 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 ));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 p12 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 'dy', 0.1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 p22 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 'dx', 0.1, 'dy', 0.1, 'P0', [0 0]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 p13 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 'dy', 0.1*ones(size(a1.y))));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 p23 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 'dx', 0.1*ones(size(a1.x)), 'dy', 0.1*ones(size(a1.y)), 'P0', [0 0]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 p14 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 'dy', ao(0.1, plist('yunits', a1.yunits))));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 p24 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 'dx', ao(0.1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 'yunits', a1.xunits)), 'dy', ao(0.1, plist('yunits', a1.yunits)), 'P0', [0 0]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 p15 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 'dy', ao(0.1*ones(size(a1.y)), plist('yunits', a1.yunits))));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 p25 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 'dx', ao(0.1*ones(size(a1.x)), plist('yunits', a1.xunits)), 'dy', ao(0.1*ones(size(a1.y)), plist('yunits', a1.yunits)), 'P0', [0 0]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 p26 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 'dx', 0.1, 'dy', 0.1, 'P0', ao([0 0])));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 p27 = linfit(a1, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 'dx', 0.1, 'dy', 0.1, 'P0', p11));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 %% Compute fit: evaluating pest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 b11 = p11.eval(plist('type', 'tsdata', 'XData', a1, 'xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 b12 = p12.eval(plist('XData', a1, 'xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 b22 = p22.eval(a1, plist('xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 b13 = p13.eval(plist('XData', a1, 'xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 b23 = p23.eval(a1, plist('type', 'tsdata', 'xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 b14 = p14.eval(plist('XData', a1, 'xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 b24 = p24.eval(a1, plist('type', 'tsdata', 'xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 b15 = p15.eval(a1, plist('xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 b25 = p25.eval(plist('XData', a1, 'xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 b26 = p26.eval(plist('type', 'tsdata', 'XData', a1.x));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 b27 = p27.eval(plist('type', 'tsdata', 'XData', a1.x));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 %% Plot fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 iplot(a1, b11, b12, b13, b14, b15, b26, b27, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 b22, b23, b24, b25, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 plist('LineStyles', {'', '--'}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 %% Remove linear trend
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 c = a1-b11;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 iplot(c)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 plot(c.hist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 %% Reproduce from history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 disp('Try rebuilding')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 a_out = rebuild(c);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 iplot(a_out)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 plot(a_out.hist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 %% Fit with a straight line
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 p = linfit(a, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 ));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 %% Compute fit: evaluating pest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 b1 = p.eval(plist('XData', a, 'xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 b2 = p.eval(a, plist('xfield', 'x'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 b3 = p.eval(plist('type', 'xydata', 'XData', a.x, 'xunits', a.xunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 b4 = p.eval(plist('XData', a.x, 'xunits', a.xunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 %% Plot fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 iplot(a, b1, b2, b3, b4, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 plist('LineStyles', {'', '--'}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 %% Fit with a straight line
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 p11 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 ));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 p12 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 'dy', 0.1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 p22 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 'dx', 0.1, 'dy', 0.1, 'P0', [0 0]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 p13 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 'dy', 0.1*ones(size(a1.x))));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 p23 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 'dx', 0.1*ones(size(a1.x)), 'dy', 0.1*ones(size(a1.x)), 'P0', [0 0]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 p14 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 'dy', ao(0.1, plist('yunits', a2.yunits))));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 p24 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 'dx', ao(0.1, plist('yunits', a1.yunits)), 'dy', ao(0.1, plist('yunits', a2.yunits)), 'P0', [0 0]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 p15 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 'dy', ao(0.1*ones(size(a2.y)), plist('yunits', a2.yunits))));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 p25 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 'dx', ao(0.1*ones(size(a1.y)), plist('yunits', a1.yunits)), 'dy', ao(0.1*ones(size(a2.y)), plist('yunits', a2.yunits)), 'P0', [0 0]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 p26 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 'dx', 0.1, 'dy', 0.1, 'P0', ao([0 0])));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 p27 = linfit(a1, a2, plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 'dx', 0.1, 'dy', 0.1, 'P0', p11));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 %% Compute fit: evaluating pest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 b11 = p11.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 b12 = p12.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 b22 = p22.eval(a1, plist('type', 'xydata'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 b13 = p13.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 b23 = p23.eval(a1, plist('type', 'xydata'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 b14 = p14.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 b24 = p24.eval(a1, plist('type', 'xydata'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 b15 = p15.eval(a1, plist('type', 'xydata'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 b25 = p25.eval(plist('type', 'xydata', 'XData', a1.y));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 b26 = p26.eval(plist('type', 'xydata', 'XData', a1.y));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 b27 = p27.eval(plist('type', 'xydata', 'XData', a1.y));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 % Build reference object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 a12 = ao(plist('xvals', a1.y, 'yvals', a2.y, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 'xunits', a1.yunits, 'yunits', a2.yunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 %% Plot fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 iplot(b22, b23, b24, b15, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 b12, b13, b14, b11, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 plist('LineStyles', {'', '--'}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 %% Plot fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 iplot(b25, b26, b27, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 plist('LineStyles', {'', '--'}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 %% Remove linear trend
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 c = a12-b27;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 iplot(c)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 plot(c.hist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 %% Reproduce from history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 disp('Try rebuilding')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 a_out = rebuild(c);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 iplot(a_out)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 plot(a_out.hist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 % END
|