0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % sDomainFit performs a fitting loop to identify model order and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 % parameters.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % DESCRIPTION: sDomainFit fit a partial fraction model to frequency
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % response data using the function utils.math.vcfit.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % The function performs a fitting loop to automatically identify model
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % order and parameters in s-domain. Output is a s-domain model expanded
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % in partial fractions:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % r1 rN
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % f(s) = ------- + ... + ------- + d
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % s - p1 s - pN
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % The function attempt to perform first the identification of a model
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % with d = 0, then if the operation do not succeed, it try the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 % identification with d different from zero.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % % Identification loop stop when the stop condition is reached.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % Stop criterion is based on three different approachs:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 % 1) Mean Squared Error and variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % Check if the normalized mean squared error is lower than the value specified in
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % FITTOL and if the relative variation of the mean squared error is lower
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % than the value specified in MSEVARTOL.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % E.g. FITTOL = 1e-3, MSEVARTOL = 1e-2 search for a fit with
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % normalized magnitude error lower than 1e-3 and and MSE relative
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % variation lower than 1e-2.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 % 1) Log residuals difference and root mean squared error
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 % Log Residuals difference
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % Check if the minimum of the logarithmic difference between data and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 % residuals is larger than a specified value. ie. if the conditioning
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 % value is 2, the function ensures that the difference between data and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % residuals is at lest 2 order of magnitude lower than data itsleves.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % Root Mean Squared Error
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % Check that the variation of the root mean squared error is lower than
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 % 10^(-1*value).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 % 2) Residuals spectral flatness and root mean squared error
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % Residuals Spectral Flatness
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 % In case of a fit on noisy data, the residuals from a good fit are
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 % expected to be as much as possible similar to a white noise. This
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 % property can be used to test the accuracy of a fit procedure. In
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 % particular it can be tested that the spectral flatness coefficient of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 % the residuals is larger than a certain qiantity sf such that 0<sf<1.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % Root Mean Squared Error
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 % Check that the variation of the root mean squared error is lower than
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 % 10^(-1*value).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 % Both in the first and second approach the fitting loop stops when the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 % two stopping conditions are satisfied.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 % The output are AOs containing the frequency response of the fitted
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 % model, while the Model parameters are output as a parfrac model
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 % in the output AOs procinfo filed.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % The function can also perform a single loop without taking care of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 % the stop conditions. This happens when 'AutoSearch' parameter is
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 % setted to 'off'.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 % If you provide more than one AO as input, they will be fitted
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % together with a common set of poles.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 % CALL: mod = sDomainFit(a, pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 % INPUTS: a - input AOs to fit to. If you provide more than one AO as
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 % input, they will be fitted together with a common set
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 % of poles. Only frequency domain (fsdata) data can be
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 % fitted. Each non fsdata object will be ignored. Input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 % objects must have the same number of elements.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 % pl - parameter list (see below)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 % OUTPUTS:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 % mod - matrix of one parfrac object for each input AO.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 % Usseful fit information are stored in the procinfoi
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 % field:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % FIT_RESP - model frequency response.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 % FIT_RESIDUALS - analysis object containing the fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 % residuals.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 % FIT_MSE - analysis object containing the mean squared
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % error progression during the fitting loop.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 % Note: all the input objects are assumed to caontain the same X
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 % (frequencies) values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 % EXAMPLES:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 % 1) Fit to a frequency-series using Mean Squared Error and variation stop
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 % criterion
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 % % Create a frequency-series AO
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 % pl_data = plist('fsfcn', '0.01./(0.0001+f)', 'f1', 1e-5, 'f2', 5, 'nf', 1000);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 % a = ao(pl_data);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 % % Fitting parameter list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % pl_fit = plist('AutoSearch','on',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 % 'StartPoles',[],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 % 'StartPolesOpt','clog',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % 'maxiter',5,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 % 'minorder',2,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 % 'maxorder',20,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 % 'weights',[],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 % 'CONDTYPE','MSE',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 % 'FITTOL',1e-3,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 % 'MSEVARTOL',1e-2,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 % 'Plot','off',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 % 'ForceStability','off',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 % 'direct term','off',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 % 'CheckProgress','off');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 % % Do fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 % b = sDomainFit(a, pl_fit);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 % 2) Fit to a frequency-series using Log residuals difference and mean
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 % squared error variation stop criterion
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 % % Create a frequency-series AO
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 % pl_data = plist('fsfcn', '0.01./(0.0001+f)', 'f1', 1e-5, 'f2', 5, 'nf', 1000);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 % a = ao(pl_data);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 % % Fitting parameter list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 % pl_fit = plist('FS',[],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 % 'AutoSearch','on',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 % 'StartPoles',[],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 % 'StartPolesOpt','clog',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 % 'maxiter',5,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 % 'minorder',2,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 % 'maxorder',20,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 % 'weights',[],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 % 'weightparam','abs',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 % 'CONDTYPE','RLD',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 % 'FITTOL',1e-3,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 % 'MSEVARTOL',1e-2,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 % 'Plot','off',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 % 'ForceStability','off',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 % 'CheckProgress','off');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 % % Do fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 % b = sDomainFit(a, pl_fit);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 % 3) Fit to a frequency-series using Residuals spectral flatness and mean
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 % squared error variation stop criterion
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 % % Create a frequency-series AO
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 % pl_data = plist('fsfcn', '0.01./(0.0001+f)', 'f1', 1e-5, 'f2', 5, 'nf', 1000);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 % a = ao(pl_data);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 % % Fitting parameter list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 % pl_fit = plist('FS',[],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 % 'AutoSearch','on',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 % 'StartPoles',[],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 % 'StartPolesOpt','clog',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 % 'maxiter',5,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 % 'minorder',2,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 % 'maxorder',20,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 % 'weights',[],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 % 'weightparam','abs',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 % 'CONDTYPE','RSF',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 % 'FITTOL',0.5,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 % 'MSEVARTOL',1e-2,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 % 'Plot','off',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 % 'ForceStability','off',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 % 'CheckProgress','off');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 % % Do fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 % b = sDomainFit(a, pl_fit);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'sDomainFit')">Parameters Description</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 % VERSION: $Id: sDomainFit.m,v 1.32 2011/08/15 09:46:44 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 function varargout = sDomainFit(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 % Check if this is a call for parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 if utils.helper.isinfocall(varargin{:})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 varargout{1} = getInfo(varargin{3});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 import utils.const.*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 % Collect input variable names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 in_names = cell(size(varargin));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 for ii = 1:nargin,in_names{ii} = inputname(ii);end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 % Collect all AOs and plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 if nargout == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 error('### sDomainFit cannot be used as a modifier. Please give an output variable.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 %%% Decide on a deep copy or a modify
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 bs = copy(as, nargout);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 inhists = [as.hist];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 % combine plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 pl = parse(pl, getDefaultPlist());
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 %%%%% Extract necessary parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 extpoles = find(pl, 'StartPoles'); % Check if external poles are providied
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 spolesopt = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 if isempty(extpoles) % if no external poles set them internally
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 splopt = find(pl, 'StartPolesOpt');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 switch lower(splopt)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 case 'real'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 spolesopt = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 case 'clog'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 spolesopt = 2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 case 'clin'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 spolesopt = 3;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 maxiter = find(pl, 'maxiter'); % set the maximum number of iterations
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 minorder = find(pl, 'minorder'); % set the minimum function order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 maxoredr = find(pl, 'maxorder');% set the maximum function order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 extweights = find(pl, 'weights'); % check if external weights are provided
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 weightparam = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 if isempty(extweights) % set internally the weights on the basis of the input options
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 wtparam = find(pl, 'weightparam');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 switch lower(wtparam)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 case 'ones'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 weightparam = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 case 'abs'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 weightparam = 2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 case 'sqrt'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 weightparam = 3;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 % decide to plot or not
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 plt = find(pl, 'plot');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 switch lower(plt)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 case 'on'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 showplot = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 case 'off'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 showplot = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 % Make a decision between Fit conditioning type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 condtype = find(pl, 'CONDTYPE');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 condtype = upper(condtype);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 switch condtype
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 case 'MSE'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 ctp = 'chivar'; % use normalized mean squared error value and relative variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 lrscond = find(pl, 'FITTOL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 % give an error for strange values of lrscond
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 if lrscond<0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 error('!!! Negative values for FITTOL are not allowed !!!')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 % handling data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 lrscond = -1*log10(lrscond);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 % give a warning for strange values of lrscond
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 if lrscond<0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 warning('You are searching for a MSE lower than %s', num2str(10^(-1*lrscond)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 case 'RLD'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 ctp = 'lrsmse'; % use residuals log difference and MSE relative variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 lrscond = find(pl, 'FITTOL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 % give a warning for strange values of lrscond
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 if lrscond<0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 error('!!! Negative values for FITTOL are not allowed !!!')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 if lrscond<1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 warning('You are searching for a frequency by frequency residuals log difference of %s', num2str(lrscond))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 case 'RSF'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 ctp = 'rftmse'; % use residuals spectral flatness and MSE relative variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 lrscond = find(pl, 'FITTOL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 % give a warning for strange values of lrscond
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 if lrscond<0 || lrscond>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 error('!!! Values <0 or >1 for FITTOL are not allowed when CONDTYPE is RSF !!!')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 % Tolerance for the MSE relative variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 msevar = find(pl, 'MSEVARTOL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 % handling data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 msevar = -1*log10(msevar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 % give a warning for strange values of msevar
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 if msevar<0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 warning('You are searching for MSE relative variation lower than %s', num2str(10^(-1*msevar)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 % decide to stabilize or not the model
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 stab = find(pl, 'ForceStability');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297 switch lower(stab)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 case 'on'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 stabfit = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 case 'off'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 stabfit = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 % decide to fit with or whitout direct term
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 dtm = find(pl, 'direct term');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 switch lower(dtm)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307 case 'on'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 dterm = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 case 'off'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 dterm = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313 % decide to disp or not the fitting progress in matlab command window
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314 prg = find(pl, 'CheckProgress');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315 switch lower(prg)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316 case 'on'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 spy = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318 case 'off'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
319 spy = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
320 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
321
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 % decide to perform or not a full automatic model search
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 autos = find(pl, 'AutoSearch');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324 switch lower(autos)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 case 'on'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326 fullauto = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 case 'off'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328 fullauto = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
329 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
330
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
331 % extract delay
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
332 delay = find(pl, 'delay');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
333
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
334 %%%%% End Extract necessary parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
335
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
336
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
337
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
338 %%%%% Fitting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
339
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
340 % Fit parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
341 params = struct('spolesopt',spolesopt,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
342 'extpoles', extpoles,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
343 'Nmaxiter',maxiter,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
344 'minorder',minorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
345 'maxorder',maxoredr,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
346 'weightparam',weightparam,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
347 'extweights', extweights,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
348 'plot',showplot,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
349 'ctp',ctp,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
350 'lrscond',lrscond,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
351 'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
352 'stabfit',stabfit,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
353 'dterm',dterm,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
354 'spy',spy,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
355 'fullauto',fullauto);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
356
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
357 %%% extracting elements from AOs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
358
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
359 % Finding the index of the first fsdata
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
360 for gg = 1:numel(bs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
361 if isa(bs(gg).data, 'fsdata')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
362 prm = gg;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
363 break
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
364 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
365 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
366
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
367 y = zeros(length(bs(prm).data.getY),numel(bs)); % initialize input vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
368 k = numel(bs(prm).data.getY); % setting a comparison constant
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
369 idx = true(numel(bs),1); % initialize the control index
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
370 for jj=1:numel(bs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
371 % checking that AOs are fsdata and skipping non fsdata objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
372 if ~isa(bs(jj).data, 'fsdata')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
373 % skipping data if non fsdata
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
374 warning('!!! %s expects ao/fsdata objects. Skipping AO %s', mfilename, ao_invars{jj});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
375 idx(jj) = false; % set the corresponding value of the control index to false
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
376 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
377 % preparing data for fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
378 yt = bs(jj).data.getY;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
379 if numel(yt)~=k
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
380 error('Input AOs must have the same number of elements')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
381 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
382 if size(yt,2)>1 % wish to work with columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
383 y(:,jj) = yt.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
384 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
385 y(:,jj) = yt;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
386 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
387 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
388 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
389 %%% extracting frequencies
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
390 % Note: all the objects are assumed to caontain the same X (frequencies) values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
391 f = bs(prm).data.getX;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
392
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
393 % reshaping y to contain only Y from fsdata, subtract delay if given by
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
394 % user
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
395 if ~isempty(delay)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
396 y = y(:,idx)./exp(-2*pi*1i*f*delay);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
397 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
398 y = y(:,idx);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
399 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
400
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
401 % Fitting loop
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
402 [res,poles,dterm,mresp,rdl,mse] = utils.math.autocfit(y,f,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
403
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
404 %%%%% Building output AOs with model responses, model parameters are %%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
405
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
406 for kk = 1:numel(bs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
407 if idx(kk) % set the corresponding Y values of fitted data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
408
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
409 % if delay is input we return a pzmodel with the corresponding delay
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
410 if isempty(delay)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
411 mdl(kk) = parfrac(plist('res', res(:,kk),'poles', poles, 'dir',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
412 dterm(:,kk), 'name', sprintf('fit(%s)', ao_invars{kk})));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
413 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
414 mdl_aux = parfrac(plist('res', res(:,kk),'poles', poles, 'dir',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
415 dterm(:,kk), 'name', sprintf('fit(%s)', ao_invars{kk})));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
416 mdl(kk) = pzmodel(mdl_aux);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
417 mdl(kk).setDelay(delay);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
418 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
419
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
420 % Output also response, residuals and mse progression in the procinfo
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
421
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
422 rsp = mresp(:,kk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
423 bs(kk).data.setY(rsp);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
424
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
425 % Set output AO name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
426 bs(kk).name = sprintf('fit(%s)', ao_invars{kk});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
427
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
428 res_ao = copy(bs(kk),1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
429 trdl = rdl(:,kk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
430 res_ao.data.setY(trdl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
431
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
432 % Set output AO name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
433 res_ao.name = sprintf('fit_residuals(%s)', ao_invars{kk});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
434
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
435 d = cdata();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
436 tmse = mse(:,kk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
437 d.setY(tmse);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
438 mse_ao = ao(d);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
439
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
440 % Set output AO name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
441 mse_ao.name = sprintf('fit_mse(%s)', ao_invars{kk});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
442
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
443 procpl = plist('fit_resp',bs(kk),...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
444 'fit_residuals',res_ao,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
445 'fit_mse',mse_ao);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
446
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
447 mdl(kk).setProcinfo(procpl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
448
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
449 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
450 mdl(kk) = parfrac();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
451 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
452
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
453 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
454
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
455 % set output as matrix if multiple inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
456 if numel(mdl) ~= 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
457 mmdl = matrix(mdl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
458 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
459 mmdl = mdl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
460 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
461
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
462 mmdl.setName(sprintf('fit(%s)', ao_invars{:}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
463
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
464 mmdl.addHistory(getInfo('None'), pl, [ao_invars(:)], [inhists(:)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
465
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
466 % ----- Set outputs -----
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
467 if nargout == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
468 varargout{1} = mmdl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
469 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
470 % multiple output is not supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
471 error('### Multiple output is not supported ###')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
472 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
473
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
474 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
475
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
476 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
477 % Get Info Object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
478 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
479 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
480 if nargin == 1 && strcmpi(varargin{1}, 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
481 sets = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
482 pl = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
483 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
484 sets = {'Default'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
485 pl = getDefaultPlist;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
486 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
487 % Build info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
488 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: sDomainFit.m,v 1.32 2011/08/15 09:46:44 hewitson Exp $', sets, pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
489 ii.setModifier(false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
490 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
491
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
492 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
493 % Get Default Plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
494 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
495 function plout = getDefaultPlist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
496 persistent pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
497 if exist('pl', 'var')==0 || isempty(pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
498 pl = buildplist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
499 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
500 plout = pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
501 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
502
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
503 function pl = buildplist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
504
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
505 pl = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
506
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
507 % AutoSearch
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
508 p = param({'AutoSearch', ['''on'': Parform a full automatic search for the<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
509 'transfer function order. The fitting<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
510 'procedure will stop when stop conditions<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
511 'defined are satisfied.<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
512 '''off'': Perform a fitting loop as long as the<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
513 'number of iteration reach ''maxiter''. The order<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
514 'of the fitting function will be that<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
515 'specified in ''minorder''.']}, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
516 {1, {'on', 'off'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
517 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
518
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
519 % StartPoles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
520 p = param({'StartPoles', ['A vector of starting poles. Providing a fixed<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
521 'set of starting poles fixes the function<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
522 'order. If it is left empty starting poles are<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
523 'internally assigned.']}, paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
524 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
525
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
526 % StartPolesOpt
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
527 p = param({'StartPolesOpt', ['Define the characteristics of internally<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
528 'assigned starting poles. Admitted values<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
529 'are:<ul>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
530 '<li>''real'' linear-spaced real poles</li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
531 '<li>''clog'' log-spaced complex poles</li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
532 '<li>''clin'' linear-spaced complex poles<li></ul>']}, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
533 {2, {'real', 'clog', 'clin'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
534 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
535
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
536 % MaxIter
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
537 p = param({'MaxIter', 'Maximum number of iterations in fit routine.'}, paramValue.DOUBLE_VALUE(50));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
538 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
539
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
540 % MinOrder
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
541 p = param({'MinOrder', 'Minimum order to fit with.'}, paramValue.DOUBLE_VALUE(2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
542 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
543
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
544 % MaxOrder
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
545 p = param({'MaxOrder', 'Maximum order to fit with.'}, paramValue.DOUBLE_VALUE(20));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
546 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
547
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
548 % Weights
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
549 p = param({'Weights', ['A vector with the desired weights. If a single<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
550 'Ao is input weights must be a Nx1 vector where<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
551 'N is the number of elements in the input Ao. If<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
552 'M Aos are passed as input, then weights must<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
553 'be a NxM matrix. If it is leaved empty weights<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
554 'are internally assigned basing on the input<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
555 'parameters']}, paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
556 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
557
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
558 % Weightparam
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
559 p = param({'weightparam', ['Specify the characteristics of the internally<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
560 'assigned weights. Admitted values are:<ul>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
561 '<li>''ones'' assigns weights equal to 1 to all data.<li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
562 '<li>''abs'' weights data with <tt>1./abs(y)</tt></li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
563 '<li>''sqrt'' weights data with <tt>1./sqrt(abs(y))</tt></li>']}, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
564 {2, {'ones', 'abs', 'sqrt'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
565 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
566
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
567 % CONDTYPE
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
568 p = param({'CONDTYPE', ['Fit conditioning type. Admitted values are:<ul>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
569 '<li>''MSE'' Mean Squared Error and variation</li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
570 '<li>''RLD'' Log residuals difference and mean squared error variation<li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
571 '<li>''RSF'' Residuals spectral flatness and mean squared error variation<li></ul>']}, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
572 {1, {'MSE', 'RLD', 'RSF'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
573 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
574
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
575 % FITTOL
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
576 p = param({'FITTOL', 'Fit tolerance.'}, paramValue.DOUBLE_VALUE(1e-3));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
577 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
578
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
579 % MSEVARTOL
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
580 p = param({'MSEVARTOL', ['Mean Squared Error Variation - Check if the<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
581 'realtive variation of the mean squared error is<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
582 'smaller than the value specified. This<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
583 'option is useful for finding the minimum of Chi-squared.']}, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
584 paramValue.DOUBLE_VALUE(1e-2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
585 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
586
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
587 % Plot
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
588 p = param({'Plot', 'Plot results of each fitting step.'}, {2, {'on', 'off'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
589 p.val.setValIndex(2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
590 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
591
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
592 % ForceStability
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
593 p = param({'ForceStability', 'Force poles to be stable'}, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
594 {2, {'on', 'off'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
595 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
596
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
597 % direct term
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
598 p = param({'direct term', 'Fit with direct term.'}, {2, {'on', 'off'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
599 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
600
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
601 % CheckProgress
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
602 p = param({'CheckProgress', 'Display the status of the fit iteration.'}, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
603 {2, {'on', 'off'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
604 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
605
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
606 % Delay
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
607 p = param({'delay', 'Innput a delay that will be subtracted from the fit.<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
608 'The output is a pzmodel which includes the inputted delay.'},paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
609 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
610 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
611 % END
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
612
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
613
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
614 % PARAMETERS:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
615 % 'AutoSearch' - 'on': Parform a full automatic search for the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
616 % transfer function order. The fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
617 % procedure will stop when stop conditions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
618 % defined are satisfied. [Default]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
619 % 'off': Perform a fitting loop as long as the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
620 % number of iteration reach 'maxiter'. The order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
621 % of the fitting function will be that
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
622 % specified in 'minorder'.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
623 % 'StartPoles' - A vector of starting poles. Providing a fixed
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
624 % set of starting poles fixes the function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
625 % order. If it is left empty starting poles are
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
626 % internally assigned. [Default []]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
627 % 'StartPolesOpt' - Define the characteristics of internally
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
628 % assigned starting poles. Admitted values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
629 % are:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
630 % 'real' linspaced real poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
631 % 'clog' logspaced complex poles [Default]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
632 % 'clin' linspaced complex poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
633 % 'maxiter' - Maximum number of allowed iteration. [Deafult
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
634 % 50].
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
635 % 'minorder' - Minimum model function order. [Default 2]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
636 % 'maxorder' - Maximum model function order. [Default 20]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
637 % 'weights' - A vector with the desired weights. If a single
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
638 % Ao is input weights must be a Nx1 vector where
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
639 % N is the number of elements in the input Ao. If
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
640 % M Aos are passed as input, then weights must
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
641 % be a NxM matrix. If it is leaved empty weights
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
642 % are internally assigned basing on the input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
643 % parameters. [Default []]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
644 % 'weightparam' - Specify the characteristics of the internally
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
645 % assigned weights. Admitted values are:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
646 % 'ones' assigns weights equal to 1 to all data.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
647 % 'abs' weights data with 1./abs(y) [Default]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
648 % 'sqrt' weights data with 1./sqrt(abs(y))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
649 % 'CONDTYPE' - Fit conditioning type. Admitted values are:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
650 % - 'MSE' Mean Squared Error and variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
651 % [Default]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
652 % - 'RLD' Log residuals difference and mean
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
653 % squared error variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
654 % - 'RSF' Residuals spectral flatness and mean
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
655 % squared error variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
656 % 'FITTOL' - Fit tolerance [Default, 1e-3]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
657 % 'MSEVARTOL' - This allow to check if the relative variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
658 % of mean squared error is lower than the value
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
659 % sepcified. [Default 1e-2]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
660 % 'Plot' - Plot fit result: 'on' or 'off' [default]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
661 % 'ForceStability' - Force poles to be stable, values are
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
662 % 'on' or 'off'. [Default 'off']
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
663 % 'direct term' - Fit with direct term if 'on', without if
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
664 % 'off'. [Default 'off']
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
665 % 'CheckProgress' - Disply the status of the fit iteration.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
666 % Values are 'on and 'off'. [Default 'off']
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
667 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
668 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
669
|