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