3437
|
1 ## Copyright (C) 1996, 1998 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. |
3437
|
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. |
3437
|
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/>. |
3437
|
18 |
6945
|
19 ## Undocumented internal function. |
|
20 |
3437
|
21 ## -*- texinfo -*- |
3500
|
22 ## @deftypefn {Function File} {} __freqresp__ (@var{sys}, @var{USEW}, @var{w}) |
5016
|
23 ## Frequency response function - used internally by @command{bode}, @command{nyquist}. |
|
24 ## minimal argument checking; ``do not attempt to do this at home''. |
3437
|
25 ## |
|
26 ## @strong{Inputs} |
|
27 ## @table @var |
|
28 ## @item sys |
|
29 ## system data structure |
|
30 ## @item USEW |
|
31 ## returned by @code{freqchkw} |
|
32 ## @item optional |
|
33 ## must be present if @var{USEW} is true (nonzero) |
|
34 ## @end table |
|
35 ## @strong{Outputs} |
|
36 ## @table @var |
|
37 ## @item @var{out} |
5016
|
38 ## vector of finite @math{G(j*w)} entries (or @math{||G(j*w)||} for @acronym{MIMO}) |
3437
|
39 ## @item w |
|
40 ## vector of corresponding frequencies |
|
41 ## @end table |
|
42 ## @end deftypefn |
|
43 |
|
44 ## Author: R. Bruce Tenison <btenison@eng.auburn.edu> |
|
45 ## Created: July 11, 1994 |
|
46 |
3438
|
47 function [ff, w] = __freqresp__ (sys, USEW, w); |
3437
|
48 |
|
49 ## SYS_INTERNAL accesses members of system data structure |
|
50 |
5568
|
51 ## Check Args |
|
52 if ((nargin < 2) || (nargin > 4)) |
6046
|
53 print_usage (); |
5568
|
54 elseif (USEW & (nargin < 3) ) |
|
55 error ("USEW = 1 but w was not passed."); |
|
56 elseif (USEW & isempty(w)) |
|
57 warning("USEW = 1 but w is empty; setting USEW=0"); |
|
58 USEW = 0; |
|
59 endif |
4460
|
60 |
5568
|
61 DIGITAL = is_digital(sys); |
4460
|
62 |
5568
|
63 ## compute default w if needed |
|
64 if(!USEW) |
|
65 if(is_siso(sys)) |
4460
|
66 sys = sysupdate(sys,"zp"); |
|
67 [zer,pol] = sys2zp(sys); |
5568
|
68 else |
4460
|
69 zer = tzero(sys); |
|
70 pol = eig(sys2ss(sys)); |
3437
|
71 endif |
|
72 |
5568
|
73 ## get default frequency range |
|
74 [wmin,wmax] = bode_bounds(zer,pol,DIGITAL,sysgettsam(sys)); |
|
75 w = logspace(wmin,wmax,50); |
|
76 else |
|
77 w = reshape(w,1,length(w)); # make sure it's a row vector |
|
78 endif |
3437
|
79 |
5568
|
80 ## now get complex values of s or z |
|
81 if(DIGITAL) |
|
82 jw = exp(i*w*sysgettsam(sys)); |
|
83 else |
|
84 jw = i*w; |
|
85 endif |
|
86 |
|
87 [nn,nz,mm,pp] = sysdimensions(sys); |
|
88 |
|
89 ## now compute the frequency response - divide by zero yields a warning |
|
90 if (strcmp(sysgettype(sys),"zp")) |
|
91 ## zero-pole form (preferred) |
|
92 [zer,pol,sysk] = sys2zp(sys); |
|
93 ff = ones(size(jw)); |
|
94 l1 = min(length(zer)*(1-isempty(zer)),length(pol)*(1-isempty(pol))); |
|
95 for ii=1:l1 |
4460
|
96 ff = ff .* (jw - zer(ii)) ./ (jw - pol(ii)); |
5568
|
97 endfor |
3437
|
98 |
5568
|
99 ## require proper transfer function, so now just get poles. |
|
100 for ii=(l1+1):length(pol) |
|
101 ff = ff ./ (jw - pol(ii)); |
|
102 endfor |
|
103 ff = ff*sysk; |
|
104 |
|
105 elseif (strcmp(sysgettype(sys),"tf")) |
|
106 ## transfer function form |
|
107 [num,den] = sys2tf(sys); |
|
108 ff = polyval(num,jw)./polyval(den,jw); |
|
109 elseif (mm==pp) |
|
110 ## The system is square; do state-space form bode plot |
|
111 [sysa,sysb,sysc,sysd,tsam,sysn,sysnz] = sys2ss(sys); |
|
112 n = sysn + sysnz; |
|
113 for ii=1:length(jw); |
4460
|
114 ff(ii) = det(sysc*((jw(ii).*eye(n)-sysa)\sysb)+sysd); |
5568
|
115 endfor; |
|
116 else |
|
117 ## Must be state space... bode |
|
118 [sysa,sysb,sysc,sysd,tsam,sysn,sysnz] = sys2ss(sys); |
|
119 n = sysn + sysnz; |
|
120 for ii=1:length(jw); |
4460
|
121 ff(ii) = norm(sysc*((jw(ii)*eye(n)-sysa)\sysb)+sysd); |
5568
|
122 endfor |
3437
|
123 |
5568
|
124 endif |
4460
|
125 |
5568
|
126 w = reshape(w,1,length(w)); |
|
127 ff = reshape(ff,1,length(ff)); |
3437
|
128 |
|
129 endfunction |
|
130 |