comparison m-toolbox/classes/@parfrac/parfrac.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 % PARFRAC partial fraction representation of a transfer function.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: PARFRAC partial fraction representation of a transfer function.
5 %
6 % R(1) R(2) R(n)
7 % H(s) = -------- + -------- + ... + -------- + K(s)
8 % s - P(1) s - P(2) s - P(n)
9 %
10 % SUPER CLASSES: ltpda_tf < ltpda_uoh < ltpda_uo < ltpda_obj
11 %
12 % CONSTRUCTOR:
13 %
14 % r = parfrac() - creates an empty parfrac object
15 % r = parfrac(res, poles, dir) - construct from residuals, poles
16 % and direct terms
17 % r = parfrac(..., 'name') - construct including name
18 % r = parfrac(..., iunits, ounits) - include input and output units
19 % r = parfrac(pl) - create a parfrac object from the
20 % description given in the parameter list.
21 % r = parfrac(pzm) - create a parfrac from a pzmodel.
22 % r = parfrac(rat) - create a parfrac from a rational TF.
23 %
24 %
25 % The poles can be specified in a array or a cell as a real or complex number.
26 %
27 % Example: r = parfrac([1 2+1i 2-1i], [6 1+3i 1-3i], []);
28 %
29 % <a href="matlab:utils.helper.displayMethodInfo('parfrac', 'parfrac')">Parameters Description</a>
30 %
31 % VERSION: $Id: parfrac.m,v 1.57 2011/10/25 11:50:55 luigi Exp $
32 %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34
35 classdef parfrac < ltpda_tf
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 % Property definition %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41 %---------- Public (read/write) Properties ----------
42 properties
43 end
44
45 %---------- Protected read-only Properties ----------
46 properties (SetAccess = protected)
47 res = []; % residuals [R]
48 poles = []; % poles (real or complex numbers) [P]
49 pmul = []; % Represents the pole multiplicity
50 dir = 0; % direct terms [K]
51 end
52
53 %---------- Private Properties ----------
54 properties (GetAccess = protected, SetAccess = protected)
55 end
56
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 % Check property setting %
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
61 methods
62 function set.res(obj, val)
63 if ~isnumeric(val) && ~isempty(val)
64 error('### The value for the property ''res'' must be a numeric array.');
65 end
66 if size(val,1) == 1
67 val = val.';
68 end
69 obj.res = val;
70 end
71 function set.poles(obj, val)
72 if ~(isnumeric(val) || iscell(val)) && ~isempty(val)
73 error('### The value for the property ''poles'' must be a numeric array.');
74 end
75 if size(val,1) == 1
76 val = val.';
77 end
78 obj.poles = val;
79 end
80 function set.dir(obj, val)
81 if ~isnumeric(val) && ~isempty(val)
82 error('### The value for the property ''dir'' must be a numeric array.');
83 end
84 if isempty(val)
85 obj.dir = val;
86 end
87 if size(val,1) == 1
88 val = val.';
89 end
90 obj.dir = val;
91 end
92 function set.pmul(obj, val)
93 if ~isnumeric(val) && ~isempty(val)
94 error('### The value for the property ''pmul'' must be a numeric array.');
95 end
96 if size(val,1) == 1
97 val = val.';
98 end
99 obj.pmul = val;
100 end
101 end
102
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 % Constructor %
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107 methods
108 function obj = parfrac(varargin)
109
110 import utils.const.*
111 utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
112
113 % Collect all parfract objects
114 [parfracs, invars, rest] = utils.helper.collect_objects(varargin(:), 'parfrac');
115
116 if isempty(rest) && ~isempty(parfracs)
117 % Do copy constructor and return
118 utils.helper.msg(msg.OPROC1, 'copy constructor');
119 obj = copy(parfracs, 1);
120 for kk=1:numel(obj)
121 obj(kk).addHistory(parfrac.getInfo('parfrac', 'None'), [], [], obj(kk).hist);
122 end
123 return
124 end
125
126 switch nargin
127 case 0
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 %%%%%%%%%%%% Zero inputs %%%%%%%%%%%%%%%
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 utils.helper.msg(msg.OPROC1, 'empty constructor');
132 obj.addHistory(parfrac.getInfo('parfrac', 'None'), plist(), [], []);
133
134 case 1
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 %%%%%%%%%%%% One inputs %%%%%%%%%%%%%%%
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
139 if ischar(varargin{1})
140 %%%%%%%%%% pzm = parfract('foo.mat') %%%%%%%%%%
141 %%%%%%%%%% pzm = parfract('foo.xml') %%%%%%%%%%
142 utils.helper.msg(msg.OPROC1, 'constructing from file %s', varargin{1});
143 obj = fromFile(obj, varargin{1});
144
145 elseif isstruct(varargin{1})
146 %%%%%%%%%% r = parfrac(struct) %%%%%%%%%%
147 utils.helper.msg(msg.OPROC1, 'constructing from struct');
148 obj = fromStruct(obj, varargin{1});
149
150 elseif isa(varargin{1}, 'rational')
151 %%%%%%%%%% r = parfrac(rational-object) %%%%%%%%%%
152 utils.helper.msg(msg.OPROC1, 'constructing from rational');
153 obj = fromRational(obj, plist('rational', varargin{1}));
154
155 elseif isa(varargin{1}, 'pzmodel')
156 %%%%%%%%%% r = parfrac(pzmodel-object) %%%%%%%%%%
157 utils.helper.msg(msg.OPROC1, 'constructing from pzmodel');
158 obj = fromPzmodel(obj, plist('pzmodel', varargin{1}));
159
160 elseif isa(varargin{1}, 'plist')
161 %%%%%%%%%% r = parfrac(plist) %%%%%%%%%%
162 pl = varargin{1};
163
164 % Selection of construction method
165 if pl.isparam('filename')
166 utils.helper.msg(msg.OPROC1, 'constructing from file %s', pl.find('filename'));
167 obj = fromFile(obj, pl);
168
169 elseif pl.isparam('hostname') || pl.isparam('conn')
170 utils.helper.msg(msg.OPROC1, 'constructing from repository %s', pl.find('hostname'));
171 obj = obj.fromRepository(pl);
172
173 elseif pl.isparam('res') || pl.isparam('poles') || pl.isparam('dir')
174 utils.helper.msg(msg.OPROC1, 'constructing from residuals/poles/direct');
175 obj = fromResidualsPolesDirect(obj, pl);
176
177 elseif pl.isparam('pzmodel')
178 utils.helper.msg(msg.OPROC1, 'constructing from pole/zero model');
179 obj = fromPzmodel(obj, pl);
180
181 elseif pl.isparam('rational')
182 utils.helper.msg(msg.OPROC1, 'constructing from rational object');
183 obj = fromRational(obj, pl);
184
185 elseif pl.isparam('built-in')
186 utils.helper.msg(msg.OPROC1, 'constructing from built-in model');
187 obj = fromModel(obj, pl);
188
189 elseif pl.isparam('Plist')
190 ipl = find(pl, 'Plist');
191 obj = parfrac(ipl);
192
193 else
194 obj.setObjectProperties(pl);
195 obj.addHistory(parfrac.getInfo('parfrac', 'None'), pl, [], []);
196 end
197 else
198 error('### Unknown single argument constructor.');
199 end
200
201 case 2
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 %%%%%%%%%%%%% Two inputs %%%%%%%%%%%%%%%
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 if (isa(varargin{1}, 'database') || isa(varargin{1}, 'mpipeline.repository.RepositoryConnection')) && isnumeric(varargin{2})
206 %%%%%%%%%% f = parfrac(<database-object>, [IDs]) %%%%%%%%%%
207 % parfrac(<database-object>, [IDs])
208 utils.helper.msg(msg.OPROC1, 'retrieve from repository');
209 obj = obj.fromRepository(plist('conn', varargin{1}, 'id', varargin{2}));
210
211 elseif (isa(varargin{1}, 'parfrac') || isa(varargin{1}, 'rational')) && isa(varargin{2}, 'plist') && isempty(varargin{2}.params)
212 %%%%%%%%%% f = parfrac(parfrac-object, <empty plist>) %%%%%%%%%%
213 obj = parfrac(varargin{1});
214
215 elseif isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && ...
216 isa(varargin{2}, 'history')
217 %%%%%%%%%% obj = parfrac(DOM node, history-objects) %%%%%%%%%%
218 obj = fromDom(obj, varargin{1}, varargin{2});
219
220 elseif isa(varargin{1}, 'ltpda_uoh') && isa(varargin{2}, 'plist')
221 %%%%%%%%%%% parfrac(<ltpda_uoh>-object, plist-object) %%%%%%%%%%
222 % always recreate from plist
223
224 % If we are trying to load from file, and the file exists, do
225 % that. Otherwise, copy the input object.
226 if varargin{2}.isparam('filename')
227 if exist(fullfile('.', find(varargin{2}, 'filename')), 'file')==2
228 obj = parfrac(varargin{2});
229 else
230 obj = parfrac(varargin{1});
231 end
232 else
233 obj = parfrac(varargin{2});
234 end
235 elseif isnumeric(varargin{1}) && isnumeric(varargin{2})
236 % r = parfrac(num, den)
237 utils.helper.msg(msg.OPROC1, 'constructing from residuals/poles/direct');
238 pl = plist('res', varargin{1}, 'poles', varargin{2});
239 obj = fromResidualsPolesDirect(obj, pl);
240
241 else
242 error('### Unknown 2 argument constructor.');
243 end
244
245 case 3
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 %%%%%%%%%%%% Three inputs %%%%%%%%%%%%%%
248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249
250 %%%%%%%%%% r = parfrac(num, den, dir) %%%%%%%%%%
251 utils.helper.msg(msg.OPROC1, 'constructing from residuals/poles/direct');
252 pl = plist('res', varargin{1}, 'poles', varargin{2}, 'dir', varargin{3});
253 obj = fromResidualsPolesDirect(obj, pl);
254
255 case 4
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 %%%%%%%%%%%% Four inputs %%%%%%%%%%%%%%%
258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259
260 %%%%%%%%%% r = parfrac(num, den, dir, name) %%%%%%%%%%
261 utils.helper.msg(msg.OPROC1, 'constructing from residuals/poles/direct');
262 pl = plist('res', varargin{1}, 'poles', varargin{2}, 'dir', varargin{3}, 'name', varargin{4});
263 obj = fromResidualsPolesDirect(obj, pl);
264
265 case 6
266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 %%%%%%%%%%%% five inputs %%%%%%%%%%%%%%%
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 %%%%%%%%%% pzm = parfrac(res, poles, dir, name, iunits, ounits) %%%%%%%%%%
270 utils.helper.msg(msg.OPROC1, 'constructing from residuals/poles/direct');
271 pl = plist('res', varargin{1}, 'poles', varargin{2}, 'dir', varargin{3}, ...
272 'name', varargin{4}, ...
273 'iunits', varargin{5}, 'ounits', varargin{6});
274 obj = fromResidualsPolesDirect(obj, pl);
275
276 otherwise
277 [parfracs, invars, rest] = utils.helper.collect_objects(varargin, 'parfrac');
278
279 %%% Do we have a list of PARFRAC objects as input
280 if ~isempty(parfracs) && isempty(rest)
281 obj = parfrac(parfracs);
282 else
283 error('### Unknown number of arguments.');
284 end
285 end
286
287 end % End constructor
288
289 end
290
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 % Methods (protected) %
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 methods (Access = protected)
295 end
296
297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 % Methods (static) %
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 methods (Static)
301
302 function mdls = getBuiltInModels(varargin)
303 mdls = ltpda_uo.getBuiltInModels('parfrac');
304 end
305
306 function out = VEROUT()
307 out = '$Id: parfrac.m,v 1.57 2011/10/25 11:50:55 luigi Exp $';
308 end
309
310 function ii = getInfo(varargin)
311 ii = utils.helper.generic_getInfo(varargin{:}, 'parfrac');
312 end
313
314 function out = SETS()
315 out = [SETS@ltpda_uoh, ...
316 {'From Rational'}, ...
317 {'From Pzmodel'}, ...
318 {'From Residuals/Poles/Direct'}];
319 end
320
321
322 function plout = getDefaultPlist(set)
323 persistent pl;
324 persistent lastset;
325 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set)
326 pl = parfrac.buildplist(set);
327 lastset = set;
328 end
329 plout = pl;
330 end
331
332 function out = buildplist(set)
333
334 if ~utils.helper.ismember(lower(parfrac.SETS), lower(set))
335 error('### Unknown set [%s]', set);
336 end
337
338 out = plist();
339 out = parfrac.addGlobalKeys(out);
340 out = buildplist@ltpda_uoh(out, set);
341
342
343 switch lower(set)
344 case 'from rational'
345 % rational
346 p = param({'rational','Rational transfer-function model object to design from.'}, {1, {rational}, paramValue.OPTIONAL});
347 out.append(p);
348 % Iunits
349 p = param({'iunits','The input units of the model.'}, paramValue.EMPTY_STRING);
350 out.append(p);
351
352 % Ounits
353 p = param({'ounits','The output units of the model.'}, paramValue.EMPTY_STRING);
354 out.append(p);
355 case 'from pzmodel'
356 % pzmodel
357 p = param({'pzmodel','Pole/zero model object to design from.'}, {1, {pzmodel}, paramValue.OPTIONAL});
358 out.append(p);
359 % Iunits
360 p = param({'iunits','The input units of the model.'}, paramValue.EMPTY_STRING);
361 out.append(p);
362
363 % Ounits
364 p = param({'ounits','The output units of the model.'}, paramValue.EMPTY_STRING);
365 out.append(p);
366 case 'from residuals/poles/direct'
367
368 % res
369 p = param({'res','Residual terms.'}, paramValue.EMPTY_DOUBLE);
370 out.append(p);
371
372 % Poles
373 p = param({'poles','Poles (real or complex numbers).'}, paramValue.EMPTY_DOUBLE);
374 out.append(p);
375
376 % Dir
377 p = param({'dir','Direct terms.'}, paramValue.DOUBLE_VALUE(0));
378 out.append(p);
379 % Iunits
380 p = param({'iunits','The input units of the model.'}, paramValue.EMPTY_STRING);
381 out.append(p);
382
383 % Ounits
384 p = param({'ounits','The output units of the model.'}, paramValue.EMPTY_STRING);
385 out.append(p);
386 end
387 end % function out = getDefaultPlist(varargin)
388
389 function obj = initObjectWithSize(n,m)
390 obj = parfrac.newarray([n m]);
391 end
392
393 end % End static methods
394
395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 % Methods (static, private) %
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398
399 methods (Static, Access=private)
400 end % End static, private methods
401
402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403 % Methods (static, hidden) %
404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405
406 methods (Static = true, Hidden = true)
407 varargout = loadobj(varargin)
408 varargout = update_struct(varargin);
409 end
410
411 methods (Hidden = true)
412 varargout = attachToDom(varargin)
413 end
414
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416 % Methods (public) %
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418 methods
419 varargout = char(varargin)
420 varargout = display(varargin)
421 varargout = copy(varargin)
422 end
423
424 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
425 % Methods (protected) %
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 methods (Access = protected)
428 varargout = respCore(varargin)
429 varargout = fromStruct(varargin)
430 varargout = fromDom(varargin)
431 end
432
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 % Methods (private) %
435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 methods (Access = private)
437 % Constructors
438 varargout = fromResidualsPolesDirect(varargin)
439 varargout = fromRational(varargin)
440 varargout = fromPzmodel(varargin)
441 end
442
443 end % End classdef
444
445 % From XML File
446 % -------------
447 %
448 % Construct a parfrac by loading it from an XML file.
449 %
450 % 'filename' - construct a parfrac from a filename.
451 % [default: empty string]
452 %
453 % Example: plist('filename', 'parfrac1.xml')
454 %
455 % From MAT File
456 % -------------
457 %
458 % Construct a parfrac by loading it from a MAT file.
459 %
460 % 'filename' - construct a parfrac from a filename.
461 % [default: empty string]
462 %
463 % Example: plist('filename', 'parfrac1.mat')
464 %
465 %
466 % From Repository
467 % ---------------
468 %
469 % Construct a parfrac by retrieving it from an LTPDA repository.
470 %
471 % 'Hostname' - the repository hostname. Only those objects which
472 % are parfracs are returned.
473 % [default: 'localhost'];
474 %
475 % Additional parameters:
476 %
477 % 'Database' - The database name [default: 'ltpda']
478 % 'ID' - A vector of object IDs. [default: []]
479 % 'CID' - Retrieve all parfrac objects from a particular
480 % collection.
481 % 'Binary' - Set to 'yes' to retrieve from stored binary
482 % representation (not always available).
483 %
484 % From Rational
485 % ------------
486 %
487 % Construct a parfrac TF from a rational TF
488 %
489 % 'rational' - the rational model to convert
490 % [default: empty rational object]
491 %
492 % Example: rat = rational([1 2 3], [4 5 6 7], 'my rational')
493 % plist('rational', rat)
494 %
495 % From Pzmodel
496 % ------------
497 %
498 % Construct a parfrac TF from a pzmodel
499 %
500 % 'pzmodel' - the pzmodel to convert
501 % [default: empty pole/zero model (pzmodel)]
502 %
503 % Example: pzm = pzmodel(1, {1 2 3}, {4 5})
504 % plist('pzmodel', pzm)
505 %
506 % From Residuals/Poles/Direct
507 % --------------------------------
508 %
509 % Construct a parfrac from arrays of coefficients
510 %
511 % 'res' - vector of residuals [default: []]
512 % 'poles' - vector/cell of real or complex numbers [default: []]
513 % 'dir' - vector of direct terms [default: []]
514 % 'name' - name of model [default: 'None']
515 %
516 % From Plist
517 % ----------
518 %
519 % 'Plist' - construct from a plist. The value passed should be a plist
520 % object. [default: empty plist]
521 %
522 % Example: pzm = pzmodel(1, {1 2 3}, {4 5})
523 % pl = plist('pzmodel', pzm)
524 % plist('PLIST', pl)