3430
|
1 ## Copyright (C) 1996 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 -*- |
3500
|
21 ## @deftypefn {Function File} {} sysupdate (@var{sys}, @var{opt}) |
3430
|
22 ## Update the internal representation of a system. |
|
23 ## |
|
24 ## @strong{Inputs} |
|
25 ## @table @var |
|
26 ## @item sys: |
|
27 ## system data structure |
|
28 ## @item opt |
|
29 ## string: |
|
30 ## @table @code |
|
31 ## @item "tf" |
|
32 ## update transfer function form |
|
33 ## @item "zp" |
|
34 ## update zero-pole form |
|
35 ## @item "ss" |
|
36 ## update state space form |
|
37 ## @item "all" |
|
38 ## all of the above |
|
39 ## @end table |
|
40 ## @end table |
|
41 ## |
|
42 ## @strong{Outputs} |
5016
|
43 ## @table @var |
|
44 ## @item retsys |
|
45 ## Contains union of data in sys and requested data. |
|
46 ## If requested data in @var{sys} is already up to date then @var{retsys}=@var{sys}. |
|
47 ## @end table |
3430
|
48 ## |
5016
|
49 ## Conversion to @command{tf} or @command{zp} exits with an error if the system is |
3430
|
50 ## mixed continuous/digital. |
|
51 ## @end deftypefn |
5053
|
52 ## |
4771
|
53 ## @seealso{tf, ss, zp, sysout, sys2ss, sys2tf, and sys2zp} |
3430
|
54 |
|
55 ## Author: John Ingram <ingraje@eng.auburn.edu> |
|
56 ## Created: July 9, 1996 |
|
57 |
|
58 function sys = sysupdate (sys, opt) |
|
59 |
|
60 ## check for correct number of inputs |
|
61 if (nargin != 2) |
|
62 usage("newsys = sysupdate(sys,opt)"); |
4030
|
63 elseif(! isstruct(sys) ) |
3430
|
64 error("1st argument must be system data structure") |
|
65 elseif(! (strcmp(opt,"tf") + strcmp(opt,"zp") + ... |
|
66 strcmp(opt,"ss") + strcmp(opt,"all")) ) |
|
67 error("2nd argument must be \"tf\", \"zp\", \"ss\", or \"all\""); |
|
68 endif |
|
69 |
|
70 ## check to make sure not trying to make a SISO system out of a MIMO sys |
|
71 if ( (strcmp(opt,"tf") + strcmp(opt,"zp") + strcmp(opt,"all")) ... |
|
72 & strcmp(sysgettype(sys),"ss") & (! is_siso(sys) ) ) |
|
73 error("MIMO -> SISO update requested"); |
|
74 endif |
|
75 |
|
76 ## update transfer function if desired |
|
77 if ( (strcmp(opt, "tf") + strcmp(opt,"all"))&& (!sys.sys(2))) |
|
78 ## check to make sure the system is not discrete and continuous |
|
79 is_digital(sys); |
|
80 |
|
81 ## if original system zero-pole |
|
82 if strcmp(sysgettype(sys),"zp") |
|
83 [sys.num,sys.den] = zp2tf(sys.zer,sys.pol,sys.k); |
|
84 sys.sys(2) = 1; |
|
85 ## if original system is state-space |
|
86 elseif(sys.sys(1) == 2) |
|
87 [sys.num,sys.den] = ss2tf(sys.a,sys.b,sys.c,sys.d); |
|
88 sys.sys(2) = 1; |
|
89 endif |
|
90 endif |
|
91 |
|
92 |
|
93 ## update zero-pole if desired |
|
94 if ( (strcmp(opt, "zp") + strcmp(opt,"all")) && (! sys.sys(3)) ) |
|
95 ## check to make sure the system is not discrete and continuous |
|
96 is_digital(sys); |
|
97 |
|
98 ## original system is transfer function |
|
99 if (sys.sys(1) == 0) |
|
100 [sys.zer,sys.pol,sys.k] = tf2zp(sys.num,sys.den); |
|
101 sys.sys(3) = 1; |
|
102 ## original system is state-space |
|
103 |
|
104 elseif(sys.sys(1) == 2) |
|
105 [sys.zer,sys.pol,sys.k] = ss2zp(sys.a,sys.b,sys.c,sys.d); |
|
106 sys.sys(3) = 1; |
|
107 endif |
|
108 |
|
109 endif |
|
110 |
|
111 ## update state-space if desired |
|
112 if ( (strcmp(opt, "ss") + strcmp(opt,"all")) && (! sys.sys(4)) ) |
|
113 ## original system is transfer function |
|
114 if (sys.sys(1) == 0) |
|
115 [sys.a,sys.b,sys.c,sys.d] = tf2ss(sys.num,sys.den); |
|
116 sys.sys(4) = 1; |
|
117 ## original system is zero-pole |
|
118 elseif(sys.sys(1) == 1) |
|
119 [sys.a,sys.b,sys.c,sys.d] = zp2ss(sys.zer,sys.pol,sys.k); |
|
120 sys.sys(4) = 1; |
|
121 endif |
|
122 |
|
123 ## create new state names |
3438
|
124 sys.stname = __sysdefstname__ (sys.n, sys.nz); |
3430
|
125 endif |
|
126 |
|
127 endfunction |