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