comparison m-toolbox/classes/@pzmodel/pzmodel.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children a71a40911c27
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % PZMODEL constructor for pzmodel class.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: PZMODEL constructor for pzmodel class.
5 %
6 %
7 % CONSTRUCTOR:
8 %
9 % pzm = pzmodel() - creates an empty pzmodel object
10 % pzm = pzmodel(g, p, z) - construct from gain, poles, zeros
11 % pzm = pzmodel(g, p, z, d) - construct from gain, poles, zeros and a delay (in seconds)
12 % pzm = pzmodel(g, p, z, 'name') - construct including name
13 % pzm = pzmodel(g, p, z, - construct from gain, poles, zeros, and
14 % iunits, ounits) io-units
15 % pzm = pzmodel('foo.fil') - construct from LISO .fil file
16 % pzm = pzmodel('foo.xml') - construct by loading the pzmodel from disk
17 % pzm = pzmodel('foo.mat') - construct by loading the pzmodel from disk
18 % pzm = pzmodel(pl) - create a pzmodel object from the
19 % description given in the parameter list.
20 % pzm = pzmodel(rat) - creates a pzmodel from rational TF
21 %
22 %
23 % Poles and zeros can be given as single values, or a 2-element vector for
24 % [f, Q]. Multiple poles and zeros should be given in a cell-array:
25 %
26 % e.g. p = pzmodel(1, {1, 2, [3 4]}, {5, [6 10]}, 2)
27 %
28 % <a href="matlab:utils.helper.displayMethodInfo('pzmodel', 'pzmodel')">Parameters Description</a>
29 %
30 % VERSION: $Id: pzmodel.m,v 1.130 2011/08/15 13:02:26 hewitson Exp $
31 %
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 classdef pzmodel < ltpda_tf
34
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 % Property definition %
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38
39 %---------- Public (read/write) Properties ----------
40 properties
41 end
42
43 %---------- Protected read-only Properties ----------
44 properties (SetAccess = protected)
45 poles = []; % pole-array of the model
46 zeros = []; % zero-array of the model
47 gain = NaN; % gain of the model
48 delay = 0; % delay of the pole/zero model
49 end
50
51 %---------- Private Properties ----------
52 properties (GetAccess = protected, SetAccess = protected)
53 end
54
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 % Check property setting %
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
59 methods
60 function set.gain(obj, val)
61 if ~isnumeric(val) || isempty(val) || ~isreal(val)
62 error('### The value for the property ''gain'' must be a real number');
63 end
64 obj.gain = val;
65 end
66 function set.poles(obj, val)
67 if ~isa(val, 'pz') && ~isempty(val)
68 error('### The value for the property ''poles'' must be a vector of pz objects.');
69 end
70 obj.poles = val;
71 end
72 function set.zeros(obj, val)
73 if ~isa(val, 'pz') && ~isempty(val)
74 error('### The value for the property ''zeros'' must be a vector of pz objects.');
75 end
76 obj.zeros = val;
77 end
78 end
79
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % Constructor %
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84 methods
85 function obj = pzmodel(varargin)
86
87 import utils.const.*
88 utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
89
90 % Collect all pzmodel objects
91 [pzs, invars, rest] = utils.helper.collect_objects(varargin(:), 'pzmodel');
92
93 if isempty(rest) && ~isempty(pzs)
94 % Do copy constructor and return
95 utils.helper.msg(msg.OPROC1, 'copy constructor');
96 obj = copy(pzs, 1);
97 for kk=1:numel(obj)
98 obj(kk).addHistory(pzmodel.getInfo('pzmodel', 'None'), [], [], obj(kk).hist);
99 end
100 return
101 end
102
103 switch nargin
104 case 0
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 %%%%%%%%%%%% Zero inputs %%%%%%%%%%%%%%%
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 utils.helper.msg(msg.OPROC1, 'empty constructor');
109 obj.addHistory(pzmodel.getInfo('pzmodel', 'None'), plist(), [], []);
110
111 case 1
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 %%%%%%%%%%%% One inputs %%%%%%%%%%%%%%%
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
116 if ischar(varargin{1})
117 %======== Filename
118 %%%%%%%%%% pzm = pzmodel('foo.mat') %%%%%%%%%%
119 %%%%%%%%%% pzm = pzmodel('foo.xml') %%%%%%%%%%
120 %%%%%%%%%% pzm = pzmodel('foo.fil') %%%%%%%%%%
121 utils.helper.msg(msg.OPROC1, 'constructing from file %s', varargin{1});
122 obj = fromFile(obj, varargin{1});
123
124 elseif isnumeric(varargin{1})
125 %%%%%%%%% pzm = pzmodel(const) %%%%%%%%%%%%%%
126
127 obj = pzmodel(varargin{1}, {}, {});
128
129 elseif isstruct(varargin{1})
130 %%%%%%%%%% pzm = pzmodel(struct) %%%%%%%%%%
131 utils.helper.msg(msg.OPROC1, 'constructing from struct');
132 obj = fromStruct(obj, varargin{1});
133
134 elseif isa(varargin{1}, 'rational')
135 %%%%%%%%%% pzm = pzmodel(rational-object) %%%%%%%%%%
136 utils.helper.msg(msg.OPROC1, 'constructing from rational');
137 obj = fromRational(obj, plist('rational', varargin{1}));
138
139 elseif isa(varargin{1}, 'parfrac')
140 %%%%%%%%%% pzm = pzmodel(rational-object) %%%%%%%%%%
141 utils.helper.msg(msg.OPROC1, 'constructing from parfrac');
142 obj = fromParfrac(obj, plist('parfrac', varargin{1}));
143
144 elseif isa(varargin{1}, 'plist')
145 %%%%%%%%%% pzm = pzmodel(plist-object) %%%%%%%%%%
146 pl = varargin{1};
147
148 if pl.isparam('filename')
149 utils.helper.msg(msg.OPROC1, 'constructing from file %s', pl.find('filename'));
150 obj = fromFile(obj, pl);
151
152 elseif pl.isparam('hostname') || pl.isparam('conn')
153 utils.helper.msg(msg.OPROC1, 'constructing from repository %s', pl.find('hostname'));
154 obj = obj.fromRepository(pl);
155
156 elseif pl.isparam('rational')
157 utils.helper.msg(msg.OPROC1, 'constructing from rational object');
158 obj = fromRational(obj, pl);
159
160 elseif pl.isparam('parfrac')
161 utils.helper.msg(msg.OPROC1, 'constructing from parfrac');
162 obj = fromParfrac(obj, pl);
163
164 elseif pl.isparam('gain') || pl.isparam('poles') || pl.isparam('zeros')
165 utils.helper.msg(msg.OPROC1, 'constructing from poles and zeros');
166 obj = fromPolesAndZeros(obj, pl);
167
168 elseif pl.isparam('pzmodel')
169 utils.helper.msg(msg.OPROC1, 'constructing from pole/zero model');
170 obj = pzmodel(find(pl, 'pzmodel'));
171
172 elseif pl.isparam('built-in')
173 utils.helper.msg(msg.OPROC1, 'constructing from built-in model');
174 obj = fromModel(obj, pl);
175
176 elseif pl.isparam('plist')
177 ipl = find(pl, 'plist');
178 % pass the ipl into the constructor
179 obj = pzmodel(ipl);
180
181 else
182 obj.setObjectProperties(pl);
183 obj.addHistory(pzmodel.getInfo('pzmodel', 'None'), pl, [], []);
184 end
185 else
186 error('### Unknown single argument constructor.');
187 end
188
189 case 2
190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 %%%%%%%%%%%%% Two inputs %%%%%%%%%%%%%%%
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193
194 if (isa(varargin{1}, 'database') || isa(varargin{1}, 'mpipeline.repository.RepositoryConnection')) && isnumeric(varargin{2})
195 %%%%%%%%%% f = pzmodel(<database-object>, [IDs]) %%%%%%%%%%
196 utils.helper.msg(msg.OPROC1, 'retrieve from repository');
197 obj = obj.fromRepository(plist('conn', varargin{1}, 'id', varargin{2}));
198
199 elseif isa(varargin{1}, 'pzmodel') && isa(varargin{2}, 'plist') && isempty(varargin{2}.params)
200 %%%%%%%%%% f = pzmodel(pzmodel-object, <empty plist>) %%%%%%%%%%
201 obj = pzmodel(varargin{1});
202
203 elseif isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && ...
204 isa(varargin{2}, 'history')
205 %%%%%%%%%% obj = pzmodel(DOM node, history-objects) %%%%%%%%%%
206 obj = fromDom(obj, varargin{1}, varargin{2});
207
208 elseif isa(varargin{1}, 'ltpda_uoh') && isa(varargin{2}, 'plist')
209 %%%%%%%%%%% pzmodel(<ltpda_uoh>-object, plist-object) %%%%%%%%%%
210 % always recreate from plist
211
212 % If we are trying to load from file, and the file exists, do
213 % that. Otherwise, copy the input object.
214 if varargin{2}.isparam('filename')
215 if exist(fullfile('.', find(varargin{2}, 'filename')), 'file')==2
216 obj = pzmodel(varargin{2});
217 else
218 obj = pzmodel(varargin{1});
219 end
220 else
221 obj = pzmodel(varargin{2});
222 end
223
224 else
225 error('### Unknown 2 argument constructor.');
226 end
227
228 case 3
229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 %%%%%%%%%%%% Three inputs %%%%%%%%%%%%%%
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232
233 %%%%%%%%%% pzm = pzmodel(gain, poles, zeros) %%%%%%%%%%
234 utils.helper.msg(msg.OPROC1, 'constructing from poles and zeros');
235 pl = plist('gain', varargin{1}, 'poles', varargin{2}, 'zeros', varargin{3});
236 obj = fromPolesAndZeros(obj, pl);
237 case 4
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 %%%%%%%%%%%% Four inputs %%%%%%%%%%%%%%%
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241
242 if isnumeric(varargin{1}) && ischar(varargin{4})
243 %%%%%%%%%% pzm = pzmodel(gain, poles, zeros, name) %%%%%%%%%%
244 utils.helper.msg(msg.OPROC1, 'constructing from poles and zeros');
245 pl = plist('gain', varargin{1}, 'poles', varargin{2}, 'zeros', varargin{3}, 'name', varargin{4});
246 obj = fromPolesAndZeros(obj, pl);
247
248 elseif isnumeric(varargin{1}) && isnumeric(varargin{4})
249 %%%%%%%%%% pzm = pzmodel(gain, poles, zeros, delay) %%%%%%%%%%
250 utils.helper.msg(msg.OPROC1, 'constructing from poles and zeros and delay');
251 pl = plist('gain', varargin{1}, 'poles', varargin{2}, 'zeros', varargin{3}, 'delay', varargin{4});
252 obj = fromPolesAndZeros(obj, pl);
253
254 else
255 error('### Unknown 4 argument constructor.');
256 end
257
258
259 case 5
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 %%%%%%%%%%%% five inputs %%%%%%%%%%%%%%%
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263
264 if isnumeric(varargin{1}) && isa(varargin{4}, 'unit') && isa(varargin{5}, 'unit')
265 %%%%%%%%%% pzm = pzmodel(gain, poles, zeros, in<unit-object>, out<unit-object>) %%%%%%%%%%
266 utils.helper.msg(msg.OPROC1, 'constructing from poles, zeros and i/o-units');
267 pl = plist('gain', varargin{1}, 'poles', varargin{2}, 'zeros', varargin{3}, 'iunits', varargin{4}, 'ounits', varargin{5});
268 obj = fromPolesAndZeros(obj, pl);
269
270 elseif isnumeric(varargin{1}) && isnumeric(varargin{4}) && ischar(varargin{5})
271 %%%%%%%%%% pzm = pzmodel(gain, poles, zeros, delay, name) %%%%%%%%%%
272 utils.helper.msg(msg.OPROC1, 'constructing from poles, zeros delay and name');
273 pl = plist('gain', varargin{1}, 'poles', varargin{2}, 'zeros', varargin{3}, 'delay', varargin{4}, 'name', varargin{5});
274 obj = fromPolesAndZeros(obj, pl);
275
276 else
277 end
278
279 otherwise
280 [pzs, invars, rest] = utils.helper.collect_objects(args, 'pzmodel');
281
282 %%% Do we have a list of PZMODELs as input
283 if ~isempty(pzs) && isempty(rest)
284 obj = pzmodel(pzs);
285 else
286 error('### Unknown number of arguments.');
287 end
288 end
289
290 end % End constructor
291
292 end
293
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 % Methods (static) %
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 methods (Static)
298
299 function mdls = getBuiltInModels(varargin)
300 mdls = ltpda_uo.getBuiltInModels('pzmodel');
301 end
302
303 function out = VEROUT()
304 out = '$Id: pzmodel.m,v 1.130 2011/08/15 13:02:26 hewitson Exp $';
305 end
306
307 function ii = getInfo(varargin)
308 ii = utils.helper.generic_getInfo(varargin{:}, 'pzmodel');
309 end
310
311 function out = SETS()
312 out = [SETS@ltpda_uoh, ...
313 {'From LISO File'}, ...
314 {'From Rational'}, ...
315 {'From Parfrac'}, ...
316 {'From Poles/Zeros'}];
317 end
318
319 function plout = getDefaultPlist(set)
320 persistent pl;
321 persistent lastset;
322 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set)
323 pl = pzmodel.buildplist(set);
324 lastset = set;
325 end
326 plout = pl;
327 end
328
329 function out = buildplist(set)
330
331 if ~utils.helper.ismember(lower(pzmodel.SETS), lower(set))
332 error('### Unknown set [%s]', set);
333 end
334
335 out = plist();
336 out = pzmodel.addGlobalKeys(out);
337 out = buildplist@ltpda_uoh(out, set);
338
339 switch lower(set)
340 case 'from poles/zeros'
341
342 % Gain
343 p = param({'gain','Model gain.'}, paramValue.DOUBLE_VALUE(1));
344 out.append(p);
345
346 % Poles
347 p = param({'poles',['Vector/Cell-array of poles. Use either pz objects or the format<br>'...
348 'like <tt>{[f1, q1], f2, f3, [f4, q4]}<tt>']}, paramValue.EMPTY_DOUBLE);
349 out.append(p);
350
351 % Zeros
352 p = param({'zeros',['Vector/Cell-array of zeros. Use either pz objects or the format<br>'...
353 'like <tt>{[f1, q1], f2, f3, [f4, q4]}<tt>']}, paramValue.EMPTY_DOUBLE);
354 out.append(p);
355
356 % Iunits
357 p = param({'iunits','The input units of the model.'}, paramValue.EMPTY_STRING);
358 out.append(p);
359
360 % Ounits
361 p = param({'ounits','The output units of the model.'}, paramValue.EMPTY_STRING);
362 out.append(p);
363
364 % Delay
365 p = param({'delay','The delay of the model in seconds.'}, paramValue.DOUBLE_VALUE(0));
366 out.append(p);
367
368 case 'from rational'
369
370 % rational
371 p = param({'rational','Rational transfer-function model object to design from.'}, {1, {rational}, paramValue.OPTIONAL});
372 out.append(p);
373
374 % Iunits
375 p = param({'iunits','The input units of the model.'}, paramValue.EMPTY_STRING);
376 out.append(p);
377
378 % Ounits
379 p = param({'ounits','The output units of the model.'}, paramValue.EMPTY_STRING);
380 out.append(p);
381
382 case 'from parfrac'
383
384 % rational
385 p = param({'parfrac','Partial fractions transfer-function model object to design from.'}, {1, {parfrac}, paramValue.OPTIONAL});
386 out.append(p);
387
388 % Iunits
389 p = param({'iunits','The input units of the model.'}, paramValue.EMPTY_STRING);
390 out.append(p);
391
392 % Ounits
393 p = param({'ounits','The output units of the model.'}, paramValue.EMPTY_STRING);
394 out.append(p);
395
396 case 'from liso file'
397 % Filename
398 p = param({'filename','LISO filename.'}, paramValue.EMPTY_STRING);
399 out.append(p);
400 end
401 end % function out = getDefaultPlist(varargin)
402
403 function obj = initObjectWithSize(n,m)
404 obj = pzmodel.newarray([n m]);
405 end
406
407 end % End static methods
408
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 % Methods (static, private) %
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412
413 methods (Static, Access=private)
414
415 [ao,bo] = abcascade(a1,b1,a2,b2)
416
417 end % End static, private methods
418
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 % Methods (static, hidden) %
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422
423 methods (Static = true, Hidden = true)
424 varargout = loadobj(varargin)
425 varargout = update_struct(varargin);
426 end
427
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 % Methods (public) %
430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
431 methods
432 varargout = char(varargin)
433 varargout = display(varargin)
434 varargout = copy(varargin)
435
436 f = getlowerFreq(varargin)
437 f = getupperFreq(varargin)
438
439 varargout = tomiir(varargin)
440 varargout = tomfir(varargin)
441 varargout = fngen(varargin)
442
443 varargout = setGain(varargin)
444 varargout = setDelay(varargin)
445 varargout = setPoles(varargin)
446 varargout = setZeros(varargin)
447 end
448
449 methods (Hidden = true)
450 varargout = attachToDom(varargin)
451 end
452
453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454 % Methods (protected) %
455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 methods (Access = protected)
457 varargout = fromLISO(varargin)
458 varargout = fromStruct(varargin)
459 varargout = fromDom(varargin)
460 varargout = pzm2ab(varargin)
461 varargout = respCore(varargin)
462 end
463
464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465 % Methods (private) %
466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
467 methods (Access = private)
468 % Constructors
469 varargout = fromPolesAndZeros(varargin)
470 varargout = fromRational(varargin)
471 varargout = fromParfrac(varargin)
472 end
473
474 end % End classdef
475