1 ## Copyright (C) 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} =} d2c (@var{sys})
20 ## @deftypefnx {Function File} {@var{sys} =} d2c (@var{sys}, @var{method})
21 ## @deftypefnx {Function File} {@var{sys} =} d2c (@var{sys}, @var{"prewarp"}, @var{w0})
22 ## Convert the discrete lti model into its continuous-time equivalent.
27 ## Discrete-time LTI model.
29 ## Optional conversion method. If not specified, default method @var{"zoh"}
33 ## Zero-order hold or matrix logarithm.
34 ## @item "tustin", "bilin"
35 ## Bilinear transformation or Tustin approximation.
37 ## Bilinear transformation with pre-warping at frequency @var{w0}.
44 ## Continuous-time LTI model.
48 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
49 ## Created: September 2011
52 function sys = d2c (sys, method = "std", w0 = 0)
54 if (nargin == 0 || nargin > 3)
58 if (! isa (sys, "lti"))
59 error ("d2c: first argument is not an lti model");
63 error ("d2c: system is already continuous-time");
66 if (! ischar (method))
67 error ("d2c: second argument is not a string");
70 if (! issample (w0, 0))
71 error ("d2c: third argument is not a valid pre-warping frequency");
74 sys = __d2c__ (sys, sys.tsam, lower (method), w0);
80 ## bilinear transformation
95 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "tustin"), "tustin"));
97 %! Mo = [Ao, Bo; Co, Do];
100 %!assert (Mo, Me, 1e-4);
118 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "zoh"), "zoh"));
120 %! Mo = [Ao, Bo; Co, Do];
121 %! Me = [A, B; C, D];
123 %!assert (Mo, Me, 1e-4);
126 ## bilinear transformation with pre-warping
141 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "prewarp", 1000), "prewarp", 1000));
143 %! Mo = [Ao, Bo; Co, Do];
144 %! Me = [A, B; C, D];
146 %!assert (Mo, Me, 1e-4);