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