Mercurial > hg > ltpda
comparison m-toolbox/classes/@pzmodel/fromParfrac.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
2 % | |
3 % FUNCTION: fromParfrac | |
4 % | |
5 % DESCRIPTION: Construct a pzmodel from a partial fractions TF | |
6 % | |
7 % CALL: pzm = fromParfrac(a, pl) | |
8 % | |
9 % PARAMETER: pl - plist | |
10 % | |
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
12 function pzm = fromParfrac(pzm, pli) | |
13 | |
14 VERSION = '$Id: fromParfrac.m,v 1.7 2011/08/15 12:18:38 hewitson Exp $'; | |
15 | |
16 | |
17 % get pzmodel info | |
18 ii = pzmodel.getInfo('pzmodel', 'From Parfrac'); | |
19 | |
20 % Set the method version string in the minfo object | |
21 ii.setMversion([VERSION '-->' ii.mversion]); | |
22 | |
23 % Combine input plist with default values | |
24 pl = applyDefaults(ii.plists, pli); | |
25 | |
26 % Set fields | |
27 pf = find(pl, 'parfrac'); | |
28 | |
29 poles = pf.poles; | |
30 | |
31 % get numerator | |
32 [num,den] = residue(pf.res,pf.poles,pf.dir); | |
33 zeros = roots(num); | |
34 | |
35 % find dc gain | |
36 ig = sum(-1*pf.res./poles) + pf.dir; | |
37 | |
38 % remove conjugate pairs | |
39 if isempty(poles) | |
40 ps = []; | |
41 else | |
42 ps = {poles(1)}; | |
43 for jj=2:numel(poles) | |
44 if ~isreal(poles(jj)) | |
45 if~any(conj(poles(jj))==[ps{:}]) | |
46 ps = [ps poles(jj)]; | |
47 end | |
48 else | |
49 ps = [ps poles(jj)]; | |
50 end | |
51 end | |
52 end | |
53 | |
54 if isempty(zeros) | |
55 zs = []; | |
56 else | |
57 zs = {zeros(1)}; | |
58 for jj=2:numel(zeros) | |
59 if ~isreal(zeros(jj)) | |
60 if~any(conj(zeros(jj))==[zs{:}]) | |
61 zs = [zs zeros(jj)]; | |
62 end | |
63 else | |
64 zs = [zs zeros(jj)]; | |
65 end | |
66 end | |
67 end | |
68 | |
69 % divide for (-2*pi) only when a real pole or zero is found | |
70 if ~isempty(ps) | |
71 numps = cell2mat(ps); | |
72 numps(imag(numps)==0) = numps(imag(numps)==0)./(2.*sign(numps(imag(numps)==0)).*pi); | |
73 ps = num2cell(numps); | |
74 end | |
75 if ~isempty(zs) | |
76 numzs = cell2mat(zs); | |
77 numzs(imag(numzs)==0) = numzs(imag(numzs)==0)./(2.*sign(numzs(imag(numzs)==0)).*pi); | |
78 zs = num2cell(numzs); | |
79 end | |
80 | |
81 pzm = pzmodel(ig, ps, zs); | |
82 | |
83 % Override some plist values | |
84 if isempty(pl.find('ounits')) | |
85 pl.pset('ounits', pf.ounits); | |
86 end | |
87 | |
88 if isempty(pl.find('iunits')) | |
89 pl.pset('iunits', pf.iunits); | |
90 end | |
91 | |
92 if isempty(pl.find('name')) | |
93 pl.pset('name', sprintf('pzmodel(%s)', pf.name)); | |
94 end | |
95 | |
96 if isempty(pl.find('description')) | |
97 pl.pset('description', pf.description); | |
98 end | |
99 | |
100 % Add history | |
101 pzm.addHistory(ii, pl, [], pf.hist); | |
102 | |
103 % Set object properties | |
104 pzm.setObjectProperties(pl); | |
105 | |
106 end |