]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@tf/display.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @tf / display.m
1 ## Copyright (C) 2009, 2010, 2011, 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 ## Display routine for TF objects.
20
21 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
22 ## Created: September 2009
23 ## Version: 0.4
24
25 function display (sys)
26
27   sysname = inputname (1);
28   [inname, outname, tsam] = __lti_data__ (sys.lti);
29
30   [inname, m] = __labels__ (inname, "u");
31   [outname, p] = __labels__ (outname, "y");
32
33   disp ("");
34   
35   if (sys.inv)
36     [num, den] = filtdata (sys);
37   else
38     num = sys.num;
39     den = sys.den;
40   endif
41
42   for nu = 1 : m
43     disp (["Transfer function '", sysname, "' from input '", inname{nu}, "' to output ..."]);
44     disp ("");
45     for ny = 1 : p
46       __disp_frac__ (num{ny, nu}, den{ny, nu}, sys.tfvar, outname{ny});
47     endfor
48   endfor
49
50   display (sys.lti);  # display sampling time
51
52   if (tsam == -2)
53     disp ("Static gain.");
54   elseif (tsam == 0)
55     disp ("Continuous-time model.");
56   else
57     disp ("Discrete-time model.");
58   endif
59
60 endfunction
61
62
63 function __disp_frac__ (num, den, tfvar, name)
64
65   MAX_LEN = 12;  # max length of output name
66   
67   tfp = isa (num, "tfpoly");
68
69   if (num == tfpoly (0))
70     str = [" ", name, ":  0"];
71   elseif ((tfp && den == 1) || (! tfp && isequal (den, 1)))
72   ## elseif (den == tfpoly (1)) doesn't work because it
73   ## would mistakingly accept non-tfpoly denominators like [0, 1]
74     str = [" ", name, ":  "];
75     numstr = tfpoly2str (num, tfvar);
76     str = [str, numstr];
77   ##elseif (length (den) == 1)  # de-comment for non-development use
78   ##  str = [" ", name, ":  "];
79   ##  num = num * (1/get (den));
80   ##  numstr = tfpoly2str (num, tfvar);
81   ##  str = [str, numstr];
82   else
83     numstr = tfpoly2str (num, tfvar);
84     denstr = tfpoly2str (den, tfvar);
85     fracstr = repmat ("-", 1, max (length (numstr), length (denstr)));
86
87     str = strjust (strvcat (numstr, fracstr, denstr), "center");
88
89     namestr = name(:, 1 : min (MAX_LEN, end));
90     namestr = [namestr, ":  "];
91     namestr = strjust (strvcat (" ", namestr, " "), "left");
92     namestr = horzcat (repmat (" ", 3, 1), namestr);
93
94     str = [namestr, str];
95   endif
96
97   disp (str);
98   disp ("");
99
100 endfunction
101