]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/series.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / series.m
1 ## Copyright (C) 2009, 2010   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} =} series (@var{sys1}, @var{sys2})
20 ## @deftypefnx {Function File} {@var{sys} =} series (@var{sys1}, @var{sys2}, @var{outputs1}, @var{inputs2})
21 ## Series connection of two LTI models.
22 ##
23 ## @strong{Block Diagram}
24 ## @example
25 ## @group
26 ##     .....................................
27 ##  u  :  +--------+ y1    u2  +--------+  :  y
28 ## ------>|  sys1  |---------->|  sys2  |------->
29 ##     :  +--------+           +--------+  :
30 ##     :................sys.................
31 ##
32 ## sys = series (sys1, sys2)
33 ## @end group
34 ## @end example
35 ## @example
36 ## @group
37 ##     .....................................
38 ##     :                   v2  +--------+  :
39 ##     :            ---------->|        |  :  y
40 ##     :  +--------+ y1    u2  |  sys2  |------->
41 ##  u  :  |        |---------->|        |  :
42 ## ------>|  sys1  |       z1  +--------+  :
43 ##     :  |        |---------->            :
44 ##     :  +--------+                       :
45 ##     :................sys.................
46 ##
47 ## outputs1 = [1]
48 ## inputs2 = [2]
49 ## sys = series (sys1, sys2, outputs1, inputs2)
50 ## @end group
51 ## @end example
52 ## @end deftypefn
53
54 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
55 ## Created: September 2009
56 ## Version: 0.2
57
58 function sys = series (sys1, sys2, out1, in2)
59
60   if (nargin == 2)
61     sys = sys2 * sys1;
62   elseif (nargin == 4)
63     [p1, m1] = size (sys1);
64     [p2, m2] = size (sys2);
65
66     if (! is_real_vector (out1))
67       error ("series: argument 3 (outputs1) invalid");
68     endif
69
70     if (! is_real_vector (in2))
71       error ("series: argument 4 (inputs2) invalid");
72     endif
73
74     l_out1 = length (out1);
75     l_in2 = length (in2);
76
77     if (l_out1 > p1)
78       error ("series: outputs1 has too many indices for sys1");
79     endif
80
81     if (l_in2 > m2)
82       error ("series: inputs2 has too many indices for sys2");
83     endif
84
85     if (l_out1 != l_in2)
86       error ("series: number of outputs1 and inputs2 indices must be equal");
87     endif
88
89     if (any (out1 > m1 | out1 < 1))
90       error ("series: range of outputs1 indices exceeds dimensions of sys1");
91     endif
92
93     if (any (in2 > p1 | in2 < 1))
94       error ("series: range of inputs2 indices exceeds dimensions of sys2");
95     endif
96
97     out_scl = full (sparse (1:l_out1, out1, 1, l_out1, p1));
98     in_scl = full (sparse (in2, 1:l_out1, 1, m2, l_in2));
99     
100     ## NOTE: for-loop does NOT the same as
101     ##       out_scl(1:l_out1, out1) = 1;
102     ##       in_scl(in2, 1:l_out1) = 1;
103     ##
104     ## out_scl = zeros (l_out1, p1);
105     ## in_scl = zeros (m2, l_in2);
106     ##
107     ## for k = 1 : l_out1
108     ##   out_scl(k, out1(k)) = 1;
109     ##   in_scl(in2(k), k) = 1;
110     ## endfor
111
112     scl = in_scl * out_scl;
113     sys = sys2 * scl * sys1;
114   else
115     print_usage ();
116   endif
117
118 endfunction