0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % PSD2TF Input power spectral density (psd) and output a stable and minimum
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 % phase transfer function.
|
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:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % Input power spectral density (psd) and output a corresponding
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % stable function. Identification can be performed for a simple system
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % (one psd) or for a two dimensional system (the four elements of the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % cross-spectral matrix). Continuous or discrete transfer functions are
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % output in partial fraction expansion:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % Continuous case:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % r1 rN
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % f(s) = ------- + ... + ------- + d
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % s - p1 s - pN
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 % Discrete case:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % r1 rN
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % f(z) = ----------- + ... + ----------- + d
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % 1-p1*z^{-1} 1-pN*z^{-1}
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % System identification is performed in frequency domain, the order of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % the model function is automatically chosen by the algorithm on the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % base of the input tolerance condition.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % In the case of simple systems the square root of the psd is fitted
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % and then the model is stabilized by the application of an all-pass
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % function.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % In the case of two dimensional systems, transfer functions frequency
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 % response is calculated by the eigendecomposition of the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 % cross-spectral matrix. Then four models are identified with fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % in frequency domain. If we call these new functions as tf11, tf12,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 % tf21 and tf22, it can be verified they are connected with the input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 % spectra by the relation:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % csd11(f) = tf11(f)*conj(tf11(f))+tf12(f)*conj(tf12(f))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % csd12(f) = tf11(f)*conj(tf21(f))+tf12(f)*conj(tf22(f))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 % csd21(f) = conj(tf11(f))*tf21(f)+conj(tf12(f))*tf22(f)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 % csd22(f) = tf21(f)*conj(tf21(f))+tf22(f)*conj(tf22(f))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % CALL:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 % One dimensional system:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 % [res, poles, dterm] = psd2tf(psd,[],[],[],f,params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 % [res, poles, dterm, mresp] = psd2tf(psd,[],[],[],f,params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 % [res, poles, dterm, mresp, rdl] = psd2tf(psd,[],[],[],f,params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 % Two dimensional systems:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 % ostruct = psd2tf(csd11,csd12,csd21,csd22,f,params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 % ostruct = psd2tf(csd11,csd12,[],csd22,f,params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 % ostruct = psd2tf(csd11,[],csd21,csd22,f,params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 % INPUT:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 % - psd is the power spectral density (1dim case)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 % - csd11, csd12, csd21 and csd22 are the elements of the cross
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % spectral matrix. If csd12 is left empty, it is calculated as
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 % conj(csd21). If csd21 is left empty, it is calculated as conj(csd12).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 % (2dim case)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 % - f: is the corresponding frequencies vector in Hz
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 % - params: is a struct of identification options, the possible values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % are:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 % - params.idtp = 0 s-domain identification --> s-domain output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 % - params.idtp = 1 z-domain identification --> z-domain output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 % params.fullauto = 0 --> Perform a fitting loop as far as the number
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 % of iteration reach Nmaxiter. The order of the fitting function will
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 % be that specified in params.minorder. If params.dterm is setted to
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 % 1 the function will fit only with direct term.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 % params.fullauto = 1 --> Parform a full automatic search for the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 % transfer function order. The fitting procedure will stop when the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 % stopping condition defined in params.ctp is satisfied. Default
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 % value.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 % - params.Nmaxiter = # set the maximum number of fitting steps
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 % performed for each trial function order. Default is 50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 % - params.minorder = # set the minimum possible function order.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 % Default is 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % - params.maxorder = # set the maximum possible function order.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 % Default is 25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 % z-domain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 % params.spolesopt = 1 --> use real starting poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 % params.spolesopt = 2 --> generates complex conjugates poles of the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % type \alfa e^{j\pi\theta} with \theta = linspace(0,pi,N/2+1).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 % params.spolesopt = 3 --> generates complex conjugates poles of the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 % type \alfa e^{j\pi\theta} with \theta = linspace(0,pi,N/2+2).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 % Default option.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 % s-domain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 % params.spolesopt = 1 --> use real starting poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 % params.spolesopt = 2 --> use logspaced complex starting poles.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 % Default option
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % params.spolesopt = 3 --> use linspaced complex starting poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % - params.weightparam = 0 --> use external weights
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 % - params.weightparam = 1 equal weights (one) for each point
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 % - params.weightparam = 2 weight with the inverse of absolute value
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % of fitting data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 % - params.weightparam = 3 weight with square root of the inverse of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 % absolute value of fitting data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 % - params.weightparam = 4 weight with the inverse of the square mean
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 % spread
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 % params.extweights = [] --> A vector of externally provided weights.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 % It has to be of the same size of input data. E.g.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 % w11,w12,w21,w22 they are assumed to be in spectral units therefore
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 % they are normalized to the values of the input spectrum
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 % - params.plot = 0 --> no plot during fit iteration
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 % - params.plot = 1 --> plot results at each fitting steps. default
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 % value.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 % - params.ctp = 'chival' --> check if the value of the Mean Squared
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 % Error is lower than 10^(-1*lsrcond).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 % - params.ctp = 'chivar' --> check if the value of the Mean Squared
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 % Error is lower than 10^(-1*lsrcond) and if the relative variation of mean
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 % squared error is lower than 10^(-1*msevar).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 % - params.ctp = 'lrs' --> check if the log difference between data and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 % residuals is point by point larger than the value indicated in
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 % lsrcond. This mean that residuals are lsrcond order of magnitudes
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 % lower than data.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 % - params.ctp = 'lrsmse' --> check if the log difference between data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 % and residuals is larger than the value indicated in lsrcond and if
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 % the relative variation of mean squared error is lower than
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 % 10^(-1*msevar).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 % - params.lrscond = # --> set conditioning value for point to point
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 % log residuals difference (params.ctp = 'lsr') and mean log residual
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 % difference (params.ctp = 'mlsrvar'). Default is 2. See help for
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 % stopfit.m for further remarks.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 % - params.msevar = # --> set conditioning value for root mean squared
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 % error variation. This allow to check that the relative variation of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 % mean squared error is lower than 10^(-1*msevar).Default is 7. See
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 % help for stopfit.m for further remarks.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 % - params.fs set the sampling frequency (Hz) useful for z-domain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 % identification. Default is 1 Hz
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 % - params.usesym = 0 perform double-precision calculation in the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 % eigendecomposition procedure to identify 2dim systems and for poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 % stabilization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 % - params.usesym = 1 uses symbolic math toolbox variable precision
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 % arithmetic in the eigendecomposition for 2dim system identification
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 % double-precison for poles stabilization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 % - params.usesym = 2 uses symbolic math toolbox variable precision
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 % arithmetic in the eigendecomposition for 2dim system identification
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 % and for poles stabilization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 % - params.dig = # set the digit precision required for variable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 % precision arithmetic calculations. Default is 50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 % params.dterm = 0 --> Try to fit without direct term
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 % params.dterm = 1 --> Try to fit with and without direct term
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 % params.spy = 0 --> Do not display the iteration progression
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 % params.spy = 1 --> Display the iteration progression
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 % OUTPUT:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 % One Dimensional System
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 % - res is the vector of residues.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 % - poles is the vector of poles.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 % - dterm is the direct term (if present).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 % - mresp is the model frequency response.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 % - rdl is the vector of residuals calculated as y - mresp.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 % Two Dimensional System
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 % - ostruct is a structure array with five fields and four elements.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 % Element 1 correspond to tf11 data, element 2 to tf12 data, element 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 % to tf21 data and elemnt 4 to tf22 data.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 % - ostruct(n).res --> is the vector of residues.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 % - ostruct(n).poles --> is the vector of poles.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 % - ostruct(n).dterm --> are the tfs direct terms.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 % - ostruct(n).mresp --> are the tfs models freq. responses.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 % - ostruct(n).rdl --> are the residuals vectors.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 % VERSION: $Id: psd2tf.m,v 1.19 2010/05/03 18:07:02 luigi Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 % HISTORY: 02-10-2008 L Ferraioli
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 % Creation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 function varargout = psd2tf(csd11,csd12,csd21,csd22,f,params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 utils.helper.msg(utils.const.msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 % Collect inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 % Default input struct
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 defaultparams = struct('idtp',1, 'Nmaxiter',50, 'minorder',2,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 'maxorder',25, 'spolesopt',2, 'weightparam',1, 'plot',0,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199 'ctp','chival','lrscond',2,'msevar',2,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 'fs',1, 'usesym',0, 'dig',50, 'dterm',0, 'spy',0, 'fullauto',1,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 'extweights', []);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 names = {'idtp','Nmaxiter','minorder','maxorder','spolesopt',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 'weightparam','plot','stopfitcond',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 'ctp','lrscond','msevar',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 'fs','usesym','dig','dterm','spy','fullauto','extweights'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 % collecting input and default params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 if ~isempty(params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 for jj=1:length(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 if isfield(params, names(jj)) && ~isempty(params.(names{1,jj}))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 defaultparams.(names{1,jj}) = params.(names{1,jj});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 % default values for input variables
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 idtp = defaultparams.idtp; % identification type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 Nmaxiter = defaultparams.Nmaxiter; % Number of max iteration in the fitting loop
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 minorder = defaultparams.minorder; % Minimum model order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 maxorder = defaultparams.maxorder; % Maximum model order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 spolesopt = defaultparams.spolesopt; % 0, Fit with no complex starting poles (complex poles can be found as fit output). 1 fit with comples starting poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 weightparam = defaultparams.weightparam; % Weight 1./abs(y). Admitted values are 0, 1, 2, 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 checking = defaultparams.plot; % Never polt. Admitted values are 0 (No polt ever), 1 (plot at the end), 2 (plot at each step)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 ctp = defaultparams.ctp;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 lrscond = defaultparams.lrscond;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 msevar = defaultparams.msevar;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 fs = defaultparams.fs; % sampling frequency
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 usesym = defaultparams.usesym; % method of calculation for the 2dim tfs calculation from psd
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 dig = defaultparams.dig; % number of digits if VPA calculation is required
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 idt = defaultparams.dterm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 spy = defaultparams.spy;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 autosearch = defaultparams.fullauto;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 extweights = defaultparams.extweights;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 % rescaling input models to get correct results
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 csd11 = csd11.*(fs/2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 csd12 = csd12.*(fs/2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 csd21 = csd21.*(fs/2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 csd22 = csd22.*(fs/2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 % Assign proper values to the control variables for symbolic calculations
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 switch usesym
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 case 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 eigsym = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 allsym = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 case 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 eigsym = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 allsym = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 case 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 eigsym = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 allsym = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 % Checking inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 [a,b] = size(csd11);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 if a < b % shifting to column
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 csd11 = csd11.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 if isempty(csd12)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 csd12 = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 [a,b] = size(csd12);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 if a < b % shifting to column
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 csd12 = csd12.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 if isempty(csd21)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 csd21 = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 [a,b] = size(csd21);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 if a < b % shifting to column
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 csd21 = csd21.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 [a,b] = size(csd22);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 if a < b % shifting to column
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 csd22 = csd22.';
|
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 [a,b] = size(f);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 if a < b % shifting to column
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 f = f.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 % Importing package
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293 import utils.math.*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 % switching between inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 clear dim
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 % cecking for empty csd or psd2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 if all([isempty(csd12) isempty(csd21) isempty(csd22)])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 dim = '1dim';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 utils.helper.msg(utils.const.msg.PROC1, ' Empty csd12, csd21 and csd22; Performing one dimesional identification on psd ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 dim ='2dim';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 utils.helper.msg(utils.const.msg.PROC1, ' Performing two dimesional identification on csd11, csd12, csd21 and csd22 ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 switch dim
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 case '1dim'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 % switching between continuous and discrete type identification
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 switch idtp
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312 case 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313 utils.helper.msg(utils.const.msg.PROC1, ' Performing s-domain identification, s-domain output ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314 itf = abs(sqrt(csd11)); % input data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316 % in case of externally provided weights
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 if ~isempty(extweights)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318 extweights = abs(extweights.*csd11./itf);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
319 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
320
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
321 % Fitting params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 params = struct('spolesopt',spolesopt, 'Nmaxiter',Nmaxiter, 'minorder',minorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 'maxorder',maxorder, 'weightparam',weightparam, 'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 'stabfit',0,'dterm',idt,'spy',spy,'fullauto',autosearch,'extweights',extweights);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328 utils.helper.msg(utils.const.msg.PROC1, ' Fitting absolute TF value with unstable model ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
329 [res,poles,dterm,mresp,rdl,mse] = utils.math.autocfit(itf,f,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
330
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
331 % all pass filtering for poles stabilization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
332 if allsym
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
333 [nr,np,nd,ntf] = utils.math.pfallpsyms(res,poles,dterm,mresp,f);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
334 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
335 [ntf,np] = utils.math.pfallps(res,poles,dterm,mresp,f,false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
336 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
337
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
338 % Fitting params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
339 params = struct('spolesopt',0,'extpoles', np,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
340 'Nmaxiter',Nmaxiter,'minorder',minorder,'maxorder',maxorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
341 'weightparam',weightparam,'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
342 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
343 'stabfit',1,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
344 'dterm',idt,'spy',spy,'fullauto',autosearch,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
345 'extweights',extweights);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
346
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
347 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
348 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF with stable model ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
349 [res,poles,dterm,mresp,rdl,mse] = utils.math.autocfit(ntf,f,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
350
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
351 % Output data switching between output type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
352 utils.helper.msg(utils.const.msg.PROC1, ' Output continuous model ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
353 if nargout == 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
354 varargout{1} = res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
355 varargout{2} = poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
356 varargout{3} = dterm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
357 elseif nargout == 4
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
358 varargout{1} = res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
359 varargout{2} = poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
360 varargout{3} = dterm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
361 varargout{4} = mresp;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
362 elseif nargout == 5
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
363 rdl = itf - abs(mresp); % residual respect to original function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
364
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
365 varargout{1} = res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
366 varargout{2} = poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
367 varargout{3} = dterm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
368 varargout{4} = mresp;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
369 varargout{5} = rdl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
370
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
371 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
372 error(' Unespected number of output. Set 3, 4 or 5! ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
373 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
374
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
375 case 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
376 utils.helper.msg(utils.const.msg.PROC1, ' Performing z-domain identification ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
377 itf = abs(sqrt(csd11)); % input data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
378
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
379 % in case of externally provided weights
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
380 if ~isempty(extweights)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
381 extweights = abs(extweights.*csd11./itf);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
382 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
383
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
384 % Fitting params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
385 params = struct('spolesopt',spolesopt, 'Nmaxiter',Nmaxiter, 'minorder',minorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
386 'maxorder',maxorder, 'weightparam',weightparam, 'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
387 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
388 'stabfit',0,'dterm',idt,'spy',spy,'fullauto',autosearch,'extweights',extweights);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
389
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
390 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
391 utils.helper.msg(utils.const.msg.PROC1, ' Fitting absolute TF value with unstable model ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
392 [res,poles,dterm,mresp,rdl,mse] = utils.math.autodfit(itf,f,fs,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
393
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
394 % all pass filtering for poles stabilization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
395 if allsym
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
396 [nr,np,nd,ntf] = utils.math.pfallpsymz(res,poles,dterm,mresp,f,fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
397 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
398 [ntf,np] = utils.math.pfallpz(res,poles,dterm,mresp,f,fs,false);
|
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 params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
402 params = struct('spolesopt',0,'extpoles', np,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
403 'Nmaxiter',Nmaxiter,'minorder',minorder,'maxorder',maxorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
404 'weightparam',weightparam,'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
405 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
406 'stabfit',1,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
407 'dterm',idt,'spy',spy,'fullauto',autosearch,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
408 'extweights',extweights);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
409
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
410 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF with stable model ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
411 [res,poles,dterm,mresp,rdl,mse] = utils.math.autodfit(ntf,f,fs,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
412
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
413 % Output data switching between output type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
414 utils.helper.msg(utils.const.msg.PROC1, ' Output z-domain model ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
415 if nargout == 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
416 varargout{1} = res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
417 varargout{2} = poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
418 varargout{3} = dterm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
419 elseif nargout == 4
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
420 varargout{1} = res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
421 varargout{2} = poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
422 varargout{3} = dterm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
423 varargout{4} = mresp;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
424 elseif nargout == 5
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
425
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
426 rdl = itf - abs(mresp); % residual respect to original function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
427
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
428 varargout{1} = res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
429 varargout{2} = poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
430 varargout{3} = dterm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
431 varargout{4} = mresp;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
432 varargout{5} = rdl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
433
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
434 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
435 error(' Unespected number of output. Set 3, 4 or 5! ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
436 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
437
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
438 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
439
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
440 case '2dim'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
441 % switching between continuous and discrete type identification
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
442 switch idtp
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
443 case 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
444 utils.helper.msg(utils.const.msg.PROC1, ' Performing s-domain identification on 2dim system, s-domain output ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
445 [tf11,tf12,tf21,tf22] = utils.math.eigcsd(csd11,csd12,csd21,csd22,'USESYM',eigsym,'DIG',dig,'OTP','TF'); % input data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
446
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
447 % Shifting to columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
448 [a,b] = size(tf11);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
449 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
450 tf11 = tf11.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
451 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
452 [a,b] = size(tf12);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
453 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
454 tf12 = tf12.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
455 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
456 [a,b] = size(tf21);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
457 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
458 tf21 = tf21.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
459 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
460 [a,b] = size(tf22);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
461 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
462 tf22 = tf22.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
463 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
464
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
465 % Collecting tfs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
466 f1 = [tf11 tf21];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
467 f2 = [tf12 tf22];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
468
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
469 % get external weights
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
470 if ~isempty(extweights)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
471 % willing to work with columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
472 [a,b] = size(extweights);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
473 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
474 extweights = extweights.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
475 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
476 wobj1 = [extweights(:,1).*abs(csd11./tf11) extweights(:,3).*abs(csd21./tf21)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
477 wobj2 = [extweights(:,2).*abs(csd12./tf12) extweights(:,4).*abs(csd22./tf22)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
478 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
479 wobj1 = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
480 wobj2 = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
481 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
482
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
483 % Fitting with unstable poles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
484
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
485 % Fitting params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
486 params = struct('spolesopt',spolesopt, 'Nmaxiter',Nmaxiter, 'minorder',minorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
487 'maxorder',maxorder, 'weightparam',weightparam, 'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
488 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
489 'stabfit',0,'dterm',idt,'spy',spy,'fullauto',autosearch,'extweights',wobj1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
490
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
491 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
492 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF11 and TF21 with unstable common poles ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
493 [res1,poles1,dterm1,mresp1,rdl1,mse1] = utils.math.autocfit(f1,f,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
494
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
495 params = struct('spolesopt',spolesopt, 'Nmaxiter',Nmaxiter, 'minorder',minorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
496 'maxorder',maxorder, 'weightparam',weightparam, 'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
497 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
498 'stabfit',0,'dterm',idt,'spy',spy,'fullauto',autosearch,'extweights',wobj2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
499
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
500 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF12 and TF22 with unstable common poles ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
501 [res2,poles2,dterm2,mresp2,rdl2,mse2] = utils.math.autocfit(f2,f,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
502
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
503 % Poles stabilization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
504 if allsym
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
505 utils.helper.msg(utils.const.msg.PROC1, ' All pass filtering of TF11 and TF21, symbolic calc... ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
506 [nr1,np1,nd1,nf1] = utils.math.pfallpsyms(res1,poles1,dterm1,mresp1,f);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
507 np1 = np1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
508 utils.helper.msg(utils.const.msg.PROC1, ' All pass filtering of TF12 and TF22, symbolic calc... ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
509 [nr2,np2,nd2,nf2] = utils.math.pfallpsyms(res2,poles2,dterm2,mresp2,f);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
510 np2 = np2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
511 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
512 utils.helper.msg(utils.const.msg.PROC1, ' All pass filtering of TF11 and TF21 ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
513 [nf1,np1] = utils.math.pfallps(res1,poles1,dterm1,mresp1,f,false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
514 np1 = np1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
515 utils.helper.msg(utils.const.msg.PROC1, ' All pass filtering of TF12 and TF22 ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
516 [nf2,np2] = utils.math.pfallps(res2,poles2,dterm2,mresp2,f,false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
517 np2 = np2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
518 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
519
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
520 % Fitting with stable poles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
521
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
522 % Fitting stable TF11 and TF21 with stable poles in s-domain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
523 % Fitting params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
524 params = struct('spolesopt',0,'Nmaxiter',Nmaxiter,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
525 'minorder',minorder,'maxorder',maxorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
526 'weightparam',weightparam,'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
527 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
528 'stabfit',1,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
529 'dterm',idt,'spy',spy,'fullauto',autosearch,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
530 'extweights',wobj1,'extpoles', np1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
531
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
532 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
533 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF11 and TF21 with stable common poles ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
534 [res1,poles1,dterm1,mresp1,rdl1,mse1] = utils.math.autocfit(nf1,f,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
535
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
536 % Fitting stable TF12 and TF22 with stable poles in s-domain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
537 % Fitting params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
538 params = struct('spolesopt',0,'Nmaxiter',Nmaxiter,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
539 'minorder',minorder,'maxorder',maxorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
540 'weightparam',weightparam,'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
541 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
542 'stabfit',1,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
543 'dterm',idt,'spy',spy,'fullauto',autosearch,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
544 'extweights',wobj2,'extpoles', np2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
545
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
546 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
547 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF12 and TF22 with stable common poles ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
548 [res2,poles2,dterm2,mresp2,rdl2,mse2] = utils.math.autocfit(nf2,f,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
549
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
550 % Output stable model %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
551 ostruct = struct();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
552
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
553 % Data for tf11
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
554 ostruct(1).res = res1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
555 ostruct(1).poles = poles1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
556 ostruct(1).dterm = dterm1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
557 ostruct(1).mresp = mresp1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
558 ostruct(1).rdl = rdl1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
559
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
560 % Data for tf12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
561 ostruct(2).res = res2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
562 ostruct(2).poles = poles2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
563 ostruct(2).dterm = dterm2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
564 ostruct(2).mresp = mresp2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
565 ostruct(2).rdl = rdl2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
566
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
567 % Data for tf21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
568 ostruct(3).res = res1(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
569 ostruct(3).poles = poles1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
570 ostruct(3).dterm = dterm1(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
571 ostruct(3).mresp = mresp1(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
572 ostruct(3).rdl = rdl1(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
573
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
574 % Data for tf22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
575 ostruct(4).res = res2(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
576 ostruct(4).poles = poles2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
577 ostruct(4).dterm = dterm2(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
578 ostruct(4).mresp = mresp2(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
579 ostruct(4).rdl = rdl2(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
580
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
581 % Output data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
582 utils.helper.msg(utils.const.msg.PROC1, ' Output continuous models ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
583 if nargout == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
584 varargout{1} = ostruct;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
585 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
586 error(' Unespected number of output. Set 1! ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
587 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
588
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
589 case 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
590 utils.helper.msg(utils.const.msg.PROC1, ' Performing z-domain identification on 2dim system, z-domain output ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
591 [tf11,tf12,tf21,tf22] = utils.math.eigcsd(csd11,csd12,csd21,csd22,'USESYM',eigsym,'DIG',dig,'OTP','TF'); % input data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
592
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
593 % Shifting to columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
594 [a,b] = size(tf11);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
595 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
596 tf11 = tf11.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
597 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
598 [a,b] = size(tf12);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
599 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
600 tf12 = tf12.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
601 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
602 [a,b] = size(tf21);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
603 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
604 tf21 = tf21.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
605 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
606 [a,b] = size(tf22);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
607 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
608 tf22 = tf22.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
609 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
610
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
611 % Collecting tfs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
612 f1 = [tf11 tf21];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
613 f2 = [tf12 tf22];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
614
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
615 % get external weights
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
616 if ~isempty(extweights)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
617 % willing to work with columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
618 [a,b] = size(extweights);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
619 if a<b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
620 extweights = extweights.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
621 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
622 wobj1 = [extweights(:,1).*abs(csd11./tf11) extweights(:,3).*abs(csd21./tf21)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
623 wobj2 = [extweights(:,2).*abs(csd12./tf12) extweights(:,4).*abs(csd22./tf22)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
624 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
625 wobj1 = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
626 wobj2 = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
627 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
628
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
629 % Fitting with unstable poles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
630 params = struct('spolesopt',spolesopt, 'Nmaxiter',Nmaxiter, 'minorder',minorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
631 'maxorder',maxorder, 'weightparam',weightparam, 'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
632 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
633 'stabfit',0,'dterm',idt,'spy',spy,'fullauto',autosearch,'extweights',wobj1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
634
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
635 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
636 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF11 and TF21 with unstable common poles ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
637 [res1,poles1,dterm1,mresp1,rdl1,mse1] = utils.math.autodfit(f1,f,fs,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
638
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
639 params = struct('spolesopt',spolesopt, 'Nmaxiter',Nmaxiter, 'minorder',minorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
640 'maxorder',maxorder, 'weightparam',weightparam, 'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
641 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
642 'stabfit',0,'dterm',idt,'spy',spy,'fullauto',autosearch,'extweights',wobj2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
643
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
644 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF12 and TF22 with unstable common poles ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
645 [res2,poles2,dterm2,mresp2,rdl2,mse2] = utils.math.autodfit(f2,f,fs,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
646
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
647 % Poles stabilization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
648 if allsym
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
649 utils.helper.msg(utils.const.msg.PROC1, ' All pass filtering of TF11 and TF21, symbolic calc... ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
650 [nr1,np1,nd1,nf1] = utils.math.pfallpsymz(res1,poles1,dterm1,mresp1,f,fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
651 np1 = np1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
652 utils.helper.msg(utils.const.msg.PROC1, ' All pass filtering of TF12 and TF22, symbolic calc... ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
653 [nr2,np2,nd2,nf2] = utils.math.pfallpsymz(res2,poles2,dterm2,mresp2,f,fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
654 np2 = np2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
655 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
656 utils.helper.msg(utils.const.msg.PROC1, ' All pass filtering of TF11 and TF21 ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
657 [nf1,np1] = utils.math.pfallpz(res1,poles1,dterm1,mresp1,f,fs,false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
658 np1 = np1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
659 utils.helper.msg(utils.const.msg.PROC1, ' All pass filtering of TF12 and TF22 ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
660 [nf2,np2] = utils.math.pfallpz(res2,poles2,dterm2,mresp2,f,fs,false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
661 np2 = np2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
662 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
663
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
664 % Fitting with stable poles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
665
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
666 % Fitting stable TF11 and TF21 with stable poles in z-domain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
667 % Fitting params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
668 params = struct('spolesopt',0,'Nmaxiter',Nmaxiter,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
669 'minorder',minorder,'maxorder',maxorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
670 'weightparam',weightparam,'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
671 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
672 'stabfit',1,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
673 'dterm',idt,'spy',spy,'fullauto',autosearch,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
674 'extweights',wobj1,'extpoles', np1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
675
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
676 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
677 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF11 and TF21 with stable common poles ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
678 [res1,poles1,dterm1,mresp1,rdl1,mse1] = utils.math.autodfit(nf1,f,fs,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
679
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
680 % Fitting stable TF12 and TF22 with stable poles in z-domain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
681 % Fitting params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
682 params = struct('spolesopt',0,'Nmaxiter',Nmaxiter,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
683 'minorder',minorder,'maxorder',maxorder,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
684 'weightparam',weightparam,'plot',checking,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
685 'ctp',ctp,'lrscond',lrscond,'msevar',msevar,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
686 'stabfit',1,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
687 'dterm',idt,'spy',spy,'fullauto',autosearch,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
688 'extweights',wobj2,'extpoles', np2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
689
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
690 % Fitting
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
691 utils.helper.msg(utils.const.msg.PROC1, ' Fitting TF12 and TF22 with stable common poles ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
692 [res2,poles2,dterm2,mresp2,rdl2,mse2] = utils.math.autodfit(nf2,f,fs,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
693
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
694 % Output stable model %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
695 ostruct = struct();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
696
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
697 % Data for tf11
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
698 ostruct(1).res = res1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
699 ostruct(1).poles = poles1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
700 ostruct(1).dterm = dterm1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
701 ostruct(1).mresp = mresp1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
702 ostruct(1).rdl = rdl1(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
703
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
704 % Data for tf12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
705 ostruct(2).res = res2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
706 ostruct(2).poles = poles2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
707 ostruct(2).dterm = dterm2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
708 ostruct(2).mresp = mresp2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
709 ostruct(2).rdl = rdl2(:,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
710
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
711 % Data for tf21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
712 ostruct(3).res = res1(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
713 ostruct(3).poles = poles1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
714 ostruct(3).dterm = dterm1(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
715 ostruct(3).mresp = mresp1(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
716 ostruct(3).rdl = rdl1(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
717
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
718 % Data for tf22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
719 ostruct(4).res = res2(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
720 ostruct(4).poles = poles2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
721 ostruct(4).dterm = dterm2(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
722 ostruct(4).mresp = mresp2(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
723 ostruct(4).rdl = rdl2(:,2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
724
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
725 % Output data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
726 utils.helper.msg(utils.const.msg.PROC1, ' Output discrete models ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
727 if nargout == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
728 varargout{1} = ostruct;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
729 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
730 error(' Unespected number of output. Set 1! ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
731 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
732
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
733 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
734 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
735
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
736 % END %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|