1 ## Copyright (C) 2010, 2012 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 ## Block diagonal concatenation of two FRD models.
20 ## This file is part of the Model Abstraction Layer.
21 ## For internal use only.
23 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
24 ## Created: October 2010
27 function retsys = __sys_group__ (sys1, sys2)
29 if (! isa (sys1, "frd"))
30 sys1 = frd (sys1, sys2.w);
33 if (! isa (sys2, "frd"))
34 sys2 = frd (sys2, sys1.w);
38 retsys.lti = __lti_group__ (sys1.lti, sys2.lti);
40 lw1 = length (sys1.w);
41 lw2 = length (sys2.w);
43 [p1, m1, l1] = size (sys1.H);
44 [p2, m2, l2] = size (sys2.H);
46 ## TODO: tolerances for frequencies, i.e. don't check for equality
48 ## find intersection of frequency vectors
49 if (lw1 == lw2 && all (sys1.w == sys2.w)) # identical frequency vectors
53 else # differing frequency vectors
54 ## find common frequencies
55 retsys.w = w = intersect (sys1.w, sys2.w);
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);
61 ## extract common responses
62 H1 = sys1.H(:, :, w1_idx);
63 H2 = sys2.H(:, :, w2_idx);
66 ## block-diagonal concatenation
67 lw = length (retsys.w);
70 H1 = mat2cell (H1, p1, m1, ones (1, lw))(:);
71 H2 = mat2cell (H2, p2, m2, ones (1, lw))(:);
73 H = cellfun (@(x, y) [x, z12; z21, y], H1, H2, "uniformoutput", false);
75 retsys.H = cat (3, H{:});