comparison m-toolbox/classes/@rational/fromPzmodel.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: fromPzmodel
4 %
5 % DESCRIPTION: Construct a rational from a pzmodel
6 %
7 % CALL: r = fromPzmodel(a, pl)
8 %
9 % PARAMETER: pl - plist
10 %
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 function r = fromPzmodel(r, pli)
13
14 VERSION = '$Id: fromPzmodel.m,v 1.11 2011/08/15 12:41:45 hewitson Exp $';
15
16
17 % get pzmodel info
18 ii = rational.getInfo('rational', 'From Pzmodel');
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 pzm = find(pl, 'pzmodel');
28
29 %--- Convert to rational
30
31 % get normalising gains
32 pg = 1;
33 for jj=1:numel(pzm.poles)
34 if pzm.poles(jj).q > 0.5
35 pg = pg .* 4*pi*pi*pzm.poles(jj).f*pzm.poles(jj).f;
36 else
37 pg = pg .* 2*pi*pzm.poles(jj).f;
38 end
39 end
40 zg = 1;
41 for jj=1:numel(pzm.zeros)
42 if pzm.zeros(jj).q > 0.5
43 zg = zg .* 4*pi*pi*pzm.zeros(jj).f*pzm.zeros(jj).f;
44 else
45 zg = zg .* 2*pi*pzm.zeros(jj).f;
46 end
47 end
48 % construct rational terms
49 if isempty(pzm.poles) % in case on no poles
50 den = 1;
51 else
52 den = poly(vertcat(pzm.poles(:).ri))./pg;
53 end
54 if isempty(pzm.zeros) % in case on no zeros
55 num = pzm.gain;
56 else
57 num = pzm.gain.*poly(vertcat(pzm.zeros(:).ri))./zg;
58 end
59
60 r.num = num;
61 r.den = den;
62
63 % Override some properties from the input pzmodel
64 if isempty(pl.find('ounits'))
65 pl.pset('ounits', pzm.ounits);
66 end
67
68 if isempty(pl.find('iunits'))
69 pl.pset('iunits', pzm.iunits);
70 end
71
72 if isempty(pl.find('name'))
73 pl.pset('name', sprintf('rational(%s)', pzm.name));
74 end
75
76 if isempty(pl.find('description'))
77 pl.pset('description', pzm.description);
78 end
79
80 % Add history
81 r.addHistory(ii, pl, [], pzm.hist);
82
83 % Set object properties
84 r.setObjectProperties(pl);
85
86 end