7017
|
1 ## Copyright (C) 1996, 1998, 2000, 2002, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3430
|
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. |
3430
|
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. |
3430
|
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/>. |
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: |
7031
|
40 ## @smallexample |
3430
|
41 ## ----------- ------- ----------- |
|
42 ## u --->| inscale |--->| sys |--->| outscale |---> y |
|
43 ## ----------- ------- ----------- |
7031
|
44 ## @end smallexample |
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 |
7135
|
62 if (nargin < 3 || nargin > 5) |
6046
|
63 print_usage (); |
7135
|
64 elseif (! isstruct (sys)) |
|
65 error ("sys must be a structured system"); |
3430
|
66 endif |
|
67 |
7135
|
68 [nn, nz, mm, pp] = sysdimensions (sys); |
3430
|
69 |
|
70 ## check for omitted scales |
7135
|
71 if (isempty (outscale)) |
|
72 outscale = eye (pp); |
|
73 endif |
|
74 if (isempty (inscale)) |
|
75 inscale = eye (mm); |
|
76 endif |
3430
|
77 |
|
78 ## check dimensions of scaling matrices |
7135
|
79 if (mm != rows (inscale)) |
|
80 error ("inscale(%dx%d) should have %d rows(# system inputs)", |
|
81 rows (inscale), columns (inscale), mm); |
|
82 elseif (pp != columns (outscale) ) |
|
83 error ("outscale(%dx%d) should have %d columns(# system outputs)", |
|
84 rows (outscale), columns (outscale), pp); |
3430
|
85 endif |
|
86 |
7135
|
87 sysyd = sysgetsignals (sys, "yd"); |
|
88 outc = find (sysyd == 0); |
|
89 outd = find (sysyd == 1); |
3430
|
90 |
7135
|
91 if (length (outc) > 0 && length (outd) > 0) |
3430
|
92 for ii = 1:rows(outscale) |
7135
|
93 nci = norm (outscale (ii, outc)); |
|
94 ndi = norm (outscale (ii, outd)); |
3430
|
95 |
7135
|
96 if (nci > 0 && ndi > 0) |
|
97 warning ("sysscale: outscale(%d,:) sums continuous and discrete outputs; setting output to cont", |
|
98 ii) |
3430
|
99 sysyd(ii) = 0; |
|
100 else |
|
101 sysyd(ii) = (ndi != 0); |
|
102 endif |
|
103 endfor |
|
104 else |
7135
|
105 sysyd = ones (1, rows (outscale)) * (length(outd) > 0); |
3430
|
106 endif |
|
107 |
|
108 ## check for SISO system type |
7135
|
109 if (strcmp (sysgettype (sys), "tf")) |
|
110 [num, den, tsam, innam, outnam] = sys2tf (sys); |
3430
|
111 num = num*inscale*outscale; |
7135
|
112 sys = tf (num, den, tsam, innam, outnam); |
|
113 return; |
|
114 elseif (strcmp (sysgettype (sys), "zp")) |
|
115 [zer, pol, kk, tsam, innam, outnam] = sys2zp (sys); |
3430
|
116 kk = kk*inscale*outscale; |
7135
|
117 sys = zp (zer, pol, k, tsam, innam, outnam); |
|
118 return; |
3430
|
119 endif |
|
120 |
|
121 ## it's a state space system... |
|
122 |
7135
|
123 [sysa, sysb, sysc, sysd, systsam, ... |
|
124 sysn, sysnz, sysstname, sysinname, sysoutname, oldyd] = sys2ss(sys); |
3430
|
125 |
|
126 sysb = sysb*inscale; |
|
127 sysc = outscale*sysc; |
|
128 sysd = outscale*sysd*inscale; |
|
129 |
7135
|
130 if (! issquare (outscale)) |
3430
|
131 ## strip extra output names (if any) |
7135
|
132 sysoutname = sysoutname(1:min(rows(outscale), columns(outscale))); |
|
133 if (nargin < 4) |
|
134 warning ("sysscale: outscale not square, outname not specified"); |
|
135 warning ("sysscale: using default output names"); |
|
136 outname = __sysdefioname__ (rows (sysc), "y"); |
3430
|
137 endif |
|
138 else |
|
139 outname = sysoutname; |
|
140 endif |
7135
|
141 if (! issquare (inscale)) |
3430
|
142 ## strip extra output names (if any) |
7135
|
143 sysinname = sysinname(1:min(rows(inscale), columns(inscale))); |
|
144 if (nargin < 5) |
|
145 warning ("sysscale: inscale not square, inname not specified"); |
|
146 warning ("sysscale: using default input names"); |
|
147 inname = __sysdefioname__ (columns (sysb), "u"); |
3430
|
148 endif |
|
149 else |
7135
|
150 inname = sysgetsignals (sys, "in"); |
3430
|
151 endif |
|
152 |
7135
|
153 sys = ss (sysa, sysb, sysc, sysd, systsam, nn, nz, sysstname, |
|
154 inname, outname, find (sysyd == 1)); |
3430
|
155 |
|
156 endfunction |