annotate scripts/control/base/nichols.m @ 6448:2110cc251779

[project @ 2007-03-24 02:47:36 by jwe]
author jwe
date Sat, 24 Mar 2007 02:47:36 +0000
parents 34f96dd5441b
children 9483da8d87e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1998 Auburn University. All rights reserved.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
2 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
4 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by the
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
7 ## Free Software Foundation; either version 2, or (at your option) any
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
8 ## later version.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
9 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
13 ## for more details.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
14 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5215
diff changeset
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5215
diff changeset
18 ## 02110-1301 USA.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
19
3451
a6cc6bc220b3 [project @ 2000-01-18 04:49:49 by jwe]
jwe
parents: 3438
diff changeset
20 ## -*- texinfo -*-
a6cc6bc220b3 [project @ 2000-01-18 04:49:49 by jwe]
jwe
parents: 3438
diff changeset
21 ## @deftypefn {Function File} {[@var{mag}, @var{phase}, @var{w}] =} nichols (@var{sys}, @var{w}, @var{outputs}, @var{inputs})
a6cc6bc220b3 [project @ 2000-01-18 04:49:49 by jwe]
jwe
parents: 3438
diff changeset
22 ## Produce Nichols plot of a system.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
23 ##
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
24 ## @strong{Inputs}
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
25 ## @table @var
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
26 ## @item sys
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
27 ## System data structure (must be either purely continuous or discrete;
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
28 ## see @command{is_digital}).
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
29 ## @item w
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
30 ## Frequency values for evaluation.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
31 ## @itemize
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
32 ## @item if sys is continuous, then nichols evaluates @math{G(jw)}.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
33 ## @item if sys is discrete, then nichols evaluates @math{G(exp(jwT))},
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
34 ## where @var{T}=@var{sys}. @var{tsam} is the system sampling time.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
35 ## @item the default frequency range is selected as follows (These
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
36 ## steps are @strong{not} performed if @var{w} is specified):
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
37 ## @enumerate
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
38 ## @item via routine @command{__bodquist__}, isolate all poles and zeros away from
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
39 ## @var{w}=0 (@math{jw=0} or @math{exp(jwT)=1}) and select the frequency range
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
40 ## based on the breakpoint locations of the frequencies.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
41 ## @item if sys is discrete time, the frequency range is limited to jwT in
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
42 ## @iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
43 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
44 ## $ [0, 2p\pi] $.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
45 ## @end tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
46 ## @end iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
47 ## @ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
48 ## [0,2p*pi].
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
49 ## @end ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
50 ## @item A ``smoothing'' routine is used to ensure that the plot phase does
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
51 ## not change excessively from point to point and that singular points
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
52 ## (e.g., crossovers from +/- 180) are accurately shown.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
53 ## @end enumerate
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
54 ## @end itemize
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
55 ## @item outputs
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
56 ## @itemx inputs
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
57 ## the names or indices of the output(s) and input(s) to be used in the
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
58 ## frequency response; see @command{sysprune}.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
59 ## @end table
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
60 ## @strong{Outputs}
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
61 ## @table @var
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
62 ## @item mag
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
63 ## @itemx phase
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
64 ## The magnitude and phase of the frequency response @math{G(jw)} or
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
65 ## @math{G(exp(jwT))} at the selected frequency values.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
66 ## @item w
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
67 ## The vector of frequency values used.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
68 ## @end table
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
69 ## If no output arguments are given, @command{nichols} plots the results to the screen.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
70 ## Descriptive labels are automatically placed. See @command{xlabel},
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
71 ## @command{ylabel}, and @command{title}.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
72 ##
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
73 ## Note: if the requested plot is for an @acronym{MIMO} system, @var{mag} is set to
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
74 ## @iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
75 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
76 ## $ \Vert G(jw) \Vert $ or $ \Vert G( {\rm exp}(jwT) \Vert $
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
77 ## @end tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
78 ## @end iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
79 ## @ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
80 ## ||G(jw)|| or ||G(exp(jwT))||
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
81 ## @end ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4422
diff changeset
82 ## and phase information is not computed.
3451
a6cc6bc220b3 [project @ 2000-01-18 04:49:49 by jwe]
jwe
parents: 3438
diff changeset
83 ## @end deftypefn
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
84
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
85 function [mag, phase, w] = nichols (sys, w, outputs, inputs)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
86
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
87 ## check number of input arguments given
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
88 if (nargin < 1 || nargin > 4)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
89 print_usage ();
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
90 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
91 if (nargin < 2)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
92 w = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
93 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
94 if (nargin < 3)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
95 outputs = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
96 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
97 if (nargin < 4)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
98 inputs = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
99 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
100
3455
f758be6e1730 [project @ 2000-01-18 19:57:12 by hodelas]
hodelas
parents: 3451
diff changeset
101 [f, w, sys] = __bodquist__ (sys, w, outputs, inputs, "nichols");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
102
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
103 [stname,inname,outname] = sysgetsignals (sys);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
104 systsam = sysgettsam (sys);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
105
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
106 ## Get the magnitude and phase of f.
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
107 mag = abs (f);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
108 phase = arg (f)*180.0/pi;
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
109
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
110 if (nargout < 1),
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
111 ## Plot the information
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
112
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
113 if (max (mag) > 0)
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
114 plot (phase, 20 * log10 (mag));
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
115 ylabel ("Gain in dB");
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
116 else
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
117 plot (phase, mag);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
118 ylabel ("Gain |Y/U|")
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
119 endif
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
120
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
121 grid ("on");
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
122
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
123 if (is_digital (sys))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
124 tistr = "(exp(jwT)) ";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
125 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
126 tistr = "(jw)";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
127 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
128
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
129 xlabel ("Phase (deg)");
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
130
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
131 if (is_siso (sys))
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
132 title (sprintf ("Nichols plot of |[Y/U]%s|, u=%s, y=%s", tistr,
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
133 sysgetsignals (sys, "in", 1, 1),
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
134 sysgetsignals (sys, "out", 1, 1));
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
135 else
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
136 title ([ "||Y(", tistr, ")/U(", tistr, ")||"]);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
137 printf ("MIMO plot from\n%s\nto\n%s\n", __outlist__ (inname, " "),
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
138 __outlist__ (outname, " "));
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
139 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
140
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
141 axis (axis2dlim ([phase(:), md(:)]));
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
142
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
143 mag = phase = w = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
144 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
145
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
146 endfunction