3430
|
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. |
3430
|
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. |
3430
|
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/>. |
3430
|
18 |
|
19 ## -*- texinfo -*- |
5016
|
20 ## @deftypefn {Function File} {@var{retsys} =} sysscale (@var{sys}, @var{outscale}, @var{inscale}, @var{outname}, @var{inname}) |
3430
|
21 ## scale inputs/outputs of a system. |
|
22 ## |
|
23 ## @strong{Inputs} |
5016
|
24 ## @table @var |
|
25 ## @item sys |
|
26 ## Structured system. |
|
27 ## @item outscale |
|
28 ## @itemx inscale |
|
29 ## Constant matrices of appropriate dimension. |
|
30 ## @item outname |
|
31 ## @itemx inname |
|
32 ## Lists of strings with the names of respectively outputs and inputs. |
|
33 ## @end table |
3430
|
34 ## |
5016
|
35 ## @strong{Output} |
|
36 ## @table @var |
|
37 ## @item retsys |
|
38 ## resulting open loop system: |
3430
|
39 ## @example |
|
40 ## ----------- ------- ----------- |
|
41 ## u --->| inscale |--->| sys |--->| outscale |---> y |
|
42 ## ----------- ------- ----------- |
|
43 ## @end example |
5016
|
44 ## @end table |
3430
|
45 ## If the input names and output names (each a list of strings) |
|
46 ## are not given and the scaling matrices |
|
47 ## are not square, then default names will be given to the inputs and/or |
|
48 ## outputs. |
|
49 ## |
|
50 ## A warning message is printed if outscale attempts to add continuous |
|
51 ## system outputs to discrete system outputs; otherwise @var{yd} is |
|
52 ## set appropriately in the returned value of @var{sys}. |
|
53 ## @end deftypefn |
|
54 |
|
55 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
56 ## Created: August 1995 |
|
57 ## modified by John Ingram 7-15-96 |
|
58 |
|
59 function sys = sysscale (sys, outscale, inscale, outname, inname) |
|
60 |
|
61 if( (nargin < 3) || (nargin > 5) ) |
6046
|
62 print_usage (); |
4030
|
63 elseif (!isstruct(sys)) |
3430
|
64 error("sys must be a structured system"); |
|
65 endif |
|
66 |
|
67 [nn,nz,mm,pp] = sysdimensions(sys); |
|
68 |
|
69 ## check for omitted scales |
|
70 if(isempty(outscale)) outscale = eye(pp); endif |
|
71 if(isempty(inscale)) inscale = eye(mm); endif |
|
72 |
|
73 ## check dimensions of scaling matrices |
|
74 if(mm!=rows(inscale)) |
|
75 error("inscale(%dx%d) should have %d rows(# system inputs)", ... |
|
76 rows(inscale),columns(inscale),mm); |
|
77 elseif( pp != columns(outscale) ) |
|
78 error("outscale(%dx%d) should have %d columns(# system outputs)", ... |
|
79 rows(outscale), columns(outscale),pp); |
|
80 endif |
|
81 |
|
82 sysyd = sysgetsignals(sys,"yd"); |
|
83 outc = find(sysyd==0); |
|
84 outd = find(sysyd==1); |
|
85 |
|
86 if(length(outc) & length(outd)) |
|
87 for ii = 1:rows(outscale) |
|
88 nci = norm(outscale(ii,outc)); |
|
89 ndi = norm(outscale(ii,outd)); |
|
90 |
|
91 if( nci & ndi) |
|
92 warning("sysscale: outscale(%d,:) sums continuous and discrete outputs; setting output to cont",ii) |
|
93 sysyd(ii) = 0; |
|
94 else |
|
95 sysyd(ii) = (ndi != 0); |
|
96 endif |
|
97 endfor |
|
98 else |
|
99 sysyd = ones(1,rows(outscale))*( length(outd) > 0); |
|
100 endif |
|
101 |
|
102 ## check for SISO system type |
|
103 if strcmp(sysgettype(sys),"tf") |
|
104 [num,den,tsam,innam,outnam] = sys2tf(sys); |
|
105 num = num*inscale*outscale; |
5957
|
106 sys = tf(num,den,tsam,innam,outnam); |
3430
|
107 return |
|
108 elseif strcmp(sysgettype(sys),"zp") |
|
109 [zer,pol,kk,tsam,innam,outnam] = sys2zp(sys); |
|
110 kk = kk*inscale*outscale; |
5957
|
111 sys = zp(zer,pol,k,tsam,innam,outnam); |
3430
|
112 return |
|
113 endif |
|
114 |
|
115 ## it's a state space system... |
|
116 |
|
117 [sysa,sysb,sysc,sysd,systsam, ... |
|
118 sysn,sysnz,sysstname,sysinname,sysoutname,oldyd] = sys2ss(sys); |
|
119 |
|
120 sysb = sysb*inscale; |
|
121 sysc = outscale*sysc; |
|
122 sysd = outscale*sysd*inscale; |
|
123 |
4030
|
124 if( !issquare(outscale) ) |
3430
|
125 ## strip extra output names (if any) |
|
126 sysoutname = sysoutname(1:min(rows(outscale),columns(outscale))); |
|
127 if( nargin < 4) |
|
128 warning("sysscale: outscale not square, outname not specified"); |
|
129 warning("sysscale: using default output names"); |
3438
|
130 outname = __sysdefioname__(rows(sysc),"y"); |
3430
|
131 endif |
|
132 else |
|
133 outname = sysoutname; |
|
134 endif |
4030
|
135 if( !issquare(inscale) ) |
3430
|
136 ## strip extra output names (if any) |
|
137 sysinname = sysinname(1:min(rows(inscale),columns(inscale))); |
|
138 if(nargin < 5) |
|
139 warning("sysscale: inscale not square, inname not specified"); |
|
140 warning("sysscale: using default input names"); |
3438
|
141 inname = __sysdefioname__(columns(sysb),"u"); |
3430
|
142 endif |
|
143 else |
|
144 inname = sysgetsignals(sys,"in"); |
|
145 endif |
|
146 |
4771
|
147 sys = ss(sysa,sysb,sysc,sysd,systsam,nn,nz,sysstname, ... |
3430
|
148 inname,outname,find(sysyd==1)); |
|
149 |
|
150 endfunction |