1 ## Copyright (C) 2009, 2011 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 ## SS to TF conversion.
21 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
22 ## Created: October 2009
25 function [retsys, retlti] = __sys2tf__ (sys)
28 [a, b, c, d, tsam, scaled] = ssdata (sys); # system could be a descriptor model
30 [num, den, ign, igd, md, p, m] = sltb04bd (a, b, c, d, scaled);
32 num = reshape (num, md, p, m);
33 den = reshape (den, md, p, m);
35 num = mat2cell (num, md, ones(1,p), ones(1,m));
36 den = mat2cell (den, md, ones(1,p), ones(1,m));
41 ign = mat2cell (ign, ones(1,p), ones(1,m));
42 igd = mat2cell (igd, ones(1,p), ones(1,m));
44 num = cellfun (@(x, y) x(1:y+1), num, ign, "uniformoutput", false);
45 den = cellfun (@(x, y) x(1:y+1), den, igd, "uniformoutput", false);
47 ## sys.e was probably singular, therefore ssdata failed.
49 [num, den] = __siso_ss2tf__ (sys);
56 idx = substruct ("()", {i, j});
57 tmp = subsref (sys, idx); # extract siso model
58 tmp = minreal (tmp); # irreducible descriptor representation
59 [n, d] = __siso_ss2tf__ (tmp);
65 tsam = get (sys, "tsam");
68 retsys = tf (num, den, tsam); # tsam needed to set appropriate tfvar
69 retlti = sys.lti; # preserve lti properties
71 ## FIXME: sys = tf (ss (5))
76 function [num, den] = __siso_ss2tf__ (sys)
78 if (isempty (sys.a)) # static gain
82 [zer, gain] = zero (sys);
84 num = gain * real (poly (zer));
85 den = real (poly (pol));