Mercurial > hg > ltpda
comparison m-toolbox/classes/@pzmodel/fromRational.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: fromRational | |
4 % | |
5 % DESCRIPTION: Construct a pzmodel from a rational TF | |
6 % | |
7 % CALL: pzm = fromRational(a, pl) | |
8 % | |
9 % PARAMETER: pl - plist | |
10 % | |
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
12 function pzm = fromRational(pzm, pli) | |
13 | |
14 VERSION = '$Id: fromRational.m,v 1.12 2011/08/15 12:20:52 hewitson Exp $'; | |
15 | |
16 | |
17 % get pzmodel info | |
18 ii = pzmodel.getInfo('pzmodel', 'From Rational'); | |
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 rat = find(pl, 'rational'); | |
28 | |
29 poles = roots(rat.den); | |
30 zeros = roots(rat.num); | |
31 | |
32 % remove conjugate pairs | |
33 if isempty(poles) | |
34 ps = []; | |
35 else | |
36 ps = {poles(1)}; | |
37 for jj=2:numel(poles) | |
38 if ~isreal(poles(jj)) | |
39 if~any(conj(poles(jj))==[ps{:}]) | |
40 ps = [ps poles(jj)]; | |
41 end | |
42 else | |
43 ps = [ps poles(jj)]; | |
44 end | |
45 end | |
46 end | |
47 | |
48 if isempty(zeros) | |
49 zs = []; | |
50 else | |
51 zs = {zeros(1)}; | |
52 for jj=2:numel(zeros) | |
53 if ~isreal(zeros(jj)) | |
54 if~any(conj(zeros(jj))==[zs{:}]) | |
55 zs = [zs zeros(jj)]; | |
56 end | |
57 else | |
58 zs = [zs zeros(jj)]; | |
59 end | |
60 end | |
61 end | |
62 | |
63 % get gain - must be a nicer way, but... | |
64 ig = abs(resp(rat, plist('f', 0))); | |
65 | |
66 % divide for (-2*pi) only when a real pole or zero is found | |
67 if ~isempty(ps) | |
68 numps = cell2mat(ps); | |
69 numps(imag(numps)==0) = numps(imag(numps)==0)/(-2*pi); | |
70 ps = num2cell(numps); | |
71 end | |
72 if ~isempty(zs) | |
73 numzs = cell2mat(zs); | |
74 numzs(imag(numzs)==0) = numzs(imag(numzs)==0)/(-2*pi); | |
75 zs = num2cell(numzs); | |
76 end | |
77 | |
78 % convert to pzmodel | |
79 pzm = pzmodel(ig.data.getY, ps, zs); | |
80 | |
81 % Override some plist values using the input object | |
82 if isempty(pl.find('ounits')) | |
83 pl.pset('ounits', rat.ounits); | |
84 end | |
85 | |
86 if isempty(pl.find('iunits')) | |
87 pl.pset('iunits', rat.iunits); | |
88 end | |
89 | |
90 if isempty(pl.find('name')) | |
91 pl.pset('name', sprintf('pzmodel(%s)', rat.name)); | |
92 end | |
93 | |
94 if isempty(pl.find('description')) | |
95 pl.pset('description', rat.description); | |
96 end | |
97 | |
98 % Add history | |
99 pzm.addHistory(ii, pl, [], rat.hist); | |
100 | |
101 % Set object properties | |
102 pzm.setObjectProperties(pl); | |
103 | |
104 end |