annotate scripts/control/base/bode_bounds.m @ 7016:93c65f2a5668

[project @ 2007-10-12 06:40:56 by jwe]
author jwe
date Fri, 12 Oct 2007 06:41:26 +0000
parents e7790bb14cfc
children a1dbe9d80eee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1996 Auburn University. All rights reserved.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
2 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
4 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
8 ## your option) any later version.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
9 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
13 ## General Public License for more details.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
14 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5686
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
18
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
3500
7923abdeb4e5 [project @ 2000-01-31 06:35:00 by jwe]
jwe
parents: 3438
diff changeset
20 ## @deftypefn {Function File} {[@var{wmin}, @var{wmax}] =} bode_bounds (@var{zer}, @var{pol}, @var{dflg}, @var{tsam})
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
21 ## Get default range of frequencies based on cutoff frequencies of system
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
22 ## poles and zeros.
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
23 ## Frequency range is the interval
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
24 ## @iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
25 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
26 ## $ [ 10^{w_{min}}, 10^{w_{max}} ] $
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
27 ## @end tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
28 ## @end iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
29 ## @ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
30 ## [10^@var{wmin}, 10^@var{wmax}]
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
31 ## @end ifinfo
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
32 ##
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 3500
diff changeset
33 ## Used internally in @command{__freqresp__} (@command{bode}, @command{nyquist})
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
34 ## @end deftypefn
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
35
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
36 function [wmin, wmax] = bode_bounds (zer, pol, DIGITAL, tsam)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
37
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
38 ## make sure zer,pol are row vectors
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
39 if(!isempty(pol)) pol = reshape(pol,1,length(pol)); endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
40 if(!isempty(zer)) zer = reshape(zer,1,length(zer)); endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
41
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
42 ## check for natural frequencies away from omega = 0
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
43 if (DIGITAL)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
44 ## The 2nd conditions prevents log(0) in the next log command
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
45 iiz = find(abs(zer - 1) > norm(zer) * eps && abs(zer) > norm(zer) * eps);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
46 iip = find(abs(pol - 1) > norm(pol) * eps && abs(pol) > norm(pol) * eps);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
47
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
48 ## avoid dividing empty matrices, it would work but looks nasty
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
49 if (!isempty(iiz)) czer = log(zer(iiz))/tsam;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
50 else czer = []; endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
51
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
52 if (!isempty(iip)) cpol = log(pol(iip))/tsam;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
53 else cpol = []; endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
54
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
55 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
56 ## continuous
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
57 iip = find((abs(pol)) > (norm(pol) * eps));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
58 iiz = find((abs(zer)) > (norm(zer) * eps));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
59
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
60 if(!isempty(zer)) czer = zer(iiz);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
61 else czer = []; endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
62 if(!isempty(pol)) cpol = pol(iip);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
63 else cpol = []; endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
64 endif
5686
e7790bb14cfc [project @ 2006-03-16 20:01:05 by jwe]
jwe
parents: 5307
diff changeset
65
e7790bb14cfc [project @ 2006-03-16 20:01:05 by jwe]
jwe
parents: 5307
diff changeset
66 if (isempty (iip) && isempty (iiz))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
67 ## no poles/zeros away from omega = 0; pick defaults
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
68 wmin = -1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
69 wmax = 3;
5686
e7790bb14cfc [project @ 2006-03-16 20:01:05 by jwe]
jwe
parents: 5307
diff changeset
70 else
e7790bb14cfc [project @ 2006-03-16 20:01:05 by jwe]
jwe
parents: 5307
diff changeset
71 wmin = floor(log10(min(abs([cpol,czer]))));
e7790bb14cfc [project @ 2006-03-16 20:01:05 by jwe]
jwe
parents: 5307
diff changeset
72 wmax = ceil(log10(max(abs([cpol,czer]))));
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
73 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
74
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
75 ## expand to show the entirety of the "interesting" portion of the plot
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
76 wmin--;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
77 wmax++;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
78
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
79 ## run digital frequency all the way to pi
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
80 if (DIGITAL) wmax = log10(pi/tsam); endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
81
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
82 endfunction