1 ## Copyright (C) 2012 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 ## @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.
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.
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.
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.
47 ## Sampling time in seconds. If @var{tsam} is not specified, -1 is returned.
51 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
52 ## Created: April 2012
55 function [num, den, tsam] = filtdata (sys, rtype = "cell")
62 error ("lti: filtdata: require discrete-time system");
65 [num, den, tsam] = tfdata (sys);
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);
72 lmax = cellfun (@max, lnum, lden, "uniformoutput", false);
74 num = cellfun (@prepad, num, lmax, "uniformoutput", false);
75 den = cellfun (@prepad, den, lmax, "uniformoutput", false);
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);
82 if (strncmpi (rtype, "v", 1) && issiso (sys))