Mercurial > hg > octave-nkf
comparison scripts/control/bode.m @ 3282:518ea57df2c4
[project @ 1999-10-13 19:00:38 by jwe]
author | jwe |
---|---|
date | Wed, 13 Oct 1999 19:00:38 +0000 |
parents | 6dd06d525de6 |
children | f7e4a95916f2 |
comparison
equal
deleted
inserted
replaced
3281:aaaa20d31a5f | 3282:518ea57df2c4 |
---|---|
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 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 | 16 # along with Octave; see the file COPYING. If not, write to the Free |
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | 18 |
19 function [mag,phase,w] = bode(sys,w,outputs,inputs) | 19 function [mag,phase,w] = bode(sys,w,outputs,inputs,plot_style) |
20 # [mag,phase,w] = bode(sys[,w,outputs,inputs]) | 20 # [mag,phase,w] = bode(sys[,w,outputs,inputs,plot_style]) |
21 # Produce Bode plots of a system | 21 # Produce Bode plots of a system |
22 # | 22 # |
23 # Compute the frequency response of a system. | 23 # Compute the frequency response of a system. |
24 # inputs: | 24 # inputs: |
25 # sys: system data structure (must be either purely continuous or discrete; | 25 # sys: system data structure (must be either purely continuous or discrete; |
38 # (3) A "smoothing" routine is used to ensure that the plot phase does | 38 # (3) A "smoothing" routine is used to ensure that the plot phase does |
39 # not change excessively from point to point and that singular | 39 # not change excessively from point to point and that singular |
40 # points (e.g., crossovers from +/- 180) are accurately shown. | 40 # points (e.g., crossovers from +/- 180) are accurately shown. |
41 # outputs, inputs: the indices of the output(s) and input(s) to be used in | 41 # outputs, inputs: the indices of the output(s) and input(s) to be used in |
42 # the frequency response; see sysprune. | 42 # the frequency response; see sysprune. |
43 # plot_style: An optional argument specifying the type of plot to | |
44 # produce (if plotting is being done). Valid values are | |
45 # "dB" or "mag". If omitted, "dB" is assumed. | |
46 # | |
43 # outputs: | 47 # outputs: |
44 # mag, phase: the magnitude and phase of the frequency response | 48 # mag, phase: the magnitude and phase of the frequency response |
45 # G(jw) or G(exp(jwT)) at the selected frequency values. | 49 # G(jw) or G(exp(jwT)) at the selected frequency values. |
46 # w: the vector of frequency values used | 50 # w: the vector of frequency values used |
47 # If no output arguments are given, bode plots the results to the screen. | 51 # If no output arguments are given, bode plots the results to the screen. |
57 # Modified by David Clem November 13, 1994 | 61 # Modified by David Clem November 13, 1994 |
58 # again by A. S. Hodel July 1995 (smart plot range, etc.) | 62 # again by A. S. Hodel July 1995 (smart plot range, etc.) |
59 # Modified by Kai P. Mueller September 28, 1997 (multiplot mode) | 63 # Modified by Kai P. Mueller September 28, 1997 (multiplot mode) |
60 | 64 |
61 # check number of input arguments given | 65 # check number of input arguments given |
62 if (nargin < 1 | nargin > 4) | 66 if (nargin < 1 | nargin > 5) |
63 usage("[mag,phase,w] = bode(sys[,w,outputs,inputs])"); | 67 usage("[mag,phase,w] = bode(sys[,w,outputs,inputs,plot_style])"); |
64 endif | 68 endif |
65 if(nargin < 2) | 69 if(nargin < 2) |
66 w = []; | 70 w = []; |
67 endif | 71 endif |
68 if(nargin < 3) | 72 if(nargin < 3) |
69 outputs = []; | 73 outputs = []; |
70 endif | 74 endif |
71 if(nargin < 4) | 75 if(nargin < 4) |
72 inputs = []; | 76 inputs = []; |
77 endif | |
78 if(nargin < 5) | |
79 plot_style = "dB"; | |
80 endif | |
81 | |
82 if (strcmp (plot_style, "dB")) | |
83 do_db_plot = 1; | |
84 elseif (strcmp (plot_style, "mag")) | |
85 do_db_plot = 0; | |
86 else | |
87 error ("bode: invalid value of plot_style specified"); | |
73 endif | 88 endif |
74 | 89 |
75 [f, w] = bodquist(sys,w,outputs,inputs,"bode"); | 90 [f, w] = bodquist(sys,w,outputs,inputs,"bode"); |
76 | 91 |
77 [stname,inname,outname] = sysgetsignals(sys); | 92 [stname,inname,outname] = sysgetsignals(sys); |
111 disp(outlist(inname," ")); | 126 disp(outlist(inname," ")); |
112 disp("to") | 127 disp("to") |
113 disp(outlist(outname," ")); | 128 disp(outlist(outname," ")); |
114 endif | 129 endif |
115 wv = [min(w), max(w)]; | 130 wv = [min(w), max(w)]; |
116 if(max(mag) > 0) | 131 if(do_db_plot && max(mag) > 0) |
117 ylabel("Gain in dB"); | 132 ylabel("Gain in dB"); |
118 md = 20*log10(mag); | 133 md = 20*log10(mag); |
119 else | 134 else |
120 ylabel("Gain |Y/U|") | 135 ylabel("Gain |Y/U|") |
121 md = mag; | 136 md = mag; |
123 | 138 |
124 axvec = axis2dlim([vec(w),vec(md)]); | 139 axvec = axis2dlim([vec(w),vec(md)]); |
125 axvec(1:2) = wv; | 140 axvec(1:2) = wv; |
126 axis(axvec); | 141 axis(axvec); |
127 grid("on"); | 142 grid("on"); |
128 semilogx(w,md); | 143 if (do_db_plot) |
144 semilogx(w,md); | |
145 else | |
146 loglog(w,md); | |
147 endif | |
129 if (is_siso(sys)) | 148 if (is_siso(sys)) |
130 if (gnuplot_has_multiplot) | 149 if (gnuplot_has_multiplot) |
131 subplot(2,1,2); | 150 subplot(2,1,2); |
132 else | 151 else |
133 prompt('Press any key for phase plot'); | 152 prompt('Press any key for phase plot'); |