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