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