1 ## Copyright (C) 2009, 2010 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} =} 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.
23 ## @strong{Block Diagram}
26 ## .....................................
27 ## u : +--------+ y1 u2 +--------+ : y
28 ## ------>| sys1 |---------->| sys2 |------->
29 ## : +--------+ +--------+ :
30 ## :................sys.................
32 ## sys = series (sys1, sys2)
37 ## .....................................
39 ## : ---------->| | : y
40 ## : +--------+ y1 u2 | sys2 |------->
41 ## u : | |---------->| | :
42 ## ------>| sys1 | z1 +--------+ :
45 ## :................sys.................
49 ## sys = series (sys1, sys2, outputs1, inputs2)
54 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
55 ## Created: September 2009
58 function sys = series (sys1, sys2, out1, in2)
63 [p1, m1] = size (sys1);
64 [p2, m2] = size (sys2);
66 if (! is_real_vector (out1))
67 error ("series: argument 3 (outputs1) invalid");
70 if (! is_real_vector (in2))
71 error ("series: argument 4 (inputs2) invalid");
74 l_out1 = length (out1);
78 error ("series: outputs1 has too many indices for sys1");
82 error ("series: inputs2 has too many indices for sys2");
86 error ("series: number of outputs1 and inputs2 indices must be equal");
89 if (any (out1 > m1 | out1 < 1))
90 error ("series: range of outputs1 indices exceeds dimensions of sys1");
93 if (any (in2 > p1 | in2 < 1))
94 error ("series: range of inputs2 indices exceeds dimensions of sys2");
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));
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;
104 ## out_scl = zeros (l_out1, p1);
105 ## in_scl = zeros (m2, l_in2);
107 ## for k = 1 : l_out1
108 ## out_scl(k, out1(k)) = 1;
109 ## in_scl(in2(k), k) = 1;
112 scl = in_scl * out_scl;
113 sys = sys2 * scl * sys1;