annotate scripts/control/system/c2d.m @ 7016:93c65f2a5668

[project @ 2007-10-12 06:40:56 by jwe]
author jwe
date Fri, 12 Oct 2007 06:41:26 +0000
parents 8b0cfeb06365
children a1dbe9d80eee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1993, 1994, 1995 John W. Eaton
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
2 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
4 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## your option) any later version.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
9 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
13 ## General Public License for more details.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
14 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
18
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
20 ## @deftypefn {Function File} {} c2d (@var{sys}, @var{opt}, @var{t})
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
21 ## @deftypefnx {Function File} {} c2d (@var{sys}, @var{t})
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
22 ##
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
23 ## Converts the system data structure describing:
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
24 ## @iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
25 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
26 ## $$ \dot x = A_cx + B_cu $$
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
27 ## @end tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
28 ## @end iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
29 ## @ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
30 ## @example
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
31 ## .
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
32 ## x = Ac x + Bc u
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
33 ## @end example
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
34 ## @end ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
35 ## into a discrete time equivalent model:
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
36 ## @iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
37 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
38 ## $$ x_{n+1} = A_dx_n + B_du_n $$
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
39 ## @end tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
40 ## @end iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
41 ## @ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
42 ## @example
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
43 ## x[n+1] = Ad x[n] + Bd u[n]
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
44 ## @end example
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
45 ## @end ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
46 ## via the matrix exponential or bilinear transform.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
47 ##
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
48 ## @strong{Inputs}
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
49 ## @table @var
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
50 ## @item sys
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
51 ## system data structure (may have both continuous time and discrete
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
52 ## time subsystems)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
53 ## @item opt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
54 ## string argument; conversion option (optional argument;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
55 ## may be omitted as shown above)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
56 ## @table @code
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
57 ## @item "ex"
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
58 ## use the matrix exponential (default)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
59 ## @item "bi"
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
60 ## use the bilinear transformation
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
61 ## @iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
62 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
63 ## $$ s = { 2(z-1) \over T(z+1) } $$
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
64 ## @end tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
65 ## @end iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
66 ## @ifinfo
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
67 ## @example
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
68 ## 2(z-1)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
69 ## s = -----
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
70 ## T(z+1)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
71 ## @end example
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
72 ## @end ifinfo
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
73 ## FIXME: This option exits with an error if @var{sys} is not purely
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
74 ## continuous. (The @code{ex} option can handle mixed systems.)
3759
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
75 ## @item "matched"
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
76 ## Use the matched pole/zero equivalent transformation (currently only
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
77 ## works for purely continuous @acronym{SISO} systems).
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
78 ## @end table
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
79 ## @item t
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
80 ## sampling time; required if @var{sys} is purely continuous.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
81 ##
5479
adb2bac3596e [project @ 2005-10-03 18:56:03 by jwe]
jwe
parents: 5478
diff changeset
82 ## @strong{Note} that if the second argument is not a string, @code{c2d()}
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
83 ## assumes that the second argument is @var{t} and performs
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
84 ## appropriate argument checks.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
85 ## @end table
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
86 ##
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
87 ## @strong{Output}
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
88 ## @table @var
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
89 ## @item dsys
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
90 ## Discrete time equivalent via zero-order hold, sample each @var{t} sec.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4946
diff changeset
91 ## @end table
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
92 ##
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4771
diff changeset
93 ## This function adds the suffix @code{_d}
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
94 ## to the names of the new discrete states.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
95 ## @end deftypefn
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
96
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
97 ## Author: R. Bruce Tenison <btenison@eng.auburn.edu>
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
98 ## Created: October 1993
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
99 ## Updated by John Ingram for system data structure August 1996
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
100
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
101 function dsys = c2d (sys, opt, T)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
102 ## parse input arguments
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
103 if(nargin < 1 | nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5479
diff changeset
104 print_usage ();
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3775
diff changeset
105 elseif (!isstruct(sys))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
106 error("sys must be a system data structure");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
107 elseif (nargin == 1)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
108 opt = "ex";
5443
ec8c33dcd1bf [project @ 2005-09-08 01:40:57 by jwe]
jwe
parents: 5307
diff changeset
109 elseif (nargin == 2 & !ischar(opt) )
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
110 T = opt;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
111 opt = "ex";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
112 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
113
5443
ec8c33dcd1bf [project @ 2005-09-08 01:40:57 by jwe]
jwe
parents: 5307
diff changeset
114 if (! ischar (opt))
3759
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
115 error ("expecting option as a string");
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
116 endif
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
117
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
118 ## check if sampling period T was passed.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
119 Ts = sysgettsam(sys);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
120 if(!exist("T"))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
121 T = Ts;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
122 if(T == 0)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
123 error("sys is purely continuous; no sampling period T provided");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
124 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
125 elseif (T != Ts & Ts > 0)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
126 warning(["c2d: T=",num2str(T),", system tsam==",num2str(Ts), ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
127 ": using T=", num2str(min(T,Ts))]);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
128 T = min(T,Ts);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
129 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
130
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
131 if (!is_sample(T))
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6046
diff changeset
132 error("sampling period T must be a positive, real scalar");
3759
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
133 elseif (! (strcmp (opt, "ex")
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
134 || strcmp (opt, "bi")
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
135 || strcmp (opt, "matched")))
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
136 error ("invalid option passed: %s", opt);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
137 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
138
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
139 sys = sysupdate(sys,"ss");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
140 [n,nz,m,p] = sysdimensions(sys);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
141 if(n == 0)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
142 dsys = syssetsignals(sys,"yd",ones(1:p));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
143 elseif(strcmp(opt,"ex"));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
144 [aa,bb,cc,dd] = sys2ss(sys);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
145 crng= 1:n;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
146 drng = n+(1:nz);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
147
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
148 ## partition state equations into continuous, imaginary subsystems
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
149 Ac = aa(crng,crng);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
150 Bc = bb(crng,:);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
151 if(nz == 0)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
152 Acd = Adc = Add = Bd = 0;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
153 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
154 Acd = aa(crng,drng);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
155 Adc = aa(drng,crng);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
156 Add = aa(drng,drng);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
157 Bd = bb(drng,:);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
158 Bc = [Bc, Acd]; ## append discrete states as inputs to cont system
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
159 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
160
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
161 ## convert state equations
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
162 mat = [Ac, Bc; zeros(m+nz,n+nz+m)];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
163 matexp = expm(mat * T);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
164
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
165 ## replace Ac
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
166 aa(crng,crng) = matexp(crng,crng); ## discretized homegenous diff eqn
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
167
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
168 ## replace Bc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
169 bb(crng,:) = matexp(crng,n+(1:m));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
170
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
171 ## replace Acd
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
172 if(nz)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
173 aa(crng,drng) = matexp(crng,n+m+(1:nz));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
174 end
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
175
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
176 stnames = sysgetsignals(sys,"st"); ## continuous states renamed below
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
177 innames = sysgetsignals(sys,"in");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
178 outnames = sysgetsignals(sys,"out");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
179 outlist = 1:p;
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
180 dsys = ss(aa,bb,cc,dd,T,0,n+nz,stnames,innames, ...
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
181 outnames,outlist);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
182 ## rename states
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
183 for ii=1:n
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
184 strval = sprintf("%s_d",sysgetsignals(dsys,"st",ii,1));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
185 dsys = syssetsignals(dsys,"st",strval,ii);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
186 endfor
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
187
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
188 elseif(strcmp(opt,"bi"))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
189 if(is_digital(sys))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
190 error("c2d: system is already digital")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
191 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
192 ## convert with bilinear transform
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
193 [a,b,c,d,tsam,n,nz,stname,inname,outname,yd] = sys2ss(sys);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
194 IT = (2/T)*eye(size(a));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
195 A = (IT+a)/(IT-a);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
196 iab = (IT-a)\b;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
197 tk=2/sqrt(T);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
198 B = tk*iab;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
199 C = tk*(c/(IT-a));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
200 D = d + (c*iab);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
201 stnamed = strappend(stname,"_d");
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
202 dsys = ss(A,B,C,D,T,0,rows(A),stnamed,inname,outname);
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3759
diff changeset
203 endif
3759
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
204 elseif(strcmp(opt,"matched"))
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
205 if(is_digital(sys))
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
206 error("c2d: system is already digital");
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
207 elseif((length(sys.inname) != 1) || (length(sys.outname) != 1))
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
208 error("c2d: system in not single input, single output");
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
209 else
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
210 sys = sysupdate(sys,"zp");
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
211 p = exp(sys.pol*T);
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
212 z = exp(sys.zer*T);
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
213 infinite_zeros = max(size(sys.pol))-max(size(sys.zer))-1;
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
214 for i = 1:infinite_zeros
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
215 z = [z ; -1];
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
216 endfor
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
217 ## Should the freaquency we adjust around always be 1?
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
218 [cmag,cphase,cw] = bode(sys,1);
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
219 [dmag,dpahse,dw] = bode(zp(z,p,1,T),1);
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
220 dsys = zp(z,p,cmag/dmag,T);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
221 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
222 else
3759
110bc441a954 [project @ 2000-12-16 01:25:12 by jwe]
jwe
parents: 3502
diff changeset
223 error ("invalid option = %s", opt);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
224 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
225
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
226 endfunction