0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % GETINITSTATE
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % DESCRIPTION:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % Initialize filters for noise generation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % CALL:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % INPUT:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % - res
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % - poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % - S0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % OUTPUT:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % Zi
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % REFERENCES:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % HISTORY: 23-04-2009 L Ferraioli
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % Creation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % VERSION: $Id: ndeigcsd.m,v 1.2 2009/06/10 16:15:32 luigi Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 function Zi = getinitstate(res,poles,S0,varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % default value for the method used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 mtd = 'svd';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 if ~isempty(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 for j=1:length(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 if strcmpi(varargin{j},'mtd')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 mtd = lower(varargin{j+1});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 % get problem dimesionality, it is assumed that res for a given filter are
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % input as columns and that each different filter has the same number of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 % residues and poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 [rw,cl] = size(res);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 N = numel(res(:,1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 % check size
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 if cl == 1 % one dimensional
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 A = res(:);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 p = poles(:);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 % Marking complex and real poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 % cindex = 1; pole is complex, next conjugate pole is marked with cindex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 % = 2. cindex = 0; pole is real
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 cindex=zeros(numel(p),1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 for mm=1:numel(p)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 if imag(p(mm))~=0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 if mm==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 cindex(mm)=1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 if cindex(mm-1)==0 || cindex(mm-1)==2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 cindex(mm)=1; cindex(mm+1)=2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 cindex(mm)=2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 NA = numel(A);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 % Build covariance matrix for filter states
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 H = zeros(NA);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 for aa = 1:NA
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 for bb = 1:NA
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 H(aa,bb) = (p(aa)*conj(p(bb))*A(aa)*conj(A(bb))*S0)/(1-p(aa)*conj(p(bb)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % avoiding problems caused by roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 HH = triu(H,0); % get upper triangular part of H
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 HH1 = triu(H,1); % get upper triangular part of H above principal diagonal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 HH2 = HH1'; % do transpose conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 H = HH + HH2; % reconstruct H in order to be really hermitian
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 % switch between methods
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 switch mtd
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 case 'svd'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % get decomposition of Hr
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 [U,S,V] = svd(H,0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % output initial states for gaussian data series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 ZZ = V*(sqrt(diag(S)).*randn(N,1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % cleaning up results for numerical approximations
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 idx = imag(poles(:,1))==0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 ZZ(idx) = real(ZZ(idx));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 % cleaning up results for numerical roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 % states associated to complex conjugate poles must be complex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 % conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 for jj = 1:numel(ZZ)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 if cindex(jj)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 ZZ(jj+1) = conj(ZZ(jj));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 case 'mvnorm'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 ZZ = mvnrnd(zeros(N,1),H,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 % willing to work with columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 if size(ZZ,2)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 ZZ = ZZ.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 if imag(ZZ(1))~=0 && imag(p(1))==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 % flip
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 ZZ = flipud(ZZ);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 % cleaning up results for numerical roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 % states associated to complex conjugate poles must be complex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 % conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 for jj = 1:numel(ZZ)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 if cindex(jj)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 ZZ(jj+1) = conj(ZZ(jj));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 else % cl dmensional
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 % join residues and poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 A = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 p = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 pdim = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 for ii=1:cl
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 % Join poles and residues as a single column
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 A = [A; res(:,ii)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 p = [p; poles(:,ii)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 pdim = [pdim; numel(poles(:,ii))];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 % Marking complex and real poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 % cindex = 1; pole is complex, next conjugate pole is marked with cindex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 % = 2. cindex = 0; pole is real
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 cindex=zeros(numel(p),1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 for mm=1:numel(p)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 if imag(p(mm))~=0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 if mm==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 cindex(mm)=1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 if cindex(mm-1)==0 || cindex(mm-1)==2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 cindex(mm)=1; cindex(mm+1)=2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 cindex(mm)=2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 % sanity check, search if poles are equals
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 eqpoles = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 if ~all(logical(diff(pdim))) % is executed if the elements of pdim are equal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 % compare poles series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 for ii=2:cl
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 if all((poles(:,ii)-poles(:,ii-1))<eps)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 eqpoles = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 if ~eqpoles % poles are different
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 NA = numel(A);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 % Build covariance matrix for filter states
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 H = zeros(NA);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 for aa = 1:NA
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 for bb = 1:NA
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 H(aa,bb) = (p(aa)*conj(p(bb))*A(aa)*conj(A(bb))*S0)/(1-p(aa)*conj(p(bb)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 % avoiding problems caused by roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 HH = triu(H,0); % get upper triangular part of H
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 HH1 = triu(H,1); % get upper triangular part of H above principal diagonal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 HH2 = HH1'; % do transpose conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 H = HH + HH2; % reconstruct H in order to be really hermitian
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 % get full rank H
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 [U,S,V] = svd(H,0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 % reducing size
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 Ur = U(1:N,1:N);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 Sr = S(1:N,1:N);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 Vr = V(1:N,1:N);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 % New full rank covariance
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 Hr = Vr*Sr*Vr';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 % avoiding problems caused by roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 HH = triu(Hr,0); % get upper triangular part of H
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 HH1 = triu(Hr,1); % get upper triangular part of H above principal diagonal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 HH2 = HH1'; % do transpose conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 Hr = HH + HH2; % reconstruct H in order to be really hermitian
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 % switch between methods
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 switch mtd
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 case 'svd'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 % get decomposition of Hr
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 [UU,SS,VV] = svd(Hr,0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 % output initial states for gaussian data series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 ZZ = VV*(sqrt(diag(SS)).*randn(N,1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 % cleaning up results for numerical roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 idx = imag(p)==0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 ZZ(idx) = real(ZZ(idx));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 % cleaning up results for numerical roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 % states associated to complex conjugate poles must be complex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 % conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 for jj = 1:numel(ZZ)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 if cindex(jj)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 ZZ(jj+1) = conj(ZZ(jj));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 case 'mvnorm'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 ZZ = mvnrnd(zeros(N,1),Hr,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 % willing to work with columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 if size(ZZ,2)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 ZZ = ZZ.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 if imag(ZZ(1))~=0 && imag(p(1))==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 % flip
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 ZZ = flipud(ZZ);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 % cleaning up results for numerical roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 % states associated to complex conjugate poles must be complex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 % conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 for jj = 1:numel(ZZ)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 if cindex(jj)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 ZZ(jj+1) = conj(ZZ(jj));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 else % poles are in common
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 NA = numel(A);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 % Build block diagonal covariance matrix for filter states
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 H = zeros(NA);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 for ii = 1:numel(pdim)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 for aa = 1+(ii-1)*pdim(ii):(ii-1)*pdim(ii)+pdim(ii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 for bb = 1+(ii-1)*pdim(ii):(ii-1)*pdim(ii)+pdim(ii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 H(aa,bb) = (p(aa)*conj(p(bb))*A(aa)*conj(A(bb))*S0)/(1-p(aa)*conj(p(bb)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 % avoiding problems caused by roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 HH = triu(H,0); % get upper triangular part of H
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 HH1 = triu(H,1); % get upper triangular part of H above principal diagonal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 HH2 = HH1'; % do transpose conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 H = HH + HH2; % reconstruct H in order to be really hermitian
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 % switch between methods
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 switch mtd
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 case 'svd'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285 % get decomposition of Hr
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 [UU,SS,VV] = svd(H,0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 % output initial states for gaussian data series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 rd = randn(N,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 rdv = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 for jj = 1:numel(pdim);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 rdv = [rdv; rd];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293 ZZ = VV*(sqrt(diag(SS)).*rdv);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 % cleaning up results for numerical roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 idx = imag(p)==0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297 ZZ(idx) = real(ZZ(idx));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 % cleaning up results for numerical roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 % states associated to complex conjugate poles must be complex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 % conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 for jj = 1:numel(ZZ)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303 if cindex(jj)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 ZZ(jj+1) = conj(ZZ(jj));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 end
|
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
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 case 'mvnorm'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 ZZ = mvnrnd(zeros(N,1),H,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312 % willing to work with columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313 if size(ZZ,2)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314 ZZ = ZZ.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316 if imag(ZZ(1))~=0 && imag(p(1))==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 % flip
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318 ZZ = flipud(ZZ);
|
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 % cleaning up results for numerical roundoff errors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 % states associated to complex conjugate poles must be complex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 % conjugate
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324 for jj = 1:numel(ZZ)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 if cindex(jj)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326 ZZ(jj+1) = conj(ZZ(jj));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
329
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
330 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
331
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
332 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
333
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
334 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
335
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
336 Zi = ZZ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
337
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
338 end |