annotate scripts/control/nichols.m @ 3381:69b167451491

[project @ 1999-12-15 20:48:10 by jwe]
author jwe
date Wed, 15 Dec 1999 20:48:45 +0000
parents f7e4a95916f2
children d931332a73dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
1 ## Copyright (C) 1998 Auburn University. All Rights Reserved
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
2 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
3 ## This file is part of Octave.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
4 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
6 ## under the terms of the GNU General Public License as published by the
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
7 ## Free Software Foundation; either version 2, or (at your option) any
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
8 ## later version.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
9 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
13 ## for more details.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
14 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
15 ## You should have received a copy of the GNU General Public License
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
18
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
19 ## [mag,phase,w] = nichols(sys[,w,outputs,inputs])
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
20 ## Produce Nichols plot of a system
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
21 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
22 ## Compute the frequency response of a system.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
23 ## inputs:
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
24 ## sys: system data structure (must be either purely continuous or discrete;
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
25 # see is_digital)
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
26 ## w: frequency values for evaluation.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
27 ## if sys is continuous, then nichols evaluates G(jw)
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
28 ## if sys is discrete, then nichols evaluates G(exp(jwT)), where T=sys.tsam
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
29 ## (the system sampling time)
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
30 ## default: the default frequency range is selected as follows: (These
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
31 ## steps are NOT performed if w is specified)
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
32 ## (1) via routine bodquist, isolate all poles and zeros away from
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
33 ## w=0 (jw=0 or exp(jwT)=1) and select the frequency
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
34 ## range based on the breakpoint locations of the frequencies.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
35 ## (2) if sys is discrete time, the frequency range is limited
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
36 ## to jwT in [0,2p*pi]
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
37 ## (3) A "smoothing" routine is used to ensure that the plot phase does
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
38 ## not change excessively from point to point and that singular
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
39 ## points (e.g., crossovers from +/- 180) are accurately shown.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
40 ## outputs, inputs: the indices of the output(s) and input(s) to be used in
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
41 ## the frequency response; see sysprune.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
42 ## outputs:
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
43 ## mag, phase: the magnitude and phase of the frequency response
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
44 ## G(jw) or G(exp(jwT)) at the selected frequency values.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
45 ## w: the vector of frequency values used
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
46 ## If no output arguments are given, nichols plots the results to the screen.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
47 ## Descriptive labels are automatically placed. See xlabel, ylable, title,
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
48 ## and replot.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
49 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
50 ## Note: if the requested plot is for an MIMO system, mag is set to
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
51 ## ||G(jw)|| or ||G(exp(jwT))|| and phase information is not computed.
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
52
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
53 function [mag,phase,w] = nichols(sys,w,outputs,inputs)
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
54
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
55 ## check number of input arguments given
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
56 if (nargin < 1 | nargin > 4)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
57 usage("[mag,phase,w] = nichols(sys[,w,outputs,inputs])");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
58 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
59 if(nargin < 2)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
60 w = [];
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
61 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
62 if(nargin < 3)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
63 outputs = [];
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
64 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
65 if(nargin < 4)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
66 inputs = [];
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
67 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
68
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
69 [f, w] = bodquist(sys,w,outputs,inputs,"nichols");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
70
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
71 [stname,inname,outname] = sysgetsignals(sys);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
72 systsam = sysgettsam(sys);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
73
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
74 ## Get the magnitude and phase of f.
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
75 mag = abs(f);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
76 phase = arg(f)*180.0/pi;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
77
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
78 if (nargout < 1),
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3284
diff changeset
79 ## Plot the information
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
80 if(gnuplot_has_multiplot)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
81 oneplot();
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
82 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
83 gset autoscale;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
84 if(gnuplot_has_multiplot)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
85 gset nokey;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
86 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
87 clearplot();
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
88 grid("on");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
89 gset data style lines;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
90 if(is_digital(sys))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
91 tistr = "(exp(jwT)) ";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
92 else
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
93 tistr = "(jw)";
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
94 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
95 xlabel("Phase (deg)");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
96 if(is_siso(sys))
3229
28aba52a2368 [project @ 1998-12-10 03:06:31 by jwe]
jwe
parents: 3228
diff changeset
97 title(["Nichols plot of |[Y/U]",tistr,"|, u=", ...
28aba52a2368 [project @ 1998-12-10 03:06:31 by jwe]
jwe
parents: 3228
diff changeset
98 sysgetsignals(sys,"in",1,1), ", y=",sysgetsignals(sys,"out",1,1)]);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
99 else
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
100 title([ "||Y(", tistr, ")/U(", tistr, ")||"]);
3229
28aba52a2368 [project @ 1998-12-10 03:06:31 by jwe]
jwe
parents: 3228
diff changeset
101 printf("MIMO plot from\n%s\nto\n%s\n",outlist(inname," "), ...
28aba52a2368 [project @ 1998-12-10 03:06:31 by jwe]
jwe
parents: 3228
diff changeset
102 outlist(outname," "));
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
103 endif
3236
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
104 if(max(mag) > 0)
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
105 ylabel("Gain in dB");
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
106 md = 20*log10(mag);
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
107 else
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
108 ylabel("Gain |Y/U|")
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
109 md = mag;
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
110 endif
98e15955107e [project @ 1999-03-05 07:17:10 by jwe]
jwe
parents: 3229
diff changeset
111
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
112 axvec = axis2dlim([vec(phase),vec(md)]);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
113 axis(axvec);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
114 plot(phase,md);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
115 mag = phase = w = [];
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
116 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
117 endfunction