0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % FROMCSD Construct a matrix filter from cross-spectral density matrix
|
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 % FUNCTION: fromCSD
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % DESCRIPTION: Construct matrix filter from cross-spectral density. Such a
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % filter can be used for multichannel noise generation in combination with
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % the MultiChannelNoise constructor of the matrix class.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % CALL: a = fromCSD(a, pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % PARAMETER: pl: plist containing 'csd'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 function a = fromCSD(a, pli)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 VERSION = '$Id: fromCSD.m,v 1.8 2010/10/29 16:09:12 ingo Exp $';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % get AO info
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 iobj = matrix.getInfo('matrix', 'From CSD');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % Set the method version string in the minfo object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 iobj.setMversion([VERSION '-->' iobj.mversion]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % Add default values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 pl = parse(pli, iobj.plists);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % Get parameters and set params for fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 csdm = find(pl, 'csd');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 if isa(csdm,'matrix') % get elements out of the input matrix
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 csdao = csdm.objs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 csdao = csdm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 fs = find(pl, 'fs');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 target = lower(find(pl, 'targetobj')); % decide to perform s domain or z domain identification
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 % if target is parfrac output a matrix of parfarc objs (s domain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 % identification)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % if target is miir output a matrix of filterbank parallel miir objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 % (z domain identification)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 usesym = lower(find(pl, 'UseSym'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 if (fs == 0) && strcmpi(target,'miir')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 error('### Please provide a valid sampling frequency for CSD constructor.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 elseif isempty(fs) && strcmpi(target,'miir')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 error('### Please provide a valid sampling frequency for CSD constructor.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 % get units for filters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 tgiunit = find(pl,'iunits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 tgounit = find(pl,'ounits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 params = struct();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 params.Nmaxiter = find(pl, 'MaxIter');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 params.minorder = find(pl, 'MinOrder');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 params.maxorder = find(pl, 'MaxOrder');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 params.spolesopt = find(pl, 'PoleType');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 params.weightparam = find(pl, 'Weights');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 % set the target output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 if strcmpi(target,'miir')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 params.TargetDomain = 'z';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 elseif strcmpi(target,'parfrac')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 params.TargetDomain = 's';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 error('### Unknown option for ''targetobj''.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 % Tolerance for MSE Value
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 lrscond = find(pl, 'FITTOL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 % give an error for strange values of lrscond
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 if lrscond<0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 error('### Negative values for FITTOL are not allowed. ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 % handling data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 lrscond = -1*log10(lrscond);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % give a warning for strange values of lrscond
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 if lrscond<0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 warning('You are searching for a MSE lower than %s', num2str(10^(-1*lrscond)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 params.lrscond = lrscond;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % Tolerance for the MSE relative variation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 msevar = find(pl, 'MSEVARTOL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 % handling data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 msevar = -1*log10(msevar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 % give a warning for strange values of msevar
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 if msevar<0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 warning('You are searching for MSE relative variation lower than %s', num2str(10^(-1*msevar)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 params.msevar = msevar;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 if isempty(params.msevar)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 params.ctp = 'chival';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 params.ctp = 'chivar';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 if(find(pl, 'plot'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 params.plot = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 params.plot = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 params.fs = fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 params.dterm = 0; % it is better to fit without direct term
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 % check if symbolic calculation is required
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 if strcmpi(usesym,'on')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 params.usesym = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 elseif strcmpi(usesym,'off')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 params.usesym = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 error('### Unknown option for ''UseSym''.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 % extracting csd
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 if numel(csdao)==1 % one dimensional psd
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 csd = csdao.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 freq = csdao.x;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 dim = 'one';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 else % multichannel system
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 dim = 'multi';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 [nn,mm] = size(csdao);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 if nn~=mm
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 error('### CSD Matrix must be square. ')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 freq = csdao.index(1).x;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 for ii = 1:nn
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 for jj = 1:nn
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 tcsd = csdao.index(ii,jj).y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 % willing to work with columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 [aa,bb] = size(tcsd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 if aa<bb
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 tcsd = tcsd.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 csd(ii,jj,:) = tcsd;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 % call csd2tf
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 % ostruct is a struct array whose fields contain the residues and poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 % of estimated TFs. Since the fit is porformed on the columns of the TF
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 % matrix, each element of the array contains the residues and poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 % corresponding to the functions on the given column of the TF matrix.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 %ostruct = utils.math.csd2tf(csd,freq,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 ostruct = utils.math.csd2tf2(csd,freq,params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 % the filter for each channel is implemented by the rows of the TF matrix
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 switch dim
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 case 'one'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 switch target
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 case 'miir'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 % --- filter ---
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 res = ostruct.res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 poles = ostruct.poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 % construct a struct array of miir filters vectors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 pfilts(numel(res),1) = miir;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 for kk=1:numel(res)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 ft = miir(res(kk), [ 1 -poles(kk)], fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 ft.setIunits(unit(tgiunit));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 ft.setOunits(unit(tgounit));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 pfilts(kk,1) = ft;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 clear ft
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 filt = filterbank(pfilts,'parallel');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 a = matrix(filt);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 % Add history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 a.addHistory(iobj, pl, [], [csdao(:).hist]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 case 'parfrac'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 res = ostruct.res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 poles = ostruct.poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 fbk = parfrac(res,poles,0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 fbk.setIunits(unit(tgiunit));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 fbk.setOunits(unit(tgounit));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 a = matrix(fbk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 % Add history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 a.addHistory(iobj, pl, [], [csdm(:).hist]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 case 'multi'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 switch target
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 case 'miir'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 % init filters array
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 %fbk(nn*nn,1) = filterbank;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 %fbk = filterbank.newarray([nn nn]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 for zz=1:nn*nn % run over system dimension
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 % --- get column filter coefficients ---
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 % each column of mres\mpoles are the coefficients of a given filter
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 clear res poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 res = ostruct(zz).res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 poles = ostruct(zz).poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 % construct a struct array of miir filters vectors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 %ft(numel(res),1) = miir;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 for kk=1:numel(res)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 ft(kk,1) = miir(res(kk), [1 -poles(kk)], fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 ft(kk,1).setIunits(unit(tgiunit));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 ft(kk,1).setOunits(unit(tgounit));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 fbk(zz,1) = filterbank(ft,'parallel');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 clear ft
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 mfbk = reshape(fbk,nn,nn);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 a = matrix(mfbk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 % % overide default name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 % if strcmpi(pl.find('name'), 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 % pl.pset('name', sprintf('fromCSD(%s)', csdao.name));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 % % overide default description
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 % if isempty(pl.find('description'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 % pl.pset('description', csdao.description);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 % Add history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 a.addHistory(iobj, pl, [], [csdao(:).hist]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 case 'parfrac'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 % init filters array
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 %fbk(nn*nn,1) = parfrac;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 for zz=1:nn*nn % run over system dimension
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 % --- get column filter coefficients ---
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 % each column of mres\mpoles are the coefficients of a given filter
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 clear res poles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 res = ostruct(zz).res;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 poles = ostruct(zz).poles;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 fbk(zz,1) = parfrac(res,poles,0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 fbk(zz,1).setIunits(unit(tgiunit));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 fbk(zz,1).setOunits(unit(tgounit));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 mfbk = reshape(fbk,nn,nn);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 a = matrix(mfbk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 % % overide default name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 % if strcmpi(pl.find('name'), 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 % pl.pset('name', sprintf('fromCSD(%s)', csdao.name));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 % % overide default description
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 % if isempty(pl.find('description'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 % pl.pset('description', csdao.description);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 % Add history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 a.addHistory(iobj, pl, [], [csdao(:).hist]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 % Set properties from the plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 warning('off', utils.const.warnings.METHOD_NOT_FOUND);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 % remove parameters we already used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 pl_set = copy(pl,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 if pl_set.isparam('csd')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285 pl_set.remove('csd');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 if pl_set.isparam('fs')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 pl_set.remove('fs');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 if pl_set.isparam('targetobj')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 pl_set.remove('targetobj');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293 if pl_set.isparam('UseSym')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294 pl_set.remove('UseSym');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 if pl_set.isparam('iunits')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297 pl_set.remove('iunits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 if pl_set.isparam('ounits')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 pl_set.remove('ounits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 if pl_set.isparam('MaxIter')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303 pl_set.remove('MaxIter');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 if pl_set.isparam('MinOrder')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 pl_set.remove('MinOrder');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 if pl_set.isparam('MaxOrder')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 pl_set.remove('MaxOrder');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 if pl_set.isparam('PoleType')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312 pl_set.remove('PoleType');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314 if pl_set.isparam('Weights')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315 pl_set.remove('Weights');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 if pl_set.isparam('FITTOL')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318 pl_set.remove('FITTOL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
319 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
320 if pl_set.isparam('MSEVARTOL')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
321 pl_set.remove('MSEVARTOL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 if pl_set.isparam('plot')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324 pl_set.remove('plot');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326 a.setProperties(pl_set);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 warning('on', utils.const.warnings.METHOD_NOT_FOUND);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328
|
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
|