Mercurial > hg > ltpda
comparison m-toolbox/test/utils/test_2dim_vcfit.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 Fitting procedure in 2dim z-domain VDFIT | |
3 % At the end you have 4 stable transfer functions in partial fractions | |
4 % | |
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
6 % HISTORY: 02-10-2008 L Ferraioli | |
7 % Creation | |
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
9 %% VERSION | |
10 | |
11 '$Id: test_2dim_vcfit.m,v 1.1 2009/04/23 10:11:26 luigi Exp $'; | |
12 | |
13 %% Clear | |
14 | |
15 clear all | |
16 | |
17 %% Loading spectra | |
18 | |
19 load ..\m-toolbox\test\mpsd.mat % load mpsd.mat first column is f then psd1, csd and psd2 | |
20 | |
21 f = mpsd(:,1); | |
22 psd1 = mpsd(:,2); | |
23 csd = mpsd(:,3); | |
24 psd2 = mpsd(:,4); | |
25 fs = 10; | |
26 | |
27 | |
28 %% Eigendecomposition | |
29 | |
30 [tf11,tf12,tf21,tf22] = utils.math.eigcsd(psd1,csd,conj(csd),psd2); | |
31 | |
32 %% Constructing vector | |
33 | |
34 f1 = [tf11 tf21]; | |
35 f2 = [tf12 tf22]; | |
36 | |
37 %% VCFIT | |
38 | |
39 N = 26; %Order of approximation | |
40 | |
41 | |
42 % Max Iteration | |
43 Nmaxiter = 70; | |
44 | |
45 % Fitting params | |
46 fitin.stable = 0; | |
47 fitin.dterm = 0; | |
48 fitin.plot = 0; | |
49 | |
50 weight = utils.math.wfun(f1,2); | |
51 % weight = 1./abs(f1); | |
52 | |
53 pparams = struct('spolesopt',2, 'type','CONT', 'pamp', 0.01); | |
54 poles1 = utils.math.startpoles(N,f,pparams); | |
55 for hh = 1:Nmaxiter | |
56 [res1,poles1,dterm1,mresp1,rdl1,mse1] = utils.math.vcfit(f1,f,poles1,weight,fitin); % Fitting | |
57 % disp(['Iter' num2str(hh)]) | |
58 | |
59 % Stop condition checking | |
60 order = length(poles1); | |
61 mlr1(hh) = mse1(:,1); | |
62 mlr2(hh) = mse1(:,2); | |
63 % [ext1,msg1] = stopfit(f1(:,1),rdl1(:,1),mlr1,order,'mlsrvar',2,0.0001,2); | |
64 % [ext2,msg2] = stopfit(f1(:,2),rdl1(:,2),mlr2,order,'mlsrvar',2,0.0001,2); | |
65 % | |
66 % if ext1 && ext2 | |
67 % disp(msg1) | |
68 % break | |
69 % end | |
70 | |
71 end | |
72 | |
73 % plotting squared error | |
74 figure() | |
75 semilogy(mlr1,'-ok') | |
76 hold on | |
77 grid on | |
78 semilogy(mlr2,'-or') | |
79 | |
80 % % plotting RMS error variation | |
81 % figure() | |
82 % semilogy(abs(diff(sqrt(mlr1))),'-ok') | |
83 % hold on | |
84 % grid on | |
85 % semilogy(abs(diff(sqrt(mlr2))),'-or') | |
86 | |
87 % plotting squared error variation | |
88 figure() | |
89 semilogy(abs(diff(mlr1)./mlr1(1,end-1)),'-ok') | |
90 hold on | |
91 grid on | |
92 semilogy(abs(diff(mlr2)./mlr2(1,end-1)),'-or') | |
93 | |
94 %% All Passing | |
95 | |
96 [np1,resp1] = pfallps(res1,poles1,dterm1,mresp1,f); | |
97 | |
98 | |
99 figure() | |
100 subplot(2,1,1); | |
101 p1 = loglog(f,abs(mresp1),'k'); | |
102 hold on | |
103 p2 = loglog(f,abs(resp1),'r'); | |
104 xlabel('Frequency [Hz]') | |
105 ylabel('Amplitude') | |
106 legend([p1(1) p2(1)],'VDFIT','Stabilized') | |
107 hold off | |
108 | |
109 subplot(2,1,2); | |
110 p4 = semilogx(f,(180/pi).*unwrap(angle(mresp1)),'k'); | |
111 hold on | |
112 p5 = semilogx(f,(180/pi).*unwrap(angle(resp1)),'r'); | |
113 xlabel('Frequency [Hz]') | |
114 ylabel('Phase [Deg]') | |
115 legend([p4(1) p5(1)],'VDFIT', 'Stabilized') | |
116 hold off | |
117 | |
118 %% VCFIT | |
119 | |
120 N = 14; %Order of approximation | |
121 | |
122 | |
123 % Max Iteration | |
124 Nmaxiter = 50; | |
125 | |
126 % Fitting params | |
127 fitin.stable = 0; | |
128 fitin.dterm = 0; | |
129 fitin.plot = 1; | |
130 | |
131 weight = wfun(f2,1); | |
132 | |
133 pparams = struct('spolesopt',1, 'type','CONT', 'pamp', 0.01); | |
134 poles2 = startpoles(N,f,pparams); | |
135 | |
136 for hh = 1:Nmaxiter | |
137 [res2,poles2,dterm2,mresp2,rdl2] = vcfit(f2,f,poles2,weight,fitin); % Fitting | |
138 disp(['Iter' num2str(hh)]) | |
139 | |
140 % Stop condition checking | |
141 order = length(poles1); | |
142 mlr1(hh) = mean(log10(abs(f2(:,1)))-log10(abs(rdl2(:,1)))); | |
143 mlr2(hh) = mean(log10(abs(f2(:,2)))-log10(abs(rdl2(:,2)))); | |
144 [ext1,msg1] = stopfit(f2(:,1),rdl2(:,1),mlr1,order,'mlrsvar',2,0.0001,2); | |
145 [ext2,msg2] = stopfit(f2(:,2),rdl2(:,2),mlr2,order,'mlrsvar',2,0.0001,2); | |
146 | |
147 if ext1 && ext2 | |
148 disp(msg1) | |
149 break | |
150 end | |
151 | |
152 end | |
153 |