]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@ss/__sys2tf__.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @ss / __sys2tf__.m
1 ## Copyright (C) 2009, 2011   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 ## SS to TF conversion.
20
21 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
22 ## Created: October 2009
23 ## Version: 0.3
24
25 function [retsys, retlti] = __sys2tf__ (sys)
26
27   try
28     [a, b, c, d, tsam, scaled] = ssdata (sys);  # system could be a descriptor model
29
30     [num, den, ign, igd, md, p, m] = sltb04bd (a, b, c, d, scaled);
31
32     num = reshape (num, md, p, m);
33     den = reshape (den, md, p, m);
34
35     num = mat2cell (num, md, ones(1,p), ones(1,m));
36     den = mat2cell (den, md, ones(1,p), ones(1,m));
37
38     num = squeeze (num);
39     den = squeeze (den);
40
41     ign = mat2cell (ign, ones(1,p), ones(1,m));
42     igd = mat2cell (igd, ones(1,p), ones(1,m));
43
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);
46   catch
47     ## sys.e was probably singular, therefore ssdata failed.
48     if (issiso (sys))
49       [num, den] = __siso_ss2tf__ (sys);
50     else
51       [p, m] = size (sys);
52       num = cell (p, m);
53       den = cell (p, m);
54       for i = 1 : p
55         for j = 1 : m
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);
60           num(i, j) = n;
61           den(i, j) = d;
62         endfor
63       endfor
64     endif
65     tsam = get (sys, "tsam");
66   end_try_catch
67
68   retsys = tf (num, den, tsam);                 # tsam needed to set appropriate tfvar
69   retlti = sys.lti;                             # preserve lti properties
70   
71   ## FIXME: sys = tf (ss (5))
72
73 endfunction
74
75
76 function [num, den] = __siso_ss2tf__ (sys)
77
78   if (isempty (sys.a))                          # static gain
79     num = sys.d;
80     den = 1;
81   else                                          # default case
82     [zer, gain] = zero (sys);
83     pol = pole (sys);
84     num = gain * real (poly (zer));
85     den = real (poly (pol));
86   endif
87
88 endfunction