Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_polyfit.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_POLYFIT tests the polyfit method of the AO class. | |
2 % | |
3 % M Hewitson 05-06-07 | |
4 % | |
5 % $Id: test_ao_polyfit.m,v 1.19 2011/05/12 03:38:27 mauro Exp $ | |
6 % | |
7 % function test_ao_polyfit() | |
8 | |
9 | |
10 %% Make fake AO from polyval | |
11 nsecs = 100; | |
12 fs = 10; | |
13 | |
14 unit_list = unit.supportedUnits; | |
15 u = unit(cell2mat(utils.math.randelement(unit_list,1))); | |
16 | |
17 pl = plist('nsecs', nsecs, 'fs', fs, ... | |
18 'tsfcn', 'polyval([3 2 1 ], t) + 1000*randn(size(t))', ... | |
19 'xunits', 's', 'yunits', u); | |
20 | |
21 a1 = ao(pl); | |
22 | |
23 %% Fit a polynomial | |
24 N = 3; | |
25 p1 = polyfit(a1, plist('N', N)); | |
26 p2 = polyfit(a1, plist('N', N, 'rescale', true)); | |
27 | |
28 | |
29 %% Compute fit: from polyval | |
30 | |
31 b1 = ao(plist('polyval', p1, 't', a1, 'xunits', a1.xunits)); | |
32 b2 = ao(plist('polyval', p2, 't', a1, 'xunits', a1.xunits)); | |
33 | |
34 %% Plot fit | |
35 iplot(a1, b1, plist('LineStyles', {'', '--'})); | |
36 | |
37 %% Remove polynomial | |
38 c = a1-b1; | |
39 iplot(c) | |
40 | |
41 plot(c.hist) | |
42 | |
43 %% Reproduce from history | |
44 disp('Try rebuilding') | |
45 a_out = rebuild(c); | |
46 iplot(a_out) | |
47 plot(a_out.hist) | |
48 | |
49 %% Compute fit: evaluating pest | |
50 | |
51 b11 = p1.eval(a1, plist('type', 'tsdata', 'xfield', 'x')); | |
52 mu = find(p2.procinfo, 'mu'); | |
53 b21 = p2.eval(plist('type', 'tsdata', 'XData', (a1.x - mu(1))/mu(2), 'xfield', 'x')); | |
54 b21.setX(a1.x); | |
55 | |
56 %% Plot fit | |
57 iplot(a1, b11, b21, plist('LineStyles', {'all','-'})); | |
58 | |
59 % end | |
60 % END |