7017
|
1 ## Copyright (C) 1996, 1998, 2000, 2003, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3437
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3437
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3437
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3437
|
19 |
6945
|
20 ## Undocumented internal function. |
|
21 |
3437
|
22 ## -*- texinfo -*- |
3500
|
23 ## @deftypefn {Function File} {} __freqresp__ (@var{sys}, @var{USEW}, @var{w}) |
5016
|
24 ## Frequency response function - used internally by @command{bode}, @command{nyquist}. |
|
25 ## minimal argument checking; ``do not attempt to do this at home''. |
3437
|
26 ## |
|
27 ## @strong{Inputs} |
|
28 ## @table @var |
|
29 ## @item sys |
|
30 ## system data structure |
|
31 ## @item USEW |
|
32 ## returned by @code{freqchkw} |
|
33 ## @item optional |
|
34 ## must be present if @var{USEW} is true (nonzero) |
|
35 ## @end table |
|
36 ## @strong{Outputs} |
|
37 ## @table @var |
|
38 ## @item @var{out} |
5016
|
39 ## vector of finite @math{G(j*w)} entries (or @math{||G(j*w)||} for @acronym{MIMO}) |
3437
|
40 ## @item w |
|
41 ## vector of corresponding frequencies |
|
42 ## @end table |
|
43 ## @end deftypefn |
|
44 |
|
45 ## Author: R. Bruce Tenison <btenison@eng.auburn.edu> |
|
46 ## Created: July 11, 1994 |
|
47 |
3438
|
48 function [ff, w] = __freqresp__ (sys, USEW, w); |
3437
|
49 |
|
50 ## SYS_INTERNAL accesses members of system data structure |
|
51 |
5568
|
52 ## Check Args |
7126
|
53 if (nargin < 2 || nargin > 4) |
6046
|
54 print_usage (); |
7126
|
55 elseif (USEW && nargin < 3) |
5568
|
56 error ("USEW = 1 but w was not passed."); |
7126
|
57 elseif (USEW && isempty (w)) |
|
58 warning ("USEW = 1 but w is empty; setting USEW=0"); |
5568
|
59 USEW = 0; |
|
60 endif |
4460
|
61 |
7126
|
62 DIGITAL = is_digital (sys); |
4460
|
63 |
5568
|
64 ## compute default w if needed |
7126
|
65 if (! USEW) |
|
66 if (is_siso (sys)) |
|
67 sys = sysupdate (sys, "zp"); |
|
68 [zer, pol] = sys2zp (sys); |
5568
|
69 else |
7126
|
70 zer = tzero (sys); |
|
71 pol = eig (sys2ss (sys)); |
3437
|
72 endif |
|
73 |
5568
|
74 ## get default frequency range |
7126
|
75 [wmin, wmax] = bode_bounds (zer, pol, DIGITAL, sysgettsam (sys)); |
|
76 w = logspace (wmin, wmax, 50); |
5568
|
77 else |
7126
|
78 w = reshape (w, 1, length (w)); # make sure it's a row vector |
5568
|
79 endif |
3437
|
80 |
5568
|
81 ## now get complex values of s or z |
7126
|
82 if (DIGITAL) |
|
83 jw = exp (i*w*sysgettsam(sys)); |
5568
|
84 else |
|
85 jw = i*w; |
|
86 endif |
|
87 |
7126
|
88 [nn, nz, mm, pp] = sysdimensions (sys); |
5568
|
89 |
|
90 ## now compute the frequency response - divide by zero yields a warning |
7126
|
91 if (strcmp (sysgettype (sys), "zp")) |
5568
|
92 ## zero-pole form (preferred) |
7126
|
93 [zer, pol, sysk] = sys2zp (sys); |
|
94 ff = ones (size (jw)); |
|
95 l1 = min (length(zer)*(1-isempty(zer)), length(pol)*(1-isempty(pol))); |
|
96 for ii = 1:l1 |
|
97 ff = ff .* (jw - zer(ii)) ./ (jw - pol(ii)); |
5568
|
98 endfor |
3437
|
99 |
5568
|
100 ## require proper transfer function, so now just get poles. |
7126
|
101 for ii = (l1+1):length(pol) |
5568
|
102 ff = ff ./ (jw - pol(ii)); |
|
103 endfor |
|
104 ff = ff*sysk; |
7126
|
105 elseif (strcmp (sysgettype (sys), "tf")) |
5568
|
106 ## transfer function form |
7126
|
107 [num, den] = sys2tf (sys); |
|
108 ff = polyval (num, jw) ./ polyval (den, jw); |
5568
|
109 elseif (mm==pp) |
|
110 ## The system is square; do state-space form bode plot |
7126
|
111 [sysa, sysb, sysc, sysd, tsam, sysn, sysnz] = sys2ss (sys); |
5568
|
112 n = sysn + sysnz; |
7126
|
113 for ii = 1:length(jw); |
|
114 ff(ii) = det (sysc*((jw(ii).*eye(n)-sysa)\sysb)+sysd); |
|
115 endfor |
5568
|
116 else |
|
117 ## Must be state space... bode |
7126
|
118 [sysa, sysb, sysc, sysd, tsam, sysn, sysnz] = sys2ss (sys); |
5568
|
119 n = sysn + sysnz; |
7126
|
120 for ii = 1:length(jw); |
|
121 ff(ii) = norm (sysc*((jw(ii)*eye(n)-sysa)\sysb)+sysd); |
5568
|
122 endfor |
|
123 endif |
4460
|
124 |
7126
|
125 w = reshape (w, 1, length (w)); |
|
126 ff = reshape (ff, 1, length (ff)); |
3437
|
127 |
|
128 endfunction |
|
129 |