]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/filtdata.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / filtdata.m
1 ## Copyright (C) 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}] =} filtdata (@var{sys})
20 ## @deftypefnx {Function File} {[@var{num}, @var{den}, @var{tsam}] =} filtdata (@var{sys}, @var{"vector"})
21 ## Access discrete-time transfer function data in DSP format.
22 ## Argument @var{sys} is not limited to transfer function models.
23 ## If @var{sys} is not a transfer function, it is converted automatically.
24 ##
25 ## @strong{Inputs}
26 ## @table @var
27 ## @item sys
28 ## Any type of discrete-time LTI model.
29 ## @item "v", "vector"
30 ## For SISO models, return @var{num} and @var{den} directly as column vectors
31 ## instead of cells containing a single column vector.
32 ## @end table
33 ##
34 ## @strong{Outputs}
35 ## @table @var
36 ## @item num
37 ## Cell of numerator(s).  Each numerator is a row vector
38 ## containing the coefficients of the polynomial in ascending powers of z^-1.
39 ## num@{i,j@} contains the numerator polynomial from input j to output i.
40 ## In the SISO case, a single vector is possible as well.
41 ## @item den
42 ## Cell of denominator(s).  Each denominator is a row vector
43 ## containing the coefficients of the polynomial in ascending powers of z^-1.
44 ## den@{i,j@} contains the denominator polynomial from input j to output i.
45 ## In the SISO case, a single vector is possible as well.
46 ## @item tsam
47 ## Sampling time in seconds.  If @var{tsam} is not specified, -1 is returned.
48 ## @end table
49 ## @end deftypefn
50
51 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
52 ## Created: April 2012
53 ## Version: 0.1
54
55 function [num, den, tsam] = filtdata (sys, rtype = "cell")
56
57   if (nargin > 2)
58     print_usage ();
59   endif
60
61   if (! isdt (sys))
62     error ("lti: filtdata: require discrete-time system");
63   endif
64
65   [num, den, tsam] = tfdata (sys);
66   
67   ## make numerator and denominator polynomials equally long
68   ## by adding leading zeros
69   lnum = cellfun (@length, num, "uniformoutput", false);
70   lden = cellfun (@length, den, "uniformoutput", false);
71
72   lmax = cellfun (@max, lnum, lden, "uniformoutput", false);
73
74   num = cellfun (@prepad, num, lmax, "uniformoutput", false);
75   den = cellfun (@prepad, den, lmax, "uniformoutput", false);
76       
77   ## remove trailing zeros
78   ## such that polynomials are as short as possible
79   num = cellfun (@__remove_trailing_zeros__, num, "uniformoutput", false);
80   den = cellfun (@__remove_trailing_zeros__, den, "uniformoutput", false);
81
82   if (strncmpi (rtype, "v", 1) && issiso (sys))
83     num = num{1};
84     den = den{1};
85   endif
86
87 endfunction