Mercurial > hg > ltpda
comparison m-toolbox/test/test_matrix_linfitsvd_ssm.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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
2 % Test linfitsvd with ssm | |
3 % | |
4 % Test with an harmonic hoscillator | |
5 % | |
6 % L Ferraioli 11-10-2010 | |
7 % | |
8 % $Id: test_matrix_linfitsvd_ssm.m,v 1.1 2010/11/22 16:57:54 luigi Exp $ | |
9 % | |
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
11 %% set parameters | |
12 | |
13 m = 2; % kg | |
14 k = 0.1; % kg s^-2 | |
15 damp = 0.05; % kg s^-1 | |
16 | |
17 fAmp = 3; | |
18 NAmp = 1; | |
19 fs = 1; | |
20 | |
21 cutbefore = 100*fs; | |
22 cutafter = 500*fs; | |
23 | |
24 %% input force and readout noise | |
25 % prepare the inputs for 2 experiments | |
26 | |
27 % input force | |
28 fc1 = ao(plist('waveform','sine wave','A',fAmp,'f',1e-1,'phi',0,'toff',cutbefore/fs,'nsecs',6e2,'fs',fs)); | |
29 in1 = zeropad(fc1,plist('Position','post','N',cutafter)); | |
30 % input readout noise | |
31 rn1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', in.nsecs)); | |
32 rn1 = rn1.*NAmp; | |
33 | |
34 % input force | |
35 fc2 = ao(plist('waveform','sine wave','A',fAmp,'f',1e-2,'phi',0,'toff',cutbefore/fs,'nsecs',6e2,'fs',fs)); | |
36 in2 = zeropad(fc2,plist('Position','post','N',cutafter)); | |
37 % input readout noise | |
38 rn2 = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', in.nsecs)); | |
39 rn2 = rn2.*NAmp; | |
40 | |
41 iplot(in1,in2) | |
42 | |
43 %% Simulate the system | |
44 | |
45 sys = ssm(plist('built-in', 'HARMONIC_OSC_1D', 'SYMBOLIC PARAMS',{'M', 'K', 'VBETA'})); | |
46 sys = sys.setParameters(plist('names',{'M', 'K', 'VBETA'},'values',[m k damp])); | |
47 sys.keepParameters(); | |
48 sys.modifyTimeStep(plist('newtimestep',1/fs)); | |
49 | |
50 plsym = plist('AOS VARIABLE NAMES',{'COMMAND.Force','noise.readout'},... | |
51 'RETURN OUTPUTS','HARMONIC_OSC_1D.position',... | |
52 'AOS',[in1,rn1]); | |
53 out1 = simulate(sys,plsym); | |
54 | |
55 plsym = plist('AOS VARIABLE NAMES',{'COMMAND.Force','noise.readout'},... | |
56 'RETURN OUTPUTS','HARMONIC_OSC_1D.position',... | |
57 'AOS',[in2,rn2]); | |
58 out2 = simulate(sys,plsym); | |
59 | |
60 iplot(out1,out2) | |
61 | |
62 %% set input data and run fit with ssm | |
63 | |
64 mod = ssm(plist('built-in', 'HARMONIC_OSC_1D', 'SYMBOLIC PARAMS',{'M', 'K', 'VBETA'})); | |
65 mod = mod.setParameters(plist('names',{'M', 'K', 'VBETA'},'values',[1.8 0.2 0.1])); | |
66 | |
67 FitParams = {'M', 'K', 'VBETA'}; | |
68 InputNames = {{'COMMAND.Force'},{'COMMAND.Force'}}; | |
69 OutputNames = {{'HARMONIC_OSC_1D.position'},{'HARMONIC_OSC_1D.position'}}; | |
70 Input = collection(in1,in2); | |
71 | |
72 o1 = matrix(out1); | |
73 o2 = matrix(out2); | |
74 | |
75 plfit = plist(... | |
76 'FitParams',FitParams,... | |
77 'Model',mod,... | |
78 'Input',Input,... | |
79 'InputNames',InputNames,... | |
80 'OutputNames',OutputNames,... | |
81 'WhiteningFilter',[],... | |
82 'tol',1,... | |
83 'Nloops',5,... % number of fit iterations | |
84 'Ncut',cutbefore); % number of data points to skip at the starting of the series to avoid whitening filter transient | |
85 | |
86 pars = linfitsvd(o1,o2,plfit); | |
87 | |
88 %% build smodel | |
89 | |
90 symmod = smodel('1./(M.*((2.*i.*pi.*f).^2)+VBETA.*(2.*i.*pi.*f)+K)'); | |
91 symmod.setParams({'M','VBETA','K'},{1.8,0.2,0.1}); | |
92 symmod.setXvar('f'); | |
93 symmod.setYunits('kg^-1 s^-2'); | |
94 smod = matrix(symmod); | |
95 | |
96 %% set input and fit | |
97 | |
98 FitParams = {'M', 'K', 'VBETA'}; | |
99 Input = collection(matrix(in1),matrix(in2)); | |
100 o1 = matrix(out1); | |
101 o2 = matrix(out2); | |
102 | |
103 plfit = plist(... | |
104 'FitParams',FitParams,... | |
105 'Model',smod,... | |
106 'Input',Input,... | |
107 'WhiteningFilter',[],... | |
108 'tol',1,... | |
109 'Nloops',5,... % number of fit iterations | |
110 'Ncut',cutbefore); % number of data points to skip at the starting of the series to avoid whitening filter transient | |
111 | |
112 pars = linfitsvd(o1,o2,plfit); |