0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % BODE makes a bode plot from the given inputs to outputs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % DESCRIPTION: BODE makes a bode plot from the given inputs to outputs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % CALL: mat_out = bode(sys, pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % mat_out = bode(sys, 'key1', 'option1')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % INPUTS:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % 'sys' - ssm object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % 'pl' - plist of options
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % OUTPUTS:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % 'mat_out' - matrix of output AOs containing the requested responses.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'bode')">Parameter Sets</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % VERSION: $Id: bode.m,v 1.40 2011/04/17 21:28:05 adrien Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 function varargout = bode(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % use the caller is method flag
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 callerIsMethod = utils.helper.callerIsMethod;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % Check if this is a call for parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 if utils.helper.isinfocall(varargin{:})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 varargout{1} = getInfo(varargin{3});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 if callerIsMethod
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % assume bode(sys,pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 system = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 pl = applyDefaults(getDefaultPlist(), varargin{2});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 % starting initial checks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 utils.helper.msg(utils.const.msg.PROC3, ['running ', mfilename]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 % Collect input variable names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 in_names = cell(size(varargin));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 for ii = 1:nargin,in_names{ii} = inputname(ii);end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % Collect all AOs and plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 [system, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 % combine default plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 if ~isempty(rest)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 pl = combine(pl, plist(rest{:}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 pl = combine(pl, getDefaultPlist());
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % retrieving system's infos
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 if numel(system)~=1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 error('we should have only one ssm and one plist object as an input')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 inhist = system.hist;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 if ~system.isStable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 error('input ssm is not stable!')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 if (system.isnumerical == 0)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 warning(['The system ' system.name ' is symbolic. The system is made numeric for bode calculation.'])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 sys = copy(system,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 sys.keepParameters;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 sys = system;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % Compute frequency vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 f = pl.find('f');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 if isempty(f)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 % finding "f2"
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 if isempty(pl.find('f2'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 if sys.timestep>0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 f2 = 0.5/sys.timestep;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 f2 = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 f2 = pl.find('f2');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 % finding "f1"
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 if isempty(pl.find('f1'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 f1 = f2*1e-5;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 f1 = pl.find('f1');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 nf = pl.find('nf');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 scale = pl.find('scale');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % building "f" vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 switch lower(scale)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 case 'log'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 f = logspace(log10(f1), log10(f2), nf);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 case 'lin'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 f = linspace(f1, f2, nf);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 error('### Unknown scale option');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 % Is the f vector in an AO?
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 if isa(f, 'ao') && (isa(f.data, 'fsdata') || isa(f.data, 'xydata'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 f = f.x;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 % Compute omega
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 w = 2*pi*f;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 if find(pl, 'reorganize')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 sys = reorganize(sys, pl, 'set', 'for bode', 'internal', 'internal');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 % getting system's i/o sizes
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 timestep = sys.timestep;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 fs = 1/timestep;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 inputSizes = sys.inputsizes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 outputSizes = sys.outputsizes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 Nin = inputSizes(1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 NstatesOut = outputSizes(1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 NoutputsOut = outputSizes(2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 A = sys.amats{1,1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 Coutputs = sys.cmats{2,1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 Cstates = sys.cmats{1,1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 B = sys.bmats{1,1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 D = sys.dmats{2,1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 Dstates = zeros(size(Cstates,1), size(D,2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 % bode computation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 resps = ssm.doBode(A, B, [Cstates; Coutputs], [Dstates; D], w, timestep);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 numericOutput = pl.find('numeric output');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 % build AO
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 if numericOutput
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 % just output pure numbers
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 count = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 for ii=1:Nin
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 for oo=1:NoutputsOut
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 y = squeeze(resps(NstatesOut+oo,ii,:));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 varargout{count} = y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 count = count + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 return;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 % First make outputs and set the data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 ao_out = ao.initObjectWithSize(NstatesOut+NoutputsOut, Nin);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 for ii=1:Nin
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 for oo=1:NstatesOut
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 ao_out(oo,ii).setData(fsdata(f, squeeze(resps(oo,ii,:)), fs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 for oo=1:NoutputsOut
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 y = squeeze(resps(NstatesOut+oo,ii,:));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 fsd = fsdata(f, y, fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 ao_out(NstatesOut+oo,ii).setData(fsd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 if ~callerIsMethod
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 % set names, units, description, and add history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 isysStr = sys.name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 for ii=1:Nin
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 for oo=1:NstatesOut
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 ao_out(oo,ii).setName( [sys.inputs(1).ports(ii).name '-->' sys.outputs(1).ports(oo).name]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 ao_out(oo,ii).setXunits('Hz');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 ao_out(oo,ii).setYunits( simplify(sys.outputs(1).ports(oo).units / sys.inputs(1).ports(ii).units));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 ao_out(oo,ii).setDescription(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 ['Bode of ' isysStr, ' from ', sys.inputs(1).ports(ii).description,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 ' to ' sys.outputs(1).ports(oo).description]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 for oo=1:NoutputsOut
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 ao_out(NstatesOut+oo,ii).setName( [sys.inputs(1).ports(ii).name '-->' sys.outputs(2).ports(oo).name]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 ao_out(NstatesOut+oo,ii).setXunits('Hz');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 ao_out(NstatesOut+oo,ii).setYunits( simplify(sys.outputs(2).ports(oo).units / sys.inputs(1).ports(ii).units));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 ao_out(NstatesOut+oo,ii).setDescription(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 ['Bode of ' isysStr, ' from ', sys.inputs(1).ports(ii).description,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 ' to ' sys.outputs(2).ports(oo).description]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 %% construct output matrix object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 out = matrix(ao_out);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 if callerIsMethod
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199 % do nothing
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 myinfo = getInfo('None');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 out.addHistory(myinfo, pl , ssm_invars(1), inhist );
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 %% Set output depending on nargout
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 if nargout == 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 varargout = {out};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 elseif nargout == 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 iplot(ao_out);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 error('Wrong number of outputs')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 % Get Info Object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 if nargin == 1 && strcmpi(varargin{1}, 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 sets = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 pl = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 sets = {'Default'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 pl = getDefaultPlist;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 % Build info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.sigproc, '$Id: bode.m,v 1.40 2011/04/17 21:28:05 adrien Exp $', sets, pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 % Get Default Plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 function pl = getDefaultPlist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 pl = ssm.getInfo('reorganize', 'for bode').plists;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 pl.remove('set');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 p = param({'f', 'A frequency vector (replaces f1, f2 and nf).'}, paramValue.EMPTY_DOUBLE) ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 p = param({'f2', 'The maximum frequency. Default is Nyquist or 1Hz.'}, paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 p = param({'f1', 'The minimum frequency. Default is f2*1e-5.'}, paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 p = param({'nf', 'The number of frequency bins.'}, paramValue.DOUBLE_VALUE(1000));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 p = param({'scale', 'Distribute frequencies on a ''log'' or ''lin'' scale.'}, {1, {'log', 'lin'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 p = param({'reorganize', 'When set to 0, this means the ssm does not need be modified to match the requested i/o. Faster but dangerous!'}, paramValue.TRUE_FALSE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 p = param({'numeric output', 'When set to ture, the output of bode will be purely numeric - no analysis objects.'}, paramValue.FALSE_TRUE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264
|