]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/tfdata.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / tfdata.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 ## @deftypefn {Function File} {[@var{num}, @var{den}, @var{tsam}] =} tfdata (@var{sys})
20 ## @deftypefnx {Function File} {[@var{num}, @var{den}, @var{tsam}] =} tfdata (@var{sys}, @var{"vector"})
21 ## @deftypefnx {Function File} {[@var{num}, @var{den}, @var{tsam}] =} tfdata (@var{sys}, @var{"tfpoly"})
22 ## Access transfer function data.
23 ## Argument @var{sys} is not limited to transfer function models.
24 ## If @var{sys} is not a transfer function, it is converted automatically.
25 ##
26 ## @strong{Inputs}
27 ## @table @var
28 ## @item sys
29 ## Any type of LTI model.
30 ## @item "v", "vector"
31 ## For SISO models, return @var{num} and @var{den} directly as column vectors
32 ## instead of cells containing a single column vector.
33 ## @end table
34 ##
35 ## @strong{Outputs}
36 ## @table @var
37 ## @item num
38 ## Cell of numerator(s).  Each numerator is a row vector
39 ## containing the coefficients of the polynomial in descending powers of
40 ## the transfer function variable.
41 ## num@{i,j@} contains the numerator polynomial from input j to output i.
42 ## In the SISO case, a single vector is possible as well.
43 ## @item den
44 ## Cell of denominator(s).  Each denominator is a row vector
45 ## containing the coefficients of the polynomial in descending powers of
46 ## the transfer function variable.
47 ## den@{i,j@} contains the denominator polynomial from input j to output i.
48 ## In the SISO case, a single vector is possible as well.
49 ## @item tsam
50 ## Sampling time in seconds.  If @var{sys} is a continuous-time model,
51 ## a zero is returned.
52 ## @end table
53 ## @end deftypefn
54
55 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
56 ## Created: September 2009
57 ## Version: 0.5
58
59 function [num, den, tsam] = tfdata (sys, rtype = "cell")
60
61   if (! isa (sys, "tf"))
62     sys = tf (sys);
63   endif
64
65   [num, den] = __sys_data__ (sys); 
66
67   tsam = sys.tsam;
68
69   if (! strncmpi (rtype, "t", 1))                # != tfpoly
70     num = cellfun (@get, num, "uniformoutput", false);
71     den = cellfun (@get, den, "uniformoutput", false);
72   endif
73
74   if (strncmpi (rtype, "v", 1) && issiso (sys))  # == vector
75     num = num{1};
76     den = den{1};
77   endif
78
79 endfunction