Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_padded_sine_model.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 clear all; | |
2 | |
3 %% | |
4 fs = 100; | |
5 nsecs = 20; | |
6 t = [0:1/fs:nsecs-1/fs]; | |
7 | |
8 a = ao(plist('built-in', 'padded_sine', ... | |
9 'f0', .1, ... | |
10 'Timebase', t, ... | |
11 'Tstart', 1.1, ... | |
12 'Ncycles', 2.1, ... | |
13 'phi', 90)) | |
14 | |
15 n = ao(plist('tsfcn', '0.1*randn(size(t))', 'fs', fs, 'nsecs', nsecs)); | |
16 | |
17 sw = a+n; | |
18 | |
19 sw.iplot | |
20 | |
21 %% Now try to fit this | |
22 | |
23 % [dc,A,f0,phi,Tstart,N] | |
24 af = ao(plist('built-in', 'padded_sine', ... | |
25 'Timebase', sw, ... | |
26 'f0', .1, ... | |
27 'P', [0 1 .11 90 1 2])); | |
28 | |
29 iplot(sw, af) | |
30 | |
31 %% Now fit with simplex | |
32 | |
33 opts = optimset('Display', 'iter', ... | |
34 'MaxFunEvals', 10000, ... | |
35 'MaxIter', 10000, ... | |
36 'TolX', 1e-15, ... | |
37 'TolFun', 1e-15, ... | |
38 'LargeScale', 'on'); | |
39 | |
40 r0 = [0 1 .11 90 1 2]; | |
41 | |
42 mksine = @(r)(ao(plist('built-in', 'padded_sine', ... | |
43 'Timebase', sw, ... | |
44 'P', r)).y); | |
45 | |
46 f = @(r)(sum((mksine(r)-sw.y).^2)); | |
47 | |
48 % Do a few iterative fits | |
49 % for kk=1:5 | |
50 x0 = fminsearch(f, r0, opts); | |
51 % end | |
52 | |
53 | |
54 %% | |
55 | |
56 afit = ao(plist('built-in', 'padded_sine', 'Timebase', sw, 'P', x0)); | |
57 | |
58 iplot(sw, afit) | |
59 | |
60 | |
61 |