From: <par...@us...> - 2012-04-21 17:27:01
|
Revision: 10307 http://octave.svn.sourceforge.net/octave/?rev=10307&view=rev Author: paramaniac Date: 2012-04-21 17:11:22 +0000 (Sat, 21 Apr 2012) Log Message: ----------- control: finish filt and filtdata, test & docstrings included Modified Paths: -------------- trunk/octave-forge/main/control/INDEX trunk/octave-forge/main/control/NEWS trunk/octave-forge/main/control/inst/@lti/filtdata.m trunk/octave-forge/main/control/inst/filt.m trunk/octave-forge/main/control/inst/test_control.m Added Paths: ----------- trunk/octave-forge/main/control/inst/__remove_trailing_zeros__.m Modified: trunk/octave-forge/main/control/INDEX =================================================================== --- trunk/octave-forge/main/control/INDEX 2012-04-21 14:03:37 UTC (rev 10306) +++ trunk/octave-forge/main/control/INDEX 2012-04-21 17:11:22 UTC (rev 10307) @@ -13,6 +13,7 @@ zpk Model Data Access @lti/dssdata + @lti/filtdata @lti/frdata @lti/get @lti/set Modified: trunk/octave-forge/main/control/NEWS =================================================================== --- trunk/octave-forge/main/control/NEWS 2012-04-21 14:03:37 UTC (rev 10306) +++ trunk/octave-forge/main/control/NEWS 2012-04-21 17:11:22 UTC (rev 10307) @@ -5,8 +5,12 @@ =============================================================================== ** filt, filtdata - -- Added function to specify disrete-time transfer functions in DSP format. + -- Added function "filt" to specify disrete-time transfer functions in DSP + format. + -- Added function "filtdata" to return any type of discrete-time LTI model + in DSP format. + =============================================================================== control-2.3.50 Release Date: 2012-03-06 Release Manager: Lukas Reichlin =============================================================================== Modified: trunk/octave-forge/main/control/inst/@lti/filtdata.m =================================================================== --- trunk/octave-forge/main/control/inst/@lti/filtdata.m 2012-04-21 14:03:37 UTC (rev 10306) +++ trunk/octave-forge/main/control/inst/@lti/filtdata.m 2012-04-21 17:11:22 UTC (rev 10307) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 Lukas F. Reichlin +## Copyright (C) 2012 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -16,42 +16,52 @@ ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{z}, @var{p}, @var{k}, @var{tsam}] =} zpkdata (@var{sys}) -## @deftypefnx {Function File} {[@var{z}, @var{p}, @var{k}, @var{tsam}] =} zpkdata (@var{sys}, @var{"v"}) -## Access zero-pole-gain data. +## @deftypefn {Function File} {[@var{num}, @var{den}, @var{tsam}] =} filtdata (@var{sys}) +## @deftypefnx {Function File} {[@var{num}, @var{den}, @var{tsam}] =} filtdata (@var{sys}, @var{"vector"}) +## Access discrete-time transfer function data in DSP format. +## Argument @var{sys} is not limited to transfer function models. +## If @var{sys} is not a transfer function, it is converted automatically. ## ## @strong{Inputs} ## @table @var ## @item sys -## Any type of LTI model. +## Any type of discrete-time LTI model. ## @item "v", "vector" -## For SISO models, return @var{z} and @var{p} directly as column vectors +## For SISO models, return @var{num} and @var{den} directly as column vectors ## instead of cells containing a single column vector. ## @end table ## ## @strong{Outputs} ## @table @var -## @item z -## Cell of column vectors containing the zeros for each channel. -## z@{i,j@} contains the zeros from input j to output i. -## @item p -## Cell of column vectors containing the poles for each channel. -## p@{i,j@} contains the poles from input j to output i. -## @item k -## Matrix containing the gains for each channel. -## k(i,j) contains the gain from input j to output i. +## @item num +## Cell of numerator(s). Each numerator is a row vector +## containing the coefficients of the polynomial in ascending powers of z^-1. +## num@{i,j@} contains the numerator polynomial from input j to output i. +## In the SISO case, a single vector is possible as well. +## @item den +## Cell of denominator(s). Each denominator is a row vector +## containing the coefficients of the polynomial in descending powers of z^-1. +## den@{i,j@} contains the denominator polynomial from input j to output i. +## In the SISO case, a single vector is possible as well. ## @item tsam -## Sampling time in seconds. If @var{sys} is a continuous-time model, -## a zero is returned. +## Sampling time in seconds. If @var{tsam} is not specified, -1 is returned. ## @end table ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> -## Created: September 2011 +## Created: April 2012 ## Version: 0.1 function [num, den, tsam] = filtdata (sys, rtype = "cell") + if (nargin > 2) + print_usage (); + endif + + if (! isdt (sys)) + error ("lti: filtdata: require discrete-time system"); + endif + [num, den, tsam] = tfdata (sys); ## make numerator and denominator polynomials equally long Added: trunk/octave-forge/main/control/inst/__remove_trailing_zeros__.m =================================================================== --- trunk/octave-forge/main/control/inst/__remove_trailing_zeros__.m (rev 0) +++ trunk/octave-forge/main/control/inst/__remove_trailing_zeros__.m 2012-04-21 17:11:22 UTC (rev 10307) @@ -0,0 +1,36 @@ +## Copyright (C) 2012 Lukas F. Reichlin +## +## This file is part of LTI Syncope. +## +## LTI Syncope is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## LTI Syncope is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## Remove trailing zeros from a polynomial, except for polynomials +## which are of length 1. For internal use only. + +## Author: Lukas Reichlin <luk...@gm...> +## Created: April 2012 +## Version: 0.1 + +function p = __remove_trailing_zeros__ (p) + + idx = find (p != 0); + + if (isempty (idx)) + p = 0; + else + p = p(1 : idx(end)); + endif + +endfunction Modified: trunk/octave-forge/main/control/inst/filt.m =================================================================== --- trunk/octave-forge/main/control/inst/filt.m 2012-04-21 14:03:37 UTC (rev 10306) +++ trunk/octave-forge/main/control/inst/filt.m 2012-04-21 17:11:22 UTC (rev 10307) @@ -121,15 +121,15 @@ endfunction - -function p = __remove_trailing_zeros__ (p) - - idx = find (p != 0); - - if (isempty (idx)) - p = 0; - else - p = p(1 : idx(end)); - endif - -endfunction \ No newline at end of file +%!shared num, den, n1, d1, n2, d2, n2e, d2e +%! num = [0, 3]; +%! den = [1, 4, 2]; +%! sys = filt (num, den); +%! [n1, d1] = filtdata (sys, "vector"); +%! [n2, d2] = tfdata (sys, "vector"); +%! n2e = [3, 0]; +%! d2e = [1, 4, 2]; +%!assert (n1, num, 1e-4); +%!assert (d1, den, 1e-4); +%!assert (n2, n2e, 1e-4); +%!assert (d2, d2e, 1e-4); Modified: trunk/octave-forge/main/control/inst/test_control.m =================================================================== --- trunk/octave-forge/main/control/inst/test_control.m 2012-04-21 14:03:37 UTC (rev 10306) +++ trunk/octave-forge/main/control/inst/test_control.m 2012-04-21 17:11:22 UTC (rev 10307) @@ -81,6 +81,7 @@ ## various m-files test ctrb +test filt test initial test issample test margin This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |