7017
|
1 ## Copyright (C) 1996, 2000, 2002, 2003, 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 -*- |
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. |
5642
|
51 ## @seealso{tf, ss, zp, sysout, sys2ss, sys2tf, sys2zp} |
3430
|
52 ## @end deftypefn |
|
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) |
6046
|
61 print_usage (); |
7136
|
62 elseif (! isstruct (sys)) |
|
63 error ("first argument must be system data structure"); |
|
64 elseif (! (strcmp (opt, "tf") || strcmp (opt, "zp") |
|
65 || strcmp (opt, "ss") || strcmp (opt, "all"))) |
|
66 error ("second argument must be \"tf\", \"zp\", \"ss\", or \"all\""); |
3430
|
67 endif |
|
68 |
|
69 ## check to make sure not trying to make a SISO system out of a MIMO sys |
7136
|
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"); |
3430
|
73 endif |
|
74 |
|
75 ## update transfer function if desired |
7136
|
76 if ((strcmp (opt, "tf") || strcmp (opt, "all")) && (! sys.sys(2))) |
3430
|
77 ## check to make sure the system is not discrete and continuous |
7136
|
78 is_digital (sys); |
3430
|
79 |
|
80 ## if original system zero-pole |
7136
|
81 if (strcmp (sysgettype (sys), "zp")) |
|
82 [sys.num, sys.den] = zp2tf (sys.zer, sys.pol, sys.k); |
3430
|
83 sys.sys(2) = 1; |
|
84 ## if original system is state-space |
7136
|
85 elseif (sys.sys(1) == 2) |
|
86 [sys.num, sys.den] = ss2tf (sys.a, sys.b, sys.c, sys.d); |
3430
|
87 sys.sys(2) = 1; |
|
88 endif |
|
89 endif |
|
90 |
|
91 |
|
92 ## update zero-pole if desired |
7136
|
93 if ((strcmp (opt, "zp") || strcmp (opt, "all")) && ! sys.sys(3)) |
3430
|
94 ## check to make sure the system is not discrete and continuous |
7136
|
95 is_digital (sys); |
3430
|
96 |
|
97 ## original system is transfer function |
|
98 if (sys.sys(1) == 0) |
7136
|
99 [sys.zer, sys.pol, sys.k] = tf2zp (sys.num, sys.den); |
3430
|
100 sys.sys(3) = 1; |
|
101 ## original system is state-space |
7136
|
102 elseif (sys.sys(1) == 2) |
|
103 [sys.zer, sys.pol, sys.k] = ss2zp (sys.a, sys.b, sys.c, sys.d); |
3430
|
104 sys.sys(3) = 1; |
|
105 endif |
|
106 endif |
|
107 |
|
108 ## update state-space if desired |
7136
|
109 if ((strcmp (opt, "ss") || strcmp (opt, "all")) && ! sys.sys(4)) |
3430
|
110 ## original system is transfer function |
|
111 if (sys.sys(1) == 0) |
7136
|
112 [sys.a, sys.b, sys.c, sys.d] = tf2ss (sys.num, sys.den); |
3430
|
113 sys.sys(4) = 1; |
|
114 ## original system is zero-pole |
7136
|
115 elseif (sys.sys(1) == 1) |
|
116 [sys.a, sys.b, sys.c, sys.d] = zp2ss (sys.zer, sys.pol, sys.k); |
3430
|
117 sys.sys(4) = 1; |
|
118 endif |
|
119 |
|
120 ## create new state names |
3438
|
121 sys.stname = __sysdefstname__ (sys.n, sys.nz); |
3430
|
122 endif |
|
123 |
|
124 endfunction |