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