3431
|
1 ## Copyright (C) 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 |
3451
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {[@var{mag}, @var{phase}, @var{w}] =} nichols (@var{sys}, @var{w}, @var{outputs}, @var{inputs}) |
|
21 ## Produce Nichols plot of a system. |
3431
|
22 ## |
|
23 ## inputs: |
|
24 ## sys: system data structure (must be either purely continuous or discrete; |
|
25 ## see is_digital) |
|
26 ## w: frequency values for evaluation. |
|
27 ## if sys is continuous, then nichols evaluates G(jw) |
|
28 ## if sys is discrete, then nichols evaluates G(exp(jwT)), where T=sys.tsam |
|
29 ## (the system sampling time) |
|
30 ## default: the default frequency range is selected as follows: (These |
|
31 ## steps are NOT performed if w is specified) |
3438
|
32 ## (1) via routine __bodquist__, isolate all poles and zeros away from |
3431
|
33 ## w=0 (jw=0 or exp(jwT)=1) and select the frequency |
|
34 ## range based on the breakpoint locations of the frequencies. |
|
35 ## (2) if sys is discrete time, the frequency range is limited |
|
36 ## to jwT in [0,2p*pi] |
|
37 ## (3) A "smoothing" routine is used to ensure that the plot phase does |
|
38 ## not change excessively from point to point and that singular |
|
39 ## points (e.g., crossovers from +/- 180) are accurately shown. |
|
40 ## outputs, inputs: the indices of the output(s) and input(s) to be used in |
|
41 ## the frequency response; see sysprune. |
|
42 ## outputs: |
|
43 ## mag, phase: the magnitude and phase of the frequency response |
|
44 ## G(jw) or G(exp(jwT)) at the selected frequency values. |
|
45 ## w: the vector of frequency values used |
|
46 ## If no output arguments are given, nichols plots the results to the screen. |
|
47 ## Descriptive labels are automatically placed. See xlabel, ylable, title, |
|
48 ## and replot. |
|
49 ## |
|
50 ## Note: if the requested plot is for an MIMO system, mag is set to |
|
51 ## ||G(jw)|| or ||G(exp(jwT))|| and phase information is not computed. |
3451
|
52 ## @end deftypefn |
3431
|
53 |
|
54 function [mag, phase, w] = nichols (sys, w, outputs, inputs) |
|
55 |
|
56 ## check number of input arguments given |
|
57 if (nargin < 1 | nargin > 4) |
|
58 usage("[mag,phase,w] = nichols(sys[,w,outputs,inputs])"); |
|
59 endif |
|
60 if(nargin < 2) |
|
61 w = []; |
|
62 endif |
|
63 if(nargin < 3) |
|
64 outputs = []; |
|
65 endif |
|
66 if(nargin < 4) |
|
67 inputs = []; |
|
68 endif |
|
69 |
3438
|
70 [f, w] = __bodquist__ (sys, w, outputs, inputs, "nichols"); |
3431
|
71 |
|
72 [stname,inname,outname] = sysgetsignals(sys); |
|
73 systsam = sysgettsam(sys); |
|
74 |
|
75 ## Get the magnitude and phase of f. |
|
76 mag = abs(f); |
|
77 phase = arg(f)*180.0/pi; |
|
78 |
|
79 if (nargout < 1), |
|
80 ## Plot the information |
|
81 if(gnuplot_has_multiplot) |
|
82 oneplot(); |
|
83 endif |
|
84 gset autoscale; |
|
85 if(gnuplot_has_multiplot) |
|
86 gset nokey; |
|
87 endif |
|
88 clearplot(); |
|
89 grid("on"); |
|
90 gset data style lines; |
|
91 if(is_digital(sys)) |
|
92 tistr = "(exp(jwT)) "; |
|
93 else |
|
94 tistr = "(jw)"; |
|
95 endif |
|
96 xlabel("Phase (deg)"); |
|
97 if(is_siso(sys)) |
|
98 title(["Nichols plot of |[Y/U]",tistr,"|, u=", ... |
|
99 sysgetsignals(sys,"in",1,1), ", y=",sysgetsignals(sys,"out",1,1)]); |
|
100 else |
|
101 title([ "||Y(", tistr, ")/U(", tistr, ")||"]); |
3438
|
102 printf("MIMO plot from\n%s\nto\n%s\n",__outlist__(inname," "), ... |
|
103 __outlist__(outname," ")); |
3431
|
104 endif |
|
105 if(max(mag) > 0) |
|
106 ylabel("Gain in dB"); |
|
107 md = 20*log10(mag); |
|
108 else |
|
109 ylabel("Gain |Y/U|") |
|
110 md = mag; |
|
111 endif |
|
112 |
|
113 axvec = axis2dlim([vec(phase),vec(md)]); |
|
114 axis(axvec); |
|
115 plot(phase,md); |
|
116 mag = phase = w = []; |
|
117 endif |
|
118 endfunction |