0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % Training session Topic 5 exercise 02
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % System identification in z-domain 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % 1) Load fsdata object from file
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % 2) Fit loaded TF data with zDomainFit and fixed order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % 3) Compare results
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % L FERRAIOLI 22-02-09
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % $Id: TrainigSession_T5_Ex02.m,v 1.3 2009/02/25 18:18:45 luigi Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 %% 1) load fsdata
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % load AO from file
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 rfilt = ao(plist('filename', 'topic5\T5_Ex02_rfilt.xml'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 iplot(rfilt)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 %% 2) Fitting TF - fixed model order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % Loaded fsdata are the response of an order 19 partial fractioned filter.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % We now try to fitting the loaded filter response with zDomainFit with a
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % fixed model order.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % We set Autosearch to off, in this case the function do not perform
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % accuracy test but simply run how far maximum number of iteration is
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % reached. Model order is fixed by minorder parameter.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 plfit1 = plist('FS',10,... % Sampling frequency for the model filters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 'AutoSearch','off',... % Automatically search for a good model
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 'StartPolesOpt','c1',... % Define the properties of the starting poles - complex distributed in the unitary circle
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 'maxiter',30,... % maximum number of iteration per model order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 'minorder',19,... % fixed model order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 'weightparam','abs',... % assign weights as 1./abs(data)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 'Plot','on',... % set the plot on or off
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 'ForceStability','on',... % force to output a stable ploes model
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 'CheckProgress','off'); % display fitting progress on the command window
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 % Do the fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 fobj = zDomainFit(rfilt,plfit1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 % setting input and output units for fitted model
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 %% 3) Compare results
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 % Extracting residues and poles from fit results
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 fRes = zeros(numel(fobj),1); % fit residue vector initialization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 fPoles = zeros(numel(fobj),1); % fit poles vector initialization
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 % extracting data from fitted filters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 for ii = 1:numel(fobj)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 fRes(ii,1) = fobj(ii).a(1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 fPoles(ii,1) = -1*fobj(ii).b(2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 [fRes,idx] = sort(fRes);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 fPoles = fPoles(idx);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 % starting model residues and poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 mRes = [2.44554138162509e-011 - 1.79482547894083e-011i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 2.44554138162509e-011 + 1.79482547894083e-011i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 2.66402334803101e-009 + 1.1025122049153e-009i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 2.66402334803101e-009 - 1.1025122049153e-009i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 -7.3560293387644e-009;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 -1.82811618589835e-009 - 1.21803627800855e-009i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 -1.82811618589835e-009 + 1.21803627800855e-009i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 1.16258677367555e-009;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 1.65216557639319e-016;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 -1.78092396888606e-016;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 -2.80420398962379e-017;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 9.21305973049041e-013 - 8.24686706827269e-014i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 9.21305973049041e-013 + 8.24686706827269e-014i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 5.10730060739905e-010 - 3.76571756625722e-011i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 5.10730060739905e-010 + 3.76571756625722e-011i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 3.45893698149735e-009;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 3.98139182134446e-014 - 8.25503935419059e-014i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 3.98139182134446e-014 + 8.25503935419059e-014i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 -1.40595719147164e-011];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 [mRes,idx] = sort(mRes);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 mPoles = [0.843464045655194 - 0.0959986292915475i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 0.843464045655194 + 0.0959986292915475i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 0.953187595424927 - 0.0190043625473383i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 0.953187595424927 + 0.0190043625473383i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 0.967176277937188;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 0.995012027005247 - 0.00268322602801729i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 0.995012027005247 + 0.00268322602801729i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 0.996564761885673;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 0.999999366165445;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 0.999981722418555;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 0.999921882627659;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 0.999624431675213 - 0.000813407848742761i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 0.999624431675213 + 0.000813407848742761i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 0.997312006278751 - 0.00265611346834941i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 0.997312006278751 + 0.00265611346834941i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 0.990516544257531;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 0.477796923118318 - 0.311064085401834i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 0.477796923118318 + 0.311064085401834i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 0];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 mPoles = mPoles(idx);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % Check the relative difference
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 (mRes-fRes)./abs(mRes)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 (mPoles-fPoles)./abs(mPoles)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 % Results are accurate to the 7th decimal digit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105
|