1 ## Copyright (C) 1996, 2000, 2004, 2005, 2006, 2007
2 ## Auburn University. All rights reserved.
5 ## This program is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## This program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{w} =} __frequency_vector__ (@var{sys})
21 ## Get default range of frequencies based on cutoff frequencies of system
23 ## Frequency range is the interval
26 ## $ [ 10^{w_{min}}, 10^{w_{max}} ] $
30 ## [10^@var{wmin}, 10^@var{wmax}]
33 ## Used by @command{__frequency_response__}
36 ## Adapted-By: Lukas Reichlin <lukas.reichlin@gmail.com>
40 function w = __frequency_vector__ (sys, wbounds = "std", wmin, wmax)
44 tsam = abs (get (sys, "tsam")); # tsam could be -1
45 discrete = ! isct (sys); # static gains (tsam = -2) are assumed continuous
47 ## make sure zer, pol are row vectors
48 pol = reshape (pol, 1, []);
49 zer = reshape (zer, 1, []);
51 ## check for natural frequencies away from omega = 0
53 ## The 2nd conditions prevents log(0) in the next log command
54 iiz = find (abs(zer-1) > norm(zer)*eps && abs(zer) > norm(zer)*eps);
55 iip = find (abs(pol-1) > norm(pol)*eps && abs(pol) > norm(pol)*eps);
57 ## avoid dividing empty matrices, it would work but looks nasty
59 czer = log (zer(iiz))/tsam;
65 cpol = log (pol(iip))/tsam;
71 iip = find (abs(pol) > norm(pol)*eps);
72 iiz = find (abs(zer) > norm(zer)*eps);
86 if (isempty (iip) && isempty (iiz))
87 ## no poles/zeros away from omega = 0; pick defaults
91 dec_min = floor (log10 (min (abs ([cpol, czer]))));
92 dec_max = ceil (log10 (max (abs ([cpol, czer]))));
95 ## expand to show the entirety of the "interesting" portion of the plot
98 if (dec_min == dec_max)
105 case "ext" # extended (for nyquist)
106 if (any (abs (pol) < sqrt (eps))) # look for integrators
114 error ("frequency_range: second argument invalid");
117 ## run discrete frequency all the way to pi
119 dec_max = log10 (pi/tsam);
122 if (nargin == 4) # w = {wmin, wmax}
123 dec_min = log10 (wmin);
124 dec_max = log10 (wmax);
127 ## create frequency vector
128 zp = [abs(zer), abs(pol)];
129 idx = find (zp > 10^dec_min & zp < 10^dec_max);
132 w = logspace (dec_min, dec_max, 500);
133 w = unique ([w, zp]); # unique also sorts frequency vector