Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_zDomainFit_1.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 script for zDomainFit | |
2 % | |
3 % L. Ferraioli 02-12-08 | |
4 % | |
5 % $Id: test_ao_zDomainFit_1.m,v 1.7 2009/12/02 16:50:49 luigi Exp $ | |
6 % | |
7 %% Building a frequency response | |
8 | |
9 % Create a frequency-series AO | |
10 % pl_data = plist('fsfcn', '0.01./(0.01+f)', 'f1', 1e-6, 'f2', 5, 'nf', 1000); | |
11 pl_data = plist('fsfcn', '(1e-3./(f).^2 + 1e3./(0.001+f) + 1e5.*f.^2).*1e-10', 'f1', 1e-6, 'f2', 5, 'nf', 100); | |
12 a = ao(pl_data); | |
13 a.setName; | |
14 | |
15 % iplot(a) | |
16 | |
17 %% Fitting 1 | |
18 % Check if Mean Square Error is lower than FITTOL and its relative | |
19 % variation is lower than MSEVARTOL | |
20 | |
21 % Fitting parameter list | |
22 pl_fit = plist('FS',10,... | |
23 'AutoSearch','on',... | |
24 'StartPoles',[],... | |
25 'StartPolesOpt','clog',... | |
26 'maxiter',40,... | |
27 'minorder',10,... | |
28 'maxorder',25,... | |
29 'weights',[],... | |
30 'weightparam','abs',... | |
31 'CONDTYPE','MSE',... | |
32 'FITTOL',1e-4,... % check if MSE is lower than 1e-4 | |
33 'MSEVARTOL',1e-2,... | |
34 'Plot','off',... | |
35 'ForceStability','off',... | |
36 'CheckProgress','off'); | |
37 | |
38 % Do fit | |
39 mod = zDomainFit(a, pl_fit); | |
40 | |
41 %% Fitting 2 | |
42 % Check if Rresiduals log difference is larger than FITTOL and MSE relative | |
43 % variation is lower than MSEVARTOL | |
44 | |
45 % Fitting parameter list | |
46 pl_fit = plist('FS',10,... | |
47 'AutoSearch','on',... | |
48 'StartPoles',[],... | |
49 'StartPolesOpt','clog',... | |
50 'maxiter',40,... | |
51 'minorder',10,... | |
52 'maxorder',25,... | |
53 'weights',[],... | |
54 'weightparam','abs',... | |
55 'CONDTYPE','RLD',... | |
56 'FITTOL',1,... % check if RLD is larger than 1 | |
57 'MSEVARTOL',1e-2,... | |
58 'Plot','off',... | |
59 'ForceStability','off',... | |
60 'CheckProgress','off'); | |
61 | |
62 % Do fit | |
63 mod = zDomainFit(a, pl_fit); | |
64 | |
65 %% Fitting 3 | |
66 % Check if Rresiduals spectral flatness is larger than FITTOL and MSE relative | |
67 % variation is lower than MSEVARTOL | |
68 | |
69 % Fitting parameter list | |
70 pl_fit = plist('FS',10,... | |
71 'AutoSearch','on',... | |
72 'StartPoles',[],... | |
73 'StartPolesOpt','clog',... | |
74 'maxiter',40,... | |
75 'minorder',10,... | |
76 'maxorder',25,... | |
77 'weights',[],... | |
78 'weightparam','abs',... | |
79 'CONDTYPE','RSF',... | |
80 'FITTOL',0.03,... % check if RSF is larger than 0.03 | |
81 'MSEVARTOL',1e-2,... | |
82 'Plot','off',... | |
83 'ForceStability','off',... | |
84 'CheckProgress','off'); | |
85 | |
86 % Do fit | |
87 mod = zDomainFit(a, pl_fit); | |
88 | |
89 %% Comparison | |
90 | |
91 resp = mod.procinfo.find('FIT_RESP'); | |
92 resids = mod.procinfo.find('FIT_RESIDUALS'); | |
93 mse = mod.procinfo.find('FIT_MSE'); | |
94 iplot(a,resp,abs(resids)) | |
95 | |
96 %% Testing the ability of reproducing models | |
97 | |
98 clear all | |
99 % Define a pratial fraction miir object | |
100 f = logspace(-6,log10(5),30); | |
101 fs = 10; | |
102 res = [0.7 0.2+0.01i 0.2-0.01i]; | |
103 poles = [0.5 0.1+0.07i 0.1-0.07i]; | |
104 tmod(3,1) = miir; | |
105 | |
106 for ii = 1:3 | |
107 tmod(ii,1) = miir(res(ii),[1 -poles(ii)],fs); | |
108 end | |
109 | |
110 btmod = filterbank(plist('filters',tmod,'type','parallel')); | |
111 | |
112 rtmod = resp(btmod.filters,plist('bank','parallel','f',f.')); | |
113 | |
114 % do the fit on the response | |
115 fs = 10; | |
116 plstd2 = plist('FS',fs,... | |
117 'AutoSearch','off',... | |
118 'StartPoles',[],... | |
119 'StartPolesOpt','clog',... | |
120 'maxiter',60,... | |
121 'minorder',3,... | |
122 'maxorder',3,... | |
123 'weights',[],... | |
124 'weightparam','abs',... | |
125 'CONDTYPE','MSE',... | |
126 'FITTOL',1e-3,... % check if MSE is lower than 1e-3 | |
127 'MSEVARTOL',1e-2,... | |
128 'Plot','off',... | |
129 'ForceStability','off',... | |
130 'CheckProgress','off'); | |
131 out = zDomainFit(rtmod,plstd2); | |
132 | |
133 % Check that coefficients are equal within a tolerance | |
134 for kk=1:numel(out.filters) | |
135 if any(abs(tmod(kk).a - out.filters(kk).a)>1e-6) | |
136 disp([num2str(kk) 'numerator coefficients are not consistent']); | |
137 else | |
138 disp([num2str(kk) 'numerator coefficients are consistent']) | |
139 end | |
140 if any(abs(tmod(kk).b - out.filters(kk).b)>1e-6) | |
141 disp([num2str(kk) 'denominator coefficients are not consistent']); | |
142 else | |
143 disp([num2str(kk) 'denominator coefficients are consistent']) | |
144 end | |
145 | |
146 end | |
147 | |
148 | |
149 %% help example | |
150 | |
151 pl = plist('fsfcn', '(1e-3./(2.*pi.*1i.*f).^2 + 1e3./(0.001+2.*pi.*1i.*f) + 1e5.*(2.*pi.*1i.*f).^2).*1e-10', 'f1', 1e-6, 'f2', 5, 'nf', 100); | |
152 a = ao(pl); | |
153 a.setName; | |
154 | |
155 % Fitting parameter list | |
156 pl_fit = plist('FS',10,... | |
157 'AutoSearch','on',... | |
158 'StartPoles',[],... | |
159 'StartPolesOpt','clog',... | |
160 'maxiter',50,... | |
161 'minorder',15,... | |
162 'maxorder',30,... | |
163 'weights',[],... | |
164 'weightparam','abs',... | |
165 'CONDTYPE','MSE',... | |
166 'FITTOL',1e-2,... | |
167 'MSEVARTOL',1e-1,... | |
168 'Plot','on',... | |
169 'ForceStability','on',... | |
170 'CheckProgress','off'); | |
171 | |
172 % Do fit | |
173 mod = zDomainFit(a, pl_fit); | |
174 | |
175 %% help test | |
176 | |
177 pl = plist('fsfcn', '(1e-3./(2.*pi.*1i.*f).^2 + 1e3./(0.001+2.*pi.*1i.*f) + 1e5.*(2.*pi.*1i.*f).^2).*1e-10', 'f1', 1e-6, 'f2', 5, 'nf', 100); | |
178 a = ao(pl); | |
179 a.setName; | |
180 | |
181 % Fitting parameter list | |
182 pl_fit = plist('FS',10,... | |
183 'AutoSearch','on',... | |
184 'StartPoles',[],... | |
185 'StartPolesOpt','clog',... | |
186 'maxiter',50,... | |
187 'minorder',15,... | |
188 'maxorder',30,... | |
189 'weights',[],... | |
190 'weightparam','abs',... | |
191 'CONDTYPE','MSE',... | |
192 'FITTOL',1e-2,... | |
193 'MSEVARTOL',1e-1,... | |
194 'Plot','on',... | |
195 'ForceStability','on',... | |
196 'CheckProgress','off'); | |
197 | |
198 % Do fit | |
199 mod = zDomainFit(a, pl_fit); |