3431
|
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by the |
|
7 ## Free Software Foundation; either version 2, or (at your option) any |
|
8 ## later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 ## for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} frdemo () |
|
21 ## Octave Controls toolbox demo: Frequency Response demo |
|
22 ## @end deftypefn |
|
23 |
|
24 ## Author: David Clem |
|
25 ## Created: August 15, 1994 |
|
26 ## a s hodel: updated to match new order of ss2zp outputs |
|
27 ## J Ingram: updated for system data structure format August 1996 |
|
28 |
|
29 function frdemo () |
|
30 |
|
31 disp("") |
|
32 clc |
|
33 j = 0; |
|
34 while (j != 4) |
|
35 disp(""); |
|
36 j = menu("Octave Controls Systems Toolbox Frequency Response Demo", |
|
37 "Bode analysis (bode)", |
|
38 "Nyquist analysis (nyquist)", |
|
39 "Nichols analysis (nichols)", |
|
40 "Return to main demo menu"); |
|
41 |
|
42 if (j == 1) |
|
43 k1 = 0; |
|
44 while (k1 != 4) |
|
45 disp("\n"); |
|
46 clc |
|
47 |
|
48 k1 = menu("Bode analysis (bode)", |
|
49 "Continuous system bode analysis", |
|
50 "Discrete system bode analysis", |
|
51 "Bode command description", |
|
52 "Return to frdemo menu"); |
|
53 |
|
54 if( k1 == 1 ) |
|
55 disp(" ") |
|
56 clc |
|
57 disp("\nContinuous system bode analysis\n"); |
|
58 disp("Example #1:") |
|
59 disp("\nConsider the system sys1="); |
|
60 sys1=tf2sys([1, 1], [1, 0, -1]); |
|
61 sysout(sys1); |
|
62 disp("\nPole-zero form can be obtained as follows:") |
|
63 cmd = "sysout(sys1,""zp"");"; |
|
64 run_cmd; |
|
65 disp("The systems bode plot is obtained as follows:"); |
|
66 cmd = "bode(sys1);"; |
|
67 run_cmd; |
|
68 disp("\nNotice that bode automatically labels the plots according to") |
|
69 disp("the selected input/output combinations.") |
|
70 disp(" ") |
|
71 disp("If the frequency range is not specified, bode automatically") |
|
72 disp("selects a frequency range based on the natural frequencies of") |
|
73 disp("of all poles away from s=0 (or z=1 in discrete time). Bode") |
|
74 disp("then checks to make sure that the phase plot is sufficiently") |
|
75 disp("smooth that relevant plot behavior is captured.") |
|
76 disp("") |
|
77 disp("Bode exits with an error if the system is mixed (both continuous") |
|
78 disp("and discrete; see is_digital for conditions)") |
|
79 prompt |
|
80 disp("\nIf the plot magnitude, phase and frequency data is desired, the"); |
|
81 disp("user can enter the following command:"); |
|
82 disp("\n[Mag,Phase,w] = bode(sys);"); |
|
83 disp("\nThis will return three vectors containing the magnitude,"); |
|
84 disp("phase and frequency.\n"); |
|
85 prompt; |
|
86 |
|
87 disp("") |
|
88 clc |
|
89 disp("Example #2, sys2=") |
|
90 cmd = "sys2=zp2sys(1, [-1, -5], 10);"; |
|
91 eval(cmd); |
|
92 cmd = "sysout(sys2);"; |
|
93 eval(cmd); |
|
94 disp("\nThe bode plot command is identical to the tf form:") |
|
95 cmd = "bode(sys2);"; |
|
96 run_cmd; |
|
97 disp("\nThe internal representation of the system is not important;") |
|
98 disp("bode automatically sorts it out internally.") |
|
99 prompt; |
|
100 |
|
101 disp("") |
|
102 clc |
|
103 disp("Example #3, Consider the following state space system sys3=:\n"); |
|
104 cmd = "sys3=ss2sys([0, 1; -1000, -1001], [0; 1], [0, -891], 1);"; |
|
105 eval(cmd); |
|
106 cmd = "sysout(sys3);"; |
|
107 eval(cmd); |
|
108 disp("\nOnce again, the bode plot command is the same:"); |
|
109 cmd = "bode(sys3);"; |
|
110 run_cmd; |
|
111 disp("\nSuppose the user is interested in the response of the system"); |
|
112 disp("defined over the input frequency range of 1 - 1000 rad/s.\n"); |
|
113 disp("First, a frequency vector is required. It can be created"); |
|
114 disp("with the command:\n"); |
|
115 cmd = "wrange = logspace(log10(1),log10(1000),100);"; |
|
116 disp(cmd); |
|
117 eval(cmd); |
|
118 disp("\nThis creates a logarithmically scaled frequency vector with"); |
|
119 disp("100 values between 1 and 1000 rad/s\n"); |
|
120 disp("Then, the bode command includes wrange in the input arguments"); |
|
121 disp("like this:"); |
|
122 cmd = "bode(sys3,wrange);"; |
|
123 run_cmd; |
|
124 prompt; |
|
125 |
|
126 disp("") |
|
127 clc |
|
128 disp("\nExample #4, The state-space system from example 3 will be"); |
|
129 disp("grouped with the system from example 2 to form a MIMO system"); |
|
130 disp("The commands to do this grouping are as follows (changing signal"); |
|
131 disp("names for clarity):"); |
|
132 cmd = "sys2 = syssetsignals(sys2,\"out\",\"y_sys2\");"; |
|
133 disp(cmd); eval(cmd); |
|
134 cmd = "sys2 = syssetsignals(sys2,\"in\",\"u_sys2\");"; |
|
135 disp(cmd); eval(cmd); |
|
136 cmd = "nn = sysdimensions(sys2);"; |
|
137 disp(cmd); eval(cmd); |
|
138 cmd = "[nn,nz] = sysdimensions(sys2);"; |
|
139 disp(cmd); eval(cmd); |
|
140 cmd = "sys2 = syssetsignals(sys2,\"st\",sysdefioname(nn+nz,\"x_sys2\"));"; |
|
141 disp(cmd); eval(cmd); |
|
142 cmd = "sys_mimo = sysgroup(sys2,sys3);"; |
|
143 disp(cmd); eval(cmd); |
|
144 disp("The resulting state-space system (after changing signal names"); |
|
145 disp("in sys2) is"); |
|
146 cmd = "sysout(sys_mimo)"; |
|
147 eval(cmd); |
|
148 disp("\nNotice that there are now 2 inputs and 2 outputs, and that it did"); |
|
149 disp("not matter what form the two systems were in when they were grouped."); |
|
150 disp(["\nTo view the system's bode plots, execute the", |
|
151 " following command:\n"]) |
|
152 cmd = "bode(sys_mimo);"; |
|
153 run_cmd; |
|
154 prompt |
|
155 disp("\nTo view the bode plots for selected channels, the command form changes:") |
|
156 cmd = "wrange = [];"; |
|
157 disp(cmd) |
|
158 eval(cmd); |
|
159 cmd = "out = 1;"; |
|
160 disp(cmd) |
|
161 eval(cmd); |
|
162 cmd = "in = 1;"; |
|
163 disp(cmd) |
|
164 eval(cmd); |
|
165 cmd = "bode(sys_mimo,wrange,out,in);"; |
|
166 run_cmd; |
|
167 disp("\nNotice that this bode plot is the same as the plot from example 2."); |
|
168 prompt |
|
169 closeplot |
|
170 |
|
171 elseif( k1 == 2 ) |
|
172 disp("") |
|
173 clc |
|
174 disp("\nDiscrete system bode analysis\n"); |
|
175 disp("Display bode plots of a discrete SISO system (dbode)\n") |
|
176 disp("Example #1, Consider the following discrete transfer"); |
|
177 disp(" function:\n"); |
|
178 cmd = "sys1 = tf2sys([0.00100502, -0.00099502], [1, -2, 1], 0.001);"; |
|
179 disp(cmd); |
|
180 eval(cmd); |
|
181 cmd = "sysout(sys1)"; |
|
182 disp(cmd); |
|
183 eval(cmd); |
|
184 disp("\nTo examine open loop zeros and poles of the system,"); |
|
185 disp("use the command:\n") |
|
186 cmd = "sysout(sys1,""zp"");"; |
|
187 run_cmd; |
|
188 disp("\nTo view the system's bode plots, execute the following"); |
|
189 disp("command:\n") |
|
190 cmd = "bode(sys1);"; |
|
191 run_cmd; |
|
192 disp("\nNotice (1) the plot label uses exp(jwT) for its title axis. This") |
|
193 disp(" allows the user to determine what kind of system was") |
|
194 disp(" used to generate the bode plot"); |
|
195 disp(" (2) the system poles are both at z=1, (break frequency at") |
|
196 disp(" jwT = 0); pure integrator poles like this are discarded") |
|
197 disp(" by Octave when computing the plot frequency range.") |
|
198 |
|
199 disp("\nIf magnitude, phase, and frequency data are also desired,"); |
|
200 disp(" perform the following command instead:\n"); |
|
201 disp("[M,P,w]=dbode(num,den,T,wrange).\n Where:"); |
|
202 disp("M => Bode magnitude response data"); |
|
203 disp("P => Bode phase response data"); |
|
204 disp("w => frequencies that M and P were evaluated at"); |
|
205 disp("sys1 => system data structure") |
|
206 disp("T => sample period") |
|
207 disp("wrange => optional vector of frequencies") |
|
208 disp(" if wrange is entered in the argument list, the"); |
|
209 disp(" system will be evaluated at these specific"); |
|
210 disp(" frequencies\n"); |
|
211 |
|
212 prompt |
|
213 disp("") |
|
214 clc |
|
215 disp("Example #2, Consider the following set of discrete poles and"); |
|
216 disp("zeros:\n") |
|
217 cmd = "sys2 = zp2sys([0.99258;0.99745],[0.99961;0.99242],1,0.001);"; |
|
218 disp(cmd); |
|
219 eval(cmd); |
|
220 cmd = "sysout(sys2)"; |
|
221 disp(cmd); |
|
222 eval(cmd); |
|
223 disp("\nTo view the system's bode plots, execute the following"); |
|
224 disp("command:\n") |
|
225 cmd = "bode(sys2);"; |
|
226 run_cmd; |
|
227 disp("Notice that the bode command is the same in both of the previous"); |
|
228 disp("examples. The bode command is also the same for the continuous case."); |
|
229 disp("The function, dbode, is no longer used."); |
|
230 |
|
231 prompt |
|
232 disp("") |
|
233 clc |
|
234 disp("\nExample #3, Now consider the following state space system:\n"); |
|
235 cmd = "sys3 = ss2sys([.857, .0011; 0, .99930],[1;1],[-.6318, .0057096],5.2, .001);"; |
|
236 disp(cmd); |
|
237 eval(cmd); |
|
238 cmd = "sysout(sys3);"; |
|
239 disp(cmd); |
|
240 eval(cmd); |
|
241 disp("\nTo view the system's bode plots, execute the following command:\n") |
|
242 cmd = "bode(sys3);"; |
|
243 run_cmd; |
|
244 disp("\nAgain, notice that the bode command is the same regardless of the form"); |
|
245 disp("of the system."); |
|
246 disp("\nSuppose the user is interested in the response of the system"); |
|
247 disp("defined over the input frequency range of 1 - 1000 rad/s.\n"); |
|
248 disp("First, a frequency vector is required. It can be created"); |
|
249 disp("with the command:\n"); |
|
250 cmd = "wrange = logspace(log10(1),log10(1000),100);"; |
|
251 disp(cmd); |
|
252 eval(cmd); |
|
253 disp("\nThis creates a logrithmetically scaled frequency vector with"); |
|
254 disp("100 values between 1 and 1000 rad/s\n"); |
|
255 disp("Then, the bode command includes wrange in the input arguments"); |
|
256 disp("like this:"); |
|
257 cmd = "bode(sys3,wrange);"; |
|
258 run_cmd; |
|
259 prompt; |
|
260 |
|
261 disp("") |
|
262 clc |
|
263 disp("\nExample #4, We will now examine a MIMO state-space system. Systems"); |
|
264 disp("two and three will be grouped."); |
|
265 cmd = "[nn,nz] = sysdimensions(sys2);"; |
|
266 disp(cmd); eval(cmd); |
|
267 cmd = "sys2 = syssetsignals(sys2,\"out\",\"y_sys2\");"; |
|
268 disp(cmd); eval(cmd); |
|
269 cmd = "sys2 = syssetsignals(sys2,\"in\",\"u_sys2\");"; |
|
270 disp(cmd); eval(cmd); |
|
271 cmd = "sys2 = syssetsignals(sys2,\"st\",sysdefioname(nn+nz,\"x_sys2\"));"; |
|
272 disp(cmd); eval(cmd); |
|
273 cmd = "sys_mimo = sysgroup(sys2,sys3);"; |
|
274 disp(cmd); eval(cmd); |
|
275 cmd = "sysout(sys_mimo);"; |
|
276 disp(cmd); |
|
277 eval(cmd); |
|
278 disp("\nTo view the system's bode plots, execute the following command:\n") |
|
279 cmd = "bode(sys_mimo);"; |
|
280 run_cmd; |
|
281 prompt |
|
282 |
|
283 disp("\nThe bode plot of a single channel is viewed as follows:") |
|
284 cmd = "wrange = [];"; |
|
285 disp(cmd) |
|
286 eval(cmd); |
|
287 cmd = "out = 1;"; |
|
288 disp(cmd) |
|
289 eval(cmd); |
|
290 cmd = "in = 1;"; |
|
291 disp(cmd) |
|
292 eval(cmd); |
|
293 cmd = "bode(sys_mimo,wrange,out,in);"; |
|
294 run_cmd; |
|
295 disp("\nNotice that this bode plot is the same as the plot from example 2."); |
|
296 prompt |
|
297 closeplot |
|
298 |
|
299 elseif( k1 == 3 ) |
|
300 help bode |
|
301 prompt |
|
302 endif |
|
303 endwhile |
|
304 elseif (j == 2) |
|
305 k2 = 0; |
|
306 disp(""); |
|
307 while (k2 != 4) |
|
308 disp("\n"); |
|
309 help nyquist |
|
310 prompt; |
|
311 disp("") |
|
312 clc; |
|
313 |
|
314 k2 = menu("Nyquist analysis (Nyquist)", |
|
315 "Continuous system nyquist analysis", |
|
316 "Discrete system nyquist analysis", |
|
317 "Mixed system nyquist analysis", |
|
318 "Return to frdemo menu"); |
|
319 |
|
320 if( k2 == 1 ) |
|
321 disp("") |
|
322 clc |
|
323 disp("\nContinuous system nyquist analysis\n"); |
|
324 disp("Display Nyquist plots of a SISO system (nyquist)\n") |
|
325 disp("Example #1, Consider the following transfer function:\n") |
|
326 cmd = "sys1 = tf2sys(1, [1, 0.8, 1]);"; |
|
327 disp(cmd); |
|
328 eval(cmd); |
|
329 disp("To examine the transfer function, use the command:"); |
|
330 cmd = "sysout(sys1);"; |
|
331 disp(cmd); |
|
332 eval(cmd); |
|
333 disp("\nTo examine the open loop zeros and poles, use the command:"); |
|
334 cmd = "sysout(sys1,""zp"");"; |
|
335 run_cmd; |
|
336 disp("\nTo view the system""s nyquist plot, execute the following"); |
|
337 disp("command:\n") |
|
338 cmd = "nyquist(sys1);"; |
|
339 run_cmd; |
|
340 disp("\nIf the real and imaginary parts of the response are desired,"); |
|
341 disp("use the following command:"); |
|
342 disp("command: [R,I,w]=nyquist(sys1);\n"); |
|
343 disp("If the user desires to evaluate the response in a certain"); |
|
344 disp("frequency range, he may do so by entering the following:"); |
|
345 disp("command: [M,P,w]=nyquist(num,den,wrange).\n") |
|
346 disp("wrange is a vector of frequencies that spans the desired"); |
|
347 disp("viewing range.\n"); |
|
348 disp("This will be illustrated in the third nyquist example.\n") |
|
349 disp("Variable Description:\n") |
|
350 disp("R => real part of response") |
|
351 disp("I => imaginary part of response") |
|
352 disp("w => frequencies that the transfer function was evaluated at") |
|
353 disp("sys1 => system data structure") |
|
354 disp("wrange => optional vector of frequencies") |
|
355 disp(" if wrange is entered in the argument list, the"); |
|
356 disp(" system will be evaluated at these specific"); |
|
357 disp(" frequencies\n") |
|
358 prompt |
|
359 |
|
360 disp("") |
|
361 clc |
|
362 disp("Example #2, Consider the following set of poles and zeros:\n") |
|
363 cmd = "sys2 = zp2sys([-1;-4],[-2+1.4142i;-2-1.4142i],1);"; |
|
364 disp(cmd); |
|
365 eval(cmd); |
|
366 disp("\nTo examine the poles and zeros, use the command:"); |
|
367 cmd = "sysout(sys2)"; |
|
368 disp(cmd); |
|
369 eval(cmd); |
|
370 disp("\nTo view the system""s nyquist plot, execute the following"); |
|
371 disp("command:\n") |
|
372 cmd = "nyquist(sys2);"; |
|
373 run_cmd; |
|
374 prompt |
|
375 |
|
376 disp("") |
|
377 clc |
|
378 disp("\nExample #3, Consider the following state space system:\n") |
|
379 cmd = "sys3 = ss2sys([0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1; 0, 0, -20, -12],[0;0;0;1],[50, 100, 0, 0],0);"; |
|
380 disp(cmd); |
|
381 eval(cmd); |
|
382 disp("\nTo examine the state-space system, use the command:"); |
|
383 cmd = "sysout(sys3)"; |
|
384 disp(cmd); |
|
385 eval(cmd); |
|
386 disp("\nTo examine the poles and zeros, use the command:"); |
|
387 cmd = "sysout(sys3,""zp"")"; |
|
388 run_cmd; |
|
389 disp("\nTo view the system""s nyquist plot, execute the following"); |
|
390 disp("commands:\n") |
|
391 cmd = "nyquist(sys3);"; |
|
392 run_cmd; |
|
393 prompt |
|
394 |
|
395 disp("Example #3 (continued), If the user wishes to evaluate the"); |
|
396 disp("system response over a desired frequency range, he must first"); |
|
397 disp("create a frequency vector.\n") |
|
398 disp("For example, suppose the user is interested in the response"); |
|
399 disp("of the system defined above over input frequency range of"); |
|
400 disp("3 - 100 rad/s.\n") |
|
401 disp("A frequency vector can be created using the command:\n"); |
|
402 cmd = "wrange = logspace(log10(3),log10(100),100);"; |
|
403 disp(cmd); |
|
404 eval(cmd); |
|
405 disp("\nNyquist can be run again using the frequency vector as"); |
|
406 disp("follows:\n") |
|
407 cmd = "nyquist(sys3,wrange);"; |
|
408 run_cmd; |
|
409 prompt |
|
410 |
|
411 disp("") |
|
412 clc |
|
413 disp("Example #4, Nyquist can be used for MIMO systems if the system has"); |
|
414 disp("an equal number of inputs and outputs. Otherwise, nyquist returns"); |
|
415 disp("an error. To examine a MIMO system, systems 2 and 3 will be grouped"); |
|
416 cmd = "[nn,nz] = sysdimensions(sys2);"; |
|
417 disp(cmd); eval(cmd); |
|
418 cmd = "sys2 = syssetsignals(sys2,\"out\",\"y_sys2\");"; |
|
419 disp(cmd); eval(cmd); |
|
420 cmd = "sys2 = syssetsignals(sys2,\"in\",\"u_sys2\");"; |
|
421 disp(cmd); eval(cmd); |
|
422 cmd = "sys2 = syssetsignals(sys2,\"st\",sysdefioname(nn+nz,\"x_sys2\"));"; |
|
423 disp(cmd); eval(cmd); |
|
424 cmd = "sys_mimo = sysgroup(sys2,sys3);"; |
|
425 disp(cmd); eval(cmd); |
|
426 cmd = "sysout(sys_mimo);"; |
|
427 disp(cmd); |
|
428 eval(cmd); |
|
429 disp("\nTo view the system's nyquist plot, execute the following command:\n") |
|
430 cmd = "nyquist(sys_mimo);"; |
|
431 run_cmd; |
|
432 prompt |
|
433 disp("\nTo view the nyquist plots for selected channels, the command form changes:") |
|
434 cmd = "nyquist(sys_mimo,[],1,1);"; |
|
435 run_cmd; |
|
436 disp("\nNotice that this bode plot is the same as the plot from example 2."); |
|
437 prompt |
|
438 closeplot |
|
439 |
|
440 |
|
441 |
|
442 elseif( k2 == 2 ) |
|
443 disp("") |
|
444 clc |
|
445 disp("\nDiscrete system nyquist analysis\n"); |
|
446 disp("Display Nyquist plots of a discrete SISO system (nyquist)\n") |
|
447 disp("We will first define a sampling time, T"); |
|
448 cmd = "T = 0.01;"; |
|
449 disp(cmd); |
|
450 eval(cmd); |
|
451 disp("\nExample #1, Consider the following transfer function:\n") |
|
452 cmd = "sys1 = tf2sys([2, -3.4, 1.5],[1, -1.6, 0.8],T);"; |
|
453 disp(cmd); |
|
454 eval(cmd); |
|
455 disp("To examine the transfer function, use the command:"); |
|
456 cmd = "sysout(sys1);"; |
|
457 disp(cmd); |
|
458 eval(cmd); |
|
459 disp("\nTo examine the open loop zeros and poles, use the command:"); |
|
460 cmd = "sysout(sys1,""zp"")"; |
|
461 disp(cmd); |
|
462 eval(cmd); |
|
463 disp("\nTo view the system""s nyquist plot, execute the following"); |
|
464 disp("command:") |
|
465 cmd = "nyquist(sys1);"; |
|
466 run_cmd; |
|
467 disp("To change the range used for the frequency, a frequency"); |
|
468 disp("is needed. Suppose the user would like to examine the"); |
|
469 disp("nyquist plot in the frequency range of 0.01 - 31.6 rad/s."); |
|
470 disp("\nThe frequency vector needed to do this is created with the"); |
|
471 disp("command:"); |
|
472 cmd = "wrange = logspace(-2,1.5,200);"; |
|
473 disp(cmd); |
|
474 eval(cmd); |
|
475 disp("\nNyquist can be run again with this frequency vector"); |
|
476 cmd = "nyquist(sys1,wrange);"; |
|
477 run_cmd; |
|
478 disp("\nIf the real and imaginary parts of the response are desired,"); |
|
479 disp("perform the following command:\n"); |
|
480 disp("[R,I,w]=nyquist(sys,wrange)\n") |
|
481 disp("Variable Description:\n") |
|
482 disp("R => real part of response") |
|
483 disp("I => imaginary part of response") |
|
484 disp("w => frequencies that the transfer function was evaluated at") |
|
485 disp("sys => The system data structure"); |
|
486 disp("wrange => optional vector of frequencies") |
|
487 disp(" if wrange is entered in the argument list, the"); |
|
488 disp(" system will be evaluated at these specific"); |
|
489 prompt |
|
490 |
|
491 disp("") |
|
492 clc |
|
493 disp("\nExample #2, Consider the following set of poles and zeros:\n") |
|
494 cmd = "sys2 = zp2sys([0.98025 + 0.01397i; 0.98025 - 0.01397i],[0.96079;0.99005],1,T);"; |
|
495 disp(cmd); |
|
496 eval(cmd); |
|
497 disp("\nTo examine the open loop zeros and poles, use the command:"); |
|
498 cmd = "sysout(sys2)"; |
|
499 disp(cmd); |
|
500 eval(cmd); |
|
501 disp("\nTo view the system's nyquist plot between the frequencies"); |
|
502 disp("0.01 - 100 rad/s, execute the following commands:\n") |
|
503 cmd = "wrange = logspace(-2,2,100);"; |
|
504 disp(cmd); |
|
505 eval(cmd); |
|
506 cmd = "nyquist(sys2,wrange);"; |
|
507 run_cmd; |
|
508 prompt; |
|
509 |
|
510 disp("") |
|
511 clc |
|
512 disp("\nExample #3, Consider the following discrete state space"); |
|
513 disp("system:\n"); |
|
514 disp("This example will use the same system used in the third"); |
|
515 disp("example in the continuous nyquist demo. First, that system"); |
|
516 disp("will have to be re-entered useing the following commands:\n"); |
|
517 cmd = "sys3 = ss2sys([0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1; 0, 0, -20, -12],[0;0;0;1],[50, 100, 0, 0],0);"; |
|
518 disp(cmd); |
|
519 eval(cmd); |
|
520 disp("\nTo examine the state-space system, use the command:"); |
|
521 cmd = "sysout(sys3)"; |
|
522 disp(cmd); |
|
523 eval(cmd); |
|
524 disp("\nTo examine the poles and zeros, use the command:"); |
|
525 cmd = "sysout(sys3,""zp"")"; |
|
526 disp(cmd); |
|
527 eval(cmd); |
|
528 disp("\nTo convert the system to discrete time, we need a sampling"); |
|
529 disp("time which can be entered like this:"); |
|
530 cmd = "T = 0.01"; |
|
531 disp(cmd); |
|
532 eval(cmd); |
|
533 disp("\nNow the command, c2d, is used to convert the system from"); |
|
534 disp("continuous to discrete time, with the following command"); |
|
535 cmd = "dsys3 = c2d(sys3,T);"; |
|
536 run_cmd; |
|
537 disp("\nTo examine the new discrete state-space system, use the"); |
|
538 disp("command"); |
|
539 cmd = "sysout(dsys3);"; |
|
540 disp(cmd); |
|
541 eval(cmd); |
|
542 disp("\nTo examine the new discrete poles and zeros, use the command:"); |
|
543 cmd = "sysout(dsys3,""zp"")"; |
|
544 disp(cmd); |
|
545 eval(cmd); |
|
546 disp("\nTo view the system's nyquist plot, execute the following"); |
|
547 disp("commands:\n"); |
|
548 cmd = "gset xrange [-4:2];"; |
|
549 disp(cmd); eval(cmd); |
|
550 cmd = "gset yrange [-2.5:2.5];"; |
|
551 disp(cmd); eval(cmd); |
|
552 cmd = "nyquist(dsys3);"; |
|
553 run_cmd; |
|
554 disp("Notice that the asymptotes swamp out the behavior of the plot") |
|
555 disp("near the origin. You may use interactive nyquist plots") |
|
556 disp("to \"zoom in\" on a plot as follows:") |
|
557 |
|
558 cmd = "atol = 1;"; |
|
559 disp(cmd) |
|
560 eval(cmd) |
|
561 cmd = "nyquist(dsys3,[],[],[],atol);"; |
|
562 run_cmd |
|
563 prompt |
|
564 |
|
565 |
|
566 disp("") |
|
567 clc |
|
568 disp("MIMO SYSTEM: Nyquist cannot be used for discrete MIMO systems"); |
|
569 disp("at this time."); |
|
570 ## cmd = "dsys_mimo = sysgroup(sys2,dsys3);"; |
|
571 ## disp(cmd); |
|
572 ## eval(cmd); |
|
573 ## cmd = "sysout(dsys_mimo);"; |
|
574 ## disp(cmd); |
|
575 ## eval(cmd); |
|
576 ## disp("\nTo view the system's nyquist plot, execute the following command:\n") |
|
577 ## cmd = "nyquist(dsys_mimo);"; |
|
578 ## run_cmd; |
|
579 ## prompt |
|
580 ## disp("\nTo view the nyquist plots for selected channels, the command form changes:") |
|
581 ## cmd = "nyquist(dsys_mimo,[],1,1);"; |
|
582 ## run_cmd; |
|
583 ## disp("\nNotice that this bode plot is the same as the plot from example 2."); |
|
584 prompt |
|
585 closeplot |
|
586 |
|
587 |
|
588 elseif( k2 == 3 ) |
|
589 disp("\nMixed system nyquist analysis\n"); |
|
590 disp("Nyquist exits with an error if it is passed a ""mixed"" system (one") |
|
591 disp("with both continuous and discrete states). Use c2d or d2c to") |
|
592 disp("convert the system to either pure digital or pure continuous form"); |
|
593 endif |
|
594 endwhile |
|
595 elseif (j == 3) |
|
596 help nichols |
|
597 prompt |
|
598 endif |
|
599 endwhile |
|
600 |
|
601 endfunction |