Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/ssm2rational.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 % SSM2RATIONAL converts a statespace model object to a rational frac. object | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SSM2RATIONAL converts a statespace model object to | |
5 % a rational fraction object. | |
6 % | |
7 % CALL: | |
8 % >> rats = ssm2rational(ssm, pl); | |
9 % | |
10 % INPUT : | |
11 % | |
12 % ssm - a ssm object | |
13 % pl - a plist with parameters 'inputs', 'states' and | |
14 % 'outputs' to indicate which inputs, states and output | |
15 % variables are taken in account. This requires proper | |
16 % variable naming. If a variable called appears more | |
17 % that once it will be used once only. | |
18 % | |
19 % | |
20 % OUTPUT: | |
21 % | |
22 % rats - an array of rational fraction object | |
23 % | |
24 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'ssm2rational')">Parameters Description</a> | |
25 % | |
26 % VERSION: $Id: ssm2rational.m,v 1.19 2011/04/08 08:56:23 hewitson Exp $ | |
27 % | |
28 % IMPLEMENTATION NOT FINISHED!!!! | |
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
30 | |
31 function varargout = ssm2rational(varargin) | |
32 | |
33 % Check if this is a call for parameters | |
34 if utils.helper.isinfocall(varargin{:}) | |
35 varargout{1} = getInfo(varargin{3}); | |
36 return | |
37 end | |
38 | |
39 %% starting initial checks | |
40 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]); | |
41 | |
42 % Collect input variable names | |
43 in_names = cell(size(varargin)); | |
44 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
45 | |
46 % Collect all SSMs and plists | |
47 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names); | |
48 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
49 if ~isempty(rest) | |
50 pl = combine(pl, plist(rest{:})); | |
51 end | |
52 pl = combine(pl, getDefaultPlist()); | |
53 | |
54 if numel(sys) ~= 1 | |
55 error('### Input (only) one SSM object.'); | |
56 end | |
57 | |
58 %% begin function body | |
59 | |
60 %% convert to double | |
61 % Convert to double arrays | |
62 [A,B,C,D,Ts,inputvarnames,ssvarnames,outputvarnames] = double(sys, pl); | |
63 | |
64 Ninputs_out = numel(inputvarnames); | |
65 Noutputs_out = numel(outputvarnames); | |
66 | |
67 if Ts > 0 | |
68 error('system should be time continuous. Use ssm2miir instead'); | |
69 else | |
70 %% convert to pzm | |
71 rational_out(Noutputs_out, Ninputs_out) = rational(); | |
72 for ii=1:Ninputs_out | |
73 for oo=1:Noutputs_out | |
74 sys_loc =ss( A,B(:,ii),C(oo,:),D(oo, ii ),Ts); | |
75 sys_loc = minreal(sys_loc); | |
76 [A_loc, B_loc, C_loc, D_loc]=ssdata(sys_loc); | |
77 [b,a] = ss2tf(A_loc, B_loc, C_loc, D_loc); | |
78 name = [ssm_invars{1},' : ',inputvarnames{ii},' -> ',outputvarnames{oo}]; | |
79 if isequal(b,0) || isequal(a,0) | |
80 m = rational(); | |
81 else | |
82 m = rational(real(b), real(a), 1/sys.timestep); | |
83 end | |
84 m.addHistory(ssm.getInfo(mfilename), pl , ssm_invars, sys.hist); | |
85 m.name = name; | |
86 rational_out(oo, ii) = m; | |
87 end | |
88 end | |
89 end | |
90 if nargout == numel(rational_out) | |
91 for ii = 1:numel(rational_out) | |
92 varargout{ii} = rational_out(ii); | |
93 end | |
94 else | |
95 varargout{1} = rational_out; | |
96 end | |
97 end | |
98 | |
99 %-------------------------------------------------------------------------- | |
100 % Get Info Object | |
101 %-------------------------------------------------------------------------- | |
102 function ii = getInfo(varargin) | |
103 | |
104 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
105 sets = {}; | |
106 pl = []; | |
107 else | |
108 sets = {'Default'}; | |
109 pl = getDefaultPlist; | |
110 end | |
111 % Build info object | |
112 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.converter, '$Id: ssm2rational.m,v 1.19 2011/04/08 08:56:23 hewitson Exp $', sets, pl); | |
113 end | |
114 | |
115 %-------------------------------------------------------------------------- | |
116 % Get Default Plist | |
117 %-------------------------------------------------------------------------- | |
118 function pl = getDefaultPlist() | |
119 pl = plist(); | |
120 | |
121 p = param({'inputs', ['Specify the inputs. Give one of:<ul>'... | |
122 '<li>A cell-array of input port names.</li>'... | |
123 '<li>A cell-array of logical arrays specifying which input ports to use for each input block.</li>'... | |
124 '<li>A cell-array of double values specifying which input ports to use for each input block.<li>'... | |
125 '<li>The string ''ALL'' to use all inputs.']}, paramValue.STRING_VALUE('ALL')); | |
126 pl.append(p); | |
127 | |
128 p = param({'states', 'Specify the states. Specify the states as for the ''inputs'' parameter.'}, paramValue.STRING_VALUE('ALL')); | |
129 pl.append(p); | |
130 | |
131 p = param({'outputs', 'Specify the outputs. Specify the outputs as for the ''inputs'' parameter.'}, paramValue.STRING_VALUE('ALL')); | |
132 pl.append(p); | |
133 end | |
134 |