]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@frd/__sys_group__.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @frd / __sys_group__.m
1 ## Copyright (C) 2010, 2012   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 ## Block diagonal concatenation of two FRD models.
20 ## This file is part of the Model Abstraction Layer.
21 ## For internal use only.
22
23 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
24 ## Created: October 2010
25 ## Version: 0.2
26
27 function retsys = __sys_group__ (sys1, sys2)
28
29   if (! isa (sys1, "frd"))
30     sys1 = frd (sys1, sys2.w);
31   endif
32
33   if (! isa (sys2, "frd"))
34     sys2 = frd (sys2, sys1.w);
35   endif
36
37   retsys = frd ();
38   retsys.lti = __lti_group__ (sys1.lti, sys2.lti);
39
40   lw1 = length (sys1.w);
41   lw2 = length (sys2.w);
42
43   [p1, m1, l1] = size (sys1.H);
44   [p2, m2, l2] = size (sys2.H);
45
46   ## TODO: tolerances for frequencies, i.e. don't check for equality
47
48   ## find intersection of frequency vectors
49   if (lw1 == lw2 && all (sys1.w == sys2.w))  # identical frequency vectors
50     retsys.w = sys1.w;
51     H1 = sys1.H;
52     H2 = sys2.H;
53   else                                       # differing frequency vectors
54     ## find common frequencies
55     retsys.w = w = intersect (sys1.w, sys2.w);
56
57     ## indices of common frequencies
58     w1_idx = arrayfun (@(x) find (sys1.w == x), w);
59     w2_idx = arrayfun (@(x) find (sys2.w == x), w);
60
61     ## extract common responses
62     H1 = sys1.H(:, :, w1_idx);
63     H2 = sys2.H(:, :, w2_idx);
64   endif
65
66   ## block-diagonal concatenation
67   lw = length (retsys.w);
68   z12 = zeros (p1, m2);
69   z21 = zeros (p2, m1);
70   H1 = mat2cell (H1, p1, m1, ones (1, lw))(:);
71   H2 = mat2cell (H2, p2, m2, ones (1, lw))(:);
72
73   H = cellfun (@(x, y) [x, z12; z21, y], H1, H2, "uniformoutput", false);
74
75   retsys.H = cat (3, H{:});
76
77 endfunction