]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/d2c.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / d2c.m
1 ## Copyright (C) 2011   Lukas F. Reichlin
2 ##
3 ## This file is part of LTI Syncope.
4 ##
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.
9 ##
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.
14 ##
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/>.
17
18 ## -*- texinfo -*-
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.
23 ##
24 ## @strong{Inputs}
25 ## @table @var
26 ## @item sys
27 ## Discrete-time LTI model.
28 ## @item method
29 ## Optional conversion method.  If not specified, default method @var{"zoh"}
30 ## is taken.
31 ## @table @var
32 ## @item "zoh"
33 ## Zero-order hold or matrix logarithm.
34 ## @item "tustin", "bilin"
35 ## Bilinear transformation or Tustin approximation.
36 ## @item "prewarp"
37 ## Bilinear transformation with pre-warping at frequency @var{w0}.
38 ## @end table
39 ## @end table
40 ##
41 ## @strong{Outputs}
42 ## @table @var
43 ## @item sys
44 ## Continuous-time LTI model.
45 ## @end table
46 ## @end deftypefn
47
48 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
49 ## Created: September 2011
50 ## Version: 0.2
51
52 function sys = d2c (sys, method = "std", w0 = 0)
53
54   if (nargin == 0 || nargin > 3)
55     print_usage ();
56   endif
57
58   if (! isa (sys, "lti"))
59     error ("d2c: first argument is not an lti model");
60   endif
61
62   if (isct (sys))
63     error ("d2c: system is already continuous-time");
64   endif
65
66   if (! ischar (method))
67     error ("d2c: second argument is not a string");
68   endif
69
70   if (! issample (w0, 0))
71     error ("d2c: third argument is not a valid pre-warping frequency");
72   endif
73
74   sys = __d2c__ (sys, sys.tsam, lower (method), w0);
75   sys.tsam = 0;
76
77 endfunction
78
79
80 ## bilinear transformation
81 ## both directions
82 %!shared Mo, Me
83 %! A = [  1.0  0.5
84 %!        0.5  1.0 ];
85 %!
86 %! B = [  0.0 -1.0
87 %!        1.0  0.0 ];
88 %!
89 %! C = [ -1.0  0.0
90 %!        0.0  1.0 ];
91 %!
92 %! D = [  1.0  0.0
93 %!        0.0 -1.0 ];
94 %!
95 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "tustin"), "tustin"));
96 %!
97 %! Mo = [Ao, Bo; Co, Do];
98 %! Me = [A, B; C, D];
99 %!
100 %!assert (Mo, Me, 1e-4);
101
102
103 ## zero-order hold
104 ## both directions
105 %!shared Mo, Me
106 %! A = [  1.0  0.5
107 %!        0.5  1.0 ];
108 %!
109 %! B = [  0.0 -1.0
110 %!        1.0  0.0 ];
111 %!
112 %! C = [ -1.0  0.0
113 %!        0.0  1.0 ];
114 %!
115 %! D = [  1.0  0.0
116 %!        0.0 -1.0 ];
117 %!
118 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "zoh"), "zoh"));
119 %!
120 %! Mo = [Ao, Bo; Co, Do];
121 %! Me = [A, B; C, D];
122 %!
123 %!assert (Mo, Me, 1e-4);
124
125
126 ## bilinear transformation with pre-warping
127 ## both directions
128 %!shared Mo, Me
129 %! A = [  1.0  0.5
130 %!        0.5  1.0 ];
131 %!
132 %! B = [  0.0 -1.0
133 %!        1.0  0.0 ];
134 %!
135 %! C = [ -1.0  0.0
136 %!        0.0  1.0 ];
137 %!
138 %! D = [  1.0  0.0
139 %!        0.0 -1.0 ];
140 %!
141 %! [Ao, Bo, Co, Do] = ssdata (d2c (c2d (ss (A, B, C, D), 2, "prewarp", 1000), "prewarp", 1000));
142 %!
143 %! Mo = [Ao, Bo; Co, Do];
144 %! Me = [A, B; C, D];
145 %!
146 %!assert (Mo, Me, 1e-4);