3213
|
1 # Copyright (C) 1996 A. Scottedward Hodel |
|
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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
|
19 function sys = sysupdate(sys,opt) |
|
20 # function retsys = sysupdate(sys,opt) |
|
21 # Update the internal representation of a system. |
|
22 # inputs: |
|
23 # sys: system data structure |
|
24 # opt: string: "tf" -> update transfer function |
|
25 # "zp" -> update zero-pole form |
|
26 # "ss" -> update state space form |
|
27 # "all" -> all of the above |
|
28 # outputs: retsys: contains union of data in sys and requested data. |
|
29 # if requested data in sys is already up to date then retsys=sys. |
|
30 # |
|
31 # conversion to tf or zp exits with an error if the system is |
|
32 # mixed continuous/digital |
|
33 # |
|
34 # see also: tf2sys, ss2sys, zp2sys, sysout, sys2ss, sys2tf, sys2zp |
|
35 |
|
36 # Written by John Ingram 7-9-96 |
|
37 # $Revision: 1.1.1.1 $ |
|
38 |
|
39 # check for correct number of inputs |
|
40 if (nargin != 2) |
|
41 usage("newsys = sysupdate(sys,opt)"); |
|
42 elseif(! is_struct(sys) ) |
|
43 error("1st argument must be system data structure") |
|
44 elseif(! (strcmp(opt,"tf") + strcmp(opt,"zp") + ... |
|
45 strcmp(opt,"ss") + strcmp(opt,"all")) ) |
|
46 error("2nd argument must be \"tf\", \"zp\", \"ss\", or \"all\""); |
|
47 endif |
|
48 |
|
49 # check to make sure not trying to make a SISO system out of a MIMO sys |
|
50 if ( (strcmp(opt,"tf") + strcmp(opt,"zp") + strcmp(opt,"all")) ... |
|
51 & (sys.sys(1) == 2) & (! is_siso(sys) ) ) |
|
52 error("MIMO -> SISO update requested"); |
|
53 endif |
|
54 |
|
55 # update transfer function if desired |
|
56 if ( (strcmp(opt, "tf") + strcmp(opt,"all"))&& (!sys.sys(2))) |
|
57 # check to make sure the system is not discrete and continuous |
|
58 is_digital(sys); |
|
59 |
|
60 # if original system zero-pole |
|
61 if (sys.sys(1) == 1) |
|
62 [sys.num,sys.den] = zp2tf(sys.zer,sys.pol,sys.k); |
|
63 sys.sys(2) = 1; |
|
64 # if original system is state-space |
|
65 elseif(sys.sys(1) == 2) |
|
66 [sys.num,sys.den] = ss2tf(sys.a,sys.b,sys.c,sys.d); |
|
67 sys.sys(2) = 1; |
|
68 endif |
|
69 endif |
|
70 |
|
71 |
|
72 # update zero-pole if desired |
|
73 if ( (strcmp(opt, "zp") + strcmp(opt,"all")) && (! sys.sys(3)) ) |
|
74 # check to make sure the system is not discrete and continuous |
|
75 is_digital(sys); |
|
76 |
|
77 # original system is transfer function |
|
78 if (sys.sys(1) == 0) |
|
79 [sys.zer,sys.pol,sys.k] = tf2zp(sys.num,sys.den); |
|
80 sys.sys(3) = 1; |
|
81 # original system is state-space |
|
82 |
|
83 elseif(sys.sys(1) == 2) |
|
84 [sys.zer,sys.pol,sys.k] = ss2zp(sys.a,sys.b,sys.c,sys.d); |
|
85 sys.sys(3) = 1; |
|
86 endif |
|
87 |
|
88 endif |
|
89 |
|
90 # update state-space if desired |
|
91 if ( (strcmp(opt, "ss") + strcmp(opt,"all")) && (! sys.sys(4)) ) |
|
92 # original system is transfer function |
|
93 if (sys.sys(1) == 0) |
|
94 [sys.a,sys.b,sys.c,sys.d] = tf2ss(sys.num,sys.den); |
|
95 sys.sys(4) = 1; |
|
96 # original system is zero-pole |
|
97 elseif(sys.sys(1) == 1) |
|
98 [sys.a,sys.b,sys.c,sys.d] = zp2ss(sys.zer,sys.pol,sys.k); |
|
99 sys.sys(4) = 1; |
|
100 endif |
|
101 |
|
102 # create new state names |
|
103 sys.stname = sysdefstname(sys.n, sys.nz); |
|
104 endif |
|
105 |
|
106 |
|
107 endfunction |