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 |
4771
|
51 ## @seealso{tf, ss, zp, sysout, sys2ss, sys2tf, and sys2zp} |
3430
|
52 |
|
53 ## Author: John Ingram <ingraje@eng.auburn.edu> |
|
54 ## Created: July 9, 1996 |
|
55 |
|
56 function sys = sysupdate (sys, opt) |
|
57 |
|
58 ## check for correct number of inputs |
|
59 if (nargin != 2) |
|
60 usage("newsys = sysupdate(sys,opt)"); |
4030
|
61 elseif(! isstruct(sys) ) |
3430
|
62 error("1st argument must be system data structure") |
|
63 elseif(! (strcmp(opt,"tf") + strcmp(opt,"zp") + ... |
|
64 strcmp(opt,"ss") + strcmp(opt,"all")) ) |
|
65 error("2nd argument must be \"tf\", \"zp\", \"ss\", or \"all\""); |
|
66 endif |
|
67 |
|
68 ## check to make sure not trying to make a SISO system out of a MIMO sys |
|
69 if ( (strcmp(opt,"tf") + strcmp(opt,"zp") + strcmp(opt,"all")) ... |
|
70 & strcmp(sysgettype(sys),"ss") & (! is_siso(sys) ) ) |
|
71 error("MIMO -> SISO update requested"); |
|
72 endif |
|
73 |
|
74 ## update transfer function if desired |
|
75 if ( (strcmp(opt, "tf") + strcmp(opt,"all"))&& (!sys.sys(2))) |
|
76 ## check to make sure the system is not discrete and continuous |
|
77 is_digital(sys); |
|
78 |
|
79 ## if original system zero-pole |
|
80 if strcmp(sysgettype(sys),"zp") |
|
81 [sys.num,sys.den] = zp2tf(sys.zer,sys.pol,sys.k); |
|
82 sys.sys(2) = 1; |
|
83 ## if original system is state-space |
|
84 elseif(sys.sys(1) == 2) |
|
85 [sys.num,sys.den] = ss2tf(sys.a,sys.b,sys.c,sys.d); |
|
86 sys.sys(2) = 1; |
|
87 endif |
|
88 endif |
|
89 |
|
90 |
|
91 ## update zero-pole if desired |
|
92 if ( (strcmp(opt, "zp") + strcmp(opt,"all")) && (! sys.sys(3)) ) |
|
93 ## check to make sure the system is not discrete and continuous |
|
94 is_digital(sys); |
|
95 |
|
96 ## original system is transfer function |
|
97 if (sys.sys(1) == 0) |
|
98 [sys.zer,sys.pol,sys.k] = tf2zp(sys.num,sys.den); |
|
99 sys.sys(3) = 1; |
|
100 ## original system is state-space |
|
101 |
|
102 elseif(sys.sys(1) == 2) |
|
103 [sys.zer,sys.pol,sys.k] = ss2zp(sys.a,sys.b,sys.c,sys.d); |
|
104 sys.sys(3) = 1; |
|
105 endif |
|
106 |
|
107 endif |
|
108 |
|
109 ## update state-space if desired |
|
110 if ( (strcmp(opt, "ss") + strcmp(opt,"all")) && (! sys.sys(4)) ) |
|
111 ## original system is transfer function |
|
112 if (sys.sys(1) == 0) |
|
113 [sys.a,sys.b,sys.c,sys.d] = tf2ss(sys.num,sys.den); |
|
114 sys.sys(4) = 1; |
|
115 ## original system is zero-pole |
|
116 elseif(sys.sys(1) == 1) |
|
117 [sys.a,sys.b,sys.c,sys.d] = zp2ss(sys.zer,sys.pol,sys.k); |
|
118 sys.sys(4) = 1; |
|
119 endif |
|
120 |
|
121 ## create new state names |
3438
|
122 sys.stname = __sysdefstname__ (sys.n, sys.nz); |
3430
|
123 endif |
|
124 |
|
125 endfunction |