1 ## Copyright (C) 2009, 2011 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
19 ## @deftypefn {Function File} {@var{sys} =} c2d (@var{sys}, @var{tsam})
20 ## @deftypefnx {Function File} {@var{sys} =} c2d (@var{sys}, @var{tsam}, @var{method})
21 ## @deftypefnx {Function File} {@var{sys} =} c2d (@var{sys}, @var{tsam}, @var{"prewarp"}, @var{w0})
22 ## Convert the continuous lti model into its discrete-time equivalent.
27 ## Continuous-time LTI model.
29 ## Sampling time in seconds.
31 ## Optional conversion method. If not specified, default method @var{"zoh"}
35 ## Zero-order hold or matrix exponential.
36 ## @item "tustin", "bilin"
37 ## Bilinear transformation or Tustin approximation.
39 ## Bilinear transformation with pre-warping at frequency @var{w0}.
46 ## Discrete-time LTI model.
50 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
51 ## Created: October 2009
54 function sys = c2d (sys, tsam, method = "std", w0 = 0)
56 if (nargin < 2 || nargin > 4)
60 if (! isa (sys, "lti"))
61 error ("c2d: first argument is not an lti model");
65 error ("c2d: system is already discrete-time");
68 if (! issample (tsam))
69 error ("c2d: second argument is not a valid sample time");
72 if (! ischar (method))
73 error ("c2d: third argument is not a string");
76 if (! issample (w0, 0))
77 error ("c2d: fourth argument is not a valid pre-warping frequency");
80 sys = __c2d__ (sys, tsam, lower (method), w0);
86 ## bilinear transformation
87 ## using oct-file directly
101 %! [Ao, Bo, Co, Do] = slab04md (A, B, C, D, 1.0, 1.0, false);
103 %! Ae = [ -1.0000 -4.0000
104 %! -4.0000 -1.0000 ];
106 %! Be = [ 2.8284 0.0000
109 %! Ce = [ 0.0000 2.8284
112 %! De = [ -1.0000 0.0000
115 %! Mo = [Ao, Bo; Co, Do];
116 %! Me = [Ae, Be; Ce, De];
118 %!assert (Mo, Me, 1e-4);
121 ## bilinear transformation
136 %! [Ao, Bo, Co, Do] = ssdata (c2d (ss (A, B, C, D), 2, "tustin"));
138 %! Ae = [ -1.0000 -4.0000
139 %! -4.0000 -1.0000 ];
141 %! Be = [ 2.8284 0.0000
144 %! Ce = [ 0.0000 2.8284
147 %! De = [ -1.0000 0.0000
150 %! Mo = [Ao, Bo; Co, Do];
151 %! Me = [Ae, Be; Ce, De];
153 %!assert (Mo, Me, 1e-4);
156 ## bilinear transformation
171 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "tustin"), "tustin"));
173 %! Mo = [Ao, Bo; Co, Do];
174 %! Me = [A, B; C, D];
176 %!assert (Mo, Me, 1e-4);
194 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "zoh"), "zoh"));
196 %! Mo = [Ao, Bo; Co, Do];
197 %! Me = [A, B; C, D];
199 %!assert (Mo, Me, 1e-4);
202 ## bilinear transformation with pre-warping
217 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "prewarp", 1000), "prewarp", 1000));
219 %! Mo = [Ao, Bo; Co, Do];
220 %! Me = [A, B; C, D];
222 %!assert (Mo, Me, 1e-4);