comparison m-toolbox/classes/@ssm/ssmFromRational.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: ssmFromRational
4 %
5 % DESCRIPTION: Construct a statespace model from a rational
6 %
7 % CALL: see ssm, this function is private
8 %
9 % TODO: check must be made there is no pole zero cancelation
10 %
11 % VERSION : '$Id: ssmFromRational.m,v 1.13 2011/03/23 20:05:37 adrien Exp $';
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = ssmFromRational(varargin)
16
17 VERSION = '$Id: ssmFromRational.m,v 1.13 2011/03/23 20:05:37 adrien Exp $';
18 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
19 % get info
20 ii = ssm.getInfo('ssm', 'From Description');
21 % Set the method version string in the minfo object
22 ii.setMversion([VERSION '-->' ii.mversion]);
23
24 if nargin ~=2
25 error('ssmFromRational need 2 inputs : (obj, plist) ')
26 elseif isa(varargin{1}, 'rational') && isa(varargin{2}, 'plist')
27 pl = combine(varargin{2}, ii.plists);
28 rationalsin = varargin{1};
29 else
30 error('### Please input (<object>,<plist>)');
31 end
32
33
34 ssmout = ssm.initObjectWithSize(size(rationalsin,1),size(rationalsin,2));
35 for i =1:numel(rationalsin)
36 num = rationalsin(i).num;
37 den = rationalsin(i).den;
38 num = num/den(1);
39 den = den/den(1);
40 Nss = size(den,2)-1;
41 if length(num)<Nss+1
42 num = [zeros(1,Nss+1-length(num)) num];
43 end
44 [q,r] = deconv(num,den);%polynmial division for den = conv(num,q)+r .
45 if ~length(q)==1
46 error('system may be non caussal');
47 end
48
49 ssmout(i).dmats = {q};
50 ssmout(i).amats = {[zeros(Nss-1,1) eye(Nss-1); fliplr(-den(2:(Nss+1)))]};
51 ssmout(i).bmats = {zeros(Nss,1)};
52 if Nss>0
53 ssmout(i).bmats{1}(Nss) = 1;
54 end
55 ssmout(i).cmats = {fliplr(r(2:(Nss+1)))};
56
57 ssmout(i).name = rationalsin(i).name;
58 ssmout(i).timestep = 0;
59
60 inputstr = 'input';
61 outputstr = 'output';
62 ssstr = 'state';
63
64 ssmout(i).inputs = ssmblock.makeBlocksWithData({inputstr},[],{{inputstr}}, {rationalsin(i).iunits},[] );
65 ssmout(i).outputs = ssmblock.makeBlocksWithData({outputstr},[],{{outputstr}}, {rationalsin(i).ounits},[] );
66 ssmout(i).states = ssmblock.makeBlocksWithSize(Nss, ssstr);
67
68 ssmout(i).addHistory(ii, pl, {''}, rationalsin(i).hist);
69
70
71 if ~strcmp(pl.find('name'),'None')
72 ssmout(i).name = pl.find('name');
73 end
74 if ~strcmp(pl.find('description'),'')
75 ssmout(i).description = pl.find('description');
76 end
77
78 end
79
80 varargout = {ssmout};
81 end
82
83