3431
|
1 ## Copyright (C) 1996 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 |
7016
|
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. |
3431
|
9 ## |
7016
|
10 ## Octave 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. |
3431
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3431
|
18 |
|
19 ## -*- texinfo -*- |
3500
|
20 ## @deftypefn {Function File} {[@var{wmin}, @var{wmax}] =} bode_bounds (@var{zer}, @var{pol}, @var{dflg}, @var{tsam}) |
3431
|
21 ## Get default range of frequencies based on cutoff frequencies of system |
|
22 ## poles and zeros. |
5016
|
23 ## Frequency range is the interval |
|
24 ## @iftex |
|
25 ## @tex |
|
26 ## $ [ 10^{w_{min}}, 10^{w_{max}} ] $ |
|
27 ## @end tex |
|
28 ## @end iftex |
|
29 ## @ifinfo |
|
30 ## [10^@var{wmin}, 10^@var{wmax}] |
|
31 ## @end ifinfo |
3431
|
32 ## |
5016
|
33 ## Used internally in @command{__freqresp__} (@command{bode}, @command{nyquist}) |
3431
|
34 ## @end deftypefn |
|
35 |
|
36 function [wmin, wmax] = bode_bounds (zer, pol, DIGITAL, tsam) |
|
37 |
|
38 ## make sure zer,pol are row vectors |
|
39 if(!isempty(pol)) pol = reshape(pol,1,length(pol)); endif |
|
40 if(!isempty(zer)) zer = reshape(zer,1,length(zer)); endif |
|
41 |
|
42 ## check for natural frequencies away from omega = 0 |
|
43 if (DIGITAL) |
|
44 ## The 2nd conditions prevents log(0) in the next log command |
|
45 iiz = find(abs(zer - 1) > norm(zer) * eps && abs(zer) > norm(zer) * eps); |
|
46 iip = find(abs(pol - 1) > norm(pol) * eps && abs(pol) > norm(pol) * eps); |
|
47 |
|
48 ## avoid dividing empty matrices, it would work but looks nasty |
|
49 if (!isempty(iiz)) czer = log(zer(iiz))/tsam; |
|
50 else czer = []; endif |
|
51 |
|
52 if (!isempty(iip)) cpol = log(pol(iip))/tsam; |
|
53 else cpol = []; endif |
|
54 |
|
55 else |
|
56 ## continuous |
|
57 iip = find((abs(pol)) > (norm(pol) * eps)); |
|
58 iiz = find((abs(zer)) > (norm(zer) * eps)); |
|
59 |
|
60 if(!isempty(zer)) czer = zer(iiz); |
|
61 else czer = []; endif |
|
62 if(!isempty(pol)) cpol = pol(iip); |
|
63 else cpol = []; endif |
|
64 endif |
5686
|
65 |
|
66 if (isempty (iip) && isempty (iiz)) |
3431
|
67 ## no poles/zeros away from omega = 0; pick defaults |
|
68 wmin = -1; |
|
69 wmax = 3; |
5686
|
70 else |
|
71 wmin = floor(log10(min(abs([cpol,czer])))); |
|
72 wmax = ceil(log10(max(abs([cpol,czer])))); |
3431
|
73 endif |
|
74 |
|
75 ## expand to show the entirety of the "interesting" portion of the plot |
|
76 wmin--; |
|
77 wmax++; |
|
78 |
|
79 ## run digital frequency all the way to pi |
|
80 if (DIGITAL) wmax = log10(pi/tsam); endif |
|
81 |
|
82 endfunction |