From: <par...@us...> - 2012-08-03 15:56:55
|
Revision: 10806 http://octave.svn.sourceforge.net/octave/?rev=10806&view=rev Author: paramaniac Date: 2012-08-03 15:56:49 +0000 (Fri, 03 Aug 2012) Log Message: ----------- control-devel: work on filter Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m 2012-08-03 15:38:45 UTC (rev 10805) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m 2012-08-03 15:56:49 UTC (rev 10806) @@ -25,22 +25,33 @@ ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> -## Created: April 2012 +## Created: August 2012 ## Version: 0.1 function dat = filter (dat, b, a = [], si = []) - if (nargin < 2 || nargin > 4 || ! isa (dat, "iddata")) + if (nargin < 2 || nargin > 4) print_usage (); endif + + if (! isa (dat, "iddata")) # there's at least one iddata set, but not as the first argument + error ("iddata: filter: first argument must be an iddata set"); + endif - if (isa (b, "lti") && issiso (b)) - si = a; - if (isct (b)) - tsam = dat.tsam; - b = c2d (b, tsam{1}); # does this make sense? + if (isa (b, "lti")) # filter (dat, sys) + if (nargin > 3) + print_usage (); endif + if (! issiso (b)) + error ("iddata: filter: second argument must be a SISO LTI system"); + endif + si = a; # filter (dat, sys, si) + if (isct (b)) # sys is continuous-time + b = c2d (b, dat.tsam{1}); # does this discretization/tsam make sense? + endif [b, a] = filtdata (b, "vector"); + elseif (nargin < 3) + print_usage (); endif dat.y = cellfun (@(y) filter (b, a, y, si, 1), dat.y, "uniformoutput", false); @@ -49,6 +60,7 @@ endfunction +## TODO: adapt test %!shared DATD, Z %! DAT = iddata ({[(1:10).', (1:2:20).'], [(10:-1:1).', (20:-2:1).']}, {[(41:50).', (46:55).'], [(61:70).', (-66:-1:-75).']}); %! DATD = detrend (DAT, "linear"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-03 20:30:48
|
Revision: 10808 http://octave.svn.sourceforge.net/octave/?rev=10808&view=rev Author: paramaniac Date: 2012-08-03 20:30:42 +0000 (Fri, 03 Aug 2012) Log Message: ----------- control-devel: save work in progress Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m 2012-08-03 19:49:11 UTC (rev 10807) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m 2012-08-03 20:30:42 UTC (rev 10808) @@ -22,6 +22,35 @@ ## removing the best fit of a polynomial of order @var{ord}. ## If @var{ord} is not specified, default value 0 is taken. ## This corresponds to removing a constant. +## +## @strong{Inputs} +## @table @var +## @item dat +## iddata identification dataset containing signals in time-domain. +## @item sys +## LTI object containing the discrete-time filter. +## @item b +## Numerator polynomial of the discrete-time filter. +## Must be a row vector containing the coefficients +## of the polynomial in ascending powers of z^-1. +## @item a +## Denominator polynomial of the discrete-time filter. +## Must be a row vector containing the coefficients +## of the polynomial in ascending powers of z^-1. +## @end table +## +## @strong{Outputs} +## @table @var +## @item dat +## iddata identification dataset in frequency-domain. +## In order to preserve signal power and noise level, +## the FFTs are normalized by dividing each transform +## by the square root of the signal length. +## The frequency values are distributed equally from 0 +## to the Nyquist frequency. The Nyquist frequency is +## only included for even signal lengths. +## @end table +## ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> @@ -38,6 +67,10 @@ error ("iddata: filter: first argument must be an iddata set"); endif + if (! dat.timedomain) + error ("iddata: filter: require iddata set in time-domain"); + endif + if (isa (b, "lti")) # filter (dat, sys) if (nargin > 3) print_usage (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-04 10:59:17
|
Revision: 10813 http://octave.svn.sourceforge.net/octave/?rev=10813&view=rev Author: paramaniac Date: 2012-08-04 10:59:11 +0000 (Sat, 04 Aug 2012) Log Message: ----------- control-devel: finish filter function, except for test Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m 2012-08-03 21:58:21 UTC (rev 10812) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/filter.m 2012-08-04 10:59:11 UTC (rev 10813) @@ -18,17 +18,18 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{dat} =} filter (@var{dat}, @var{sys}) ## @deftypefnx {Function File} {@var{dat} =} filter (@var{dat}, @var{b}, @var{a}) -## Detrend outputs and inputs of dataset @var{dat} by -## removing the best fit of a polynomial of order @var{ord}. -## If @var{ord} is not specified, default value 0 is taken. -## This corresponds to removing a constant. +## Filter output and input signals of dataset @var{dat}. +## The filter is specified either by @acronym{LTI} system @var{sys} +## or by transfer function polynomials @var{b} and @var{a} as described +## in the help text of the built-in filter command. Type @code{help filter} +## for more information. ## ## @strong{Inputs} ## @table @var ## @item dat ## iddata identification dataset containing signals in time-domain. ## @item sys -## LTI object containing the discrete-time filter. +## @acronym{LTI} object containing the discrete-time filter. ## @item b ## Numerator polynomial of the discrete-time filter. ## Must be a row vector containing the coefficients @@ -42,13 +43,8 @@ ## @strong{Outputs} ## @table @var ## @item dat -## iddata identification dataset in frequency-domain. -## In order to preserve signal power and noise level, -## the FFTs are normalized by dividing each transform -## by the square root of the signal length. -## The frequency values are distributed equally from 0 -## to the Nyquist frequency. The Nyquist frequency is -## only included for even signal lengths. +## iddata identification dataset with filtered +## output and input signals. ## @end table ## ## @end deftypefn @@ -63,7 +59,7 @@ print_usage (); endif - if (! isa (dat, "iddata")) # there's at least one iddata set, but not as the first argument + if (! isa (dat, "iddata")) # there's at least one iddata set, but not as the first argument error ("iddata: filter: first argument must be an iddata set"); endif @@ -71,22 +67,24 @@ error ("iddata: filter: require iddata set in time-domain"); endif - if (isa (b, "lti")) # filter (dat, sys) - if (nargin > 3) + if (isa (b, "lti")) # filter (dat, sys) + if (nargin > 3) # filter (dat, sys, si) has at most 3 inputs print_usage (); endif if (! issiso (b)) error ("iddata: filter: second argument must be a SISO LTI system"); endif - si = a; # filter (dat, sys, si) - if (isct (b)) # sys is continuous-time - b = c2d (b, dat.tsam{1}); # does this discretization/tsam make sense? + si = a; # filter (dat, sys, si) + if (isct (b)) # sys is continuous-time + b = c2d (b, dat.tsam{1}); # does this discretization/tsam make sense? endif - [b, a] = filtdata (b, "vector"); + [b, a] = filtdata (b, "vector"); # convert LTI system to transfer function elseif (nargin < 3) print_usage (); endif + ## use Octave's filter function for each experiment + ## the fifth argument '1' specifies the dimension in case of datasets with only 1 sample dat.y = cellfun (@(y) filter (b, a, y, si, 1), dat.y, "uniformoutput", false); dat.u = cellfun (@(u) filter (b, a, u, si, 1), dat.u, "uniformoutput", false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |