# HG changeset patch # User Mike Miller # Date 1376395424 14400 # Node ID 95a402f56b959ae8bfa53cf5ba014d0915a223ac # Parent 86c45a04990f7fc86f2cf7f8f0ce382936f3d394 spectral_adf.m: Add input validation, add %!tests, and fix docstring * spectral_adf.m: Add input validation, add %!tests, and fix docstring. diff -r 86c45a04990f -r 95a402f56b95 scripts/signal/spectral_adf.m --- a/scripts/signal/spectral_adf.m Tue Aug 13 08:00:33 2013 -0400 +++ b/scripts/signal/spectral_adf.m Tue Aug 13 08:03:44 2013 -0400 @@ -17,16 +17,19 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} spectral_adf (@var{c}, @var{win}, @var{b}) +## @deftypefn {Function File} {} spectral_adf (@var{c}) +## @deftypefnx {Function File} {} spectral_adf (@var{c}, @var{win}) +## @deftypefnx {Function File} {} spectral_adf (@var{c}, @var{win}, @var{b}) ## Return the spectral density estimator given a vector of ## autocovariances @var{c}, window name @var{win}, and bandwidth, ## @var{b}. ## ## The window name, e.g., @code{"triangle"} or @code{"rectangle"} is -## used to search for a function called @code{@var{win}_sw}. +## used to search for a function called @code{@var{win}_lw}. ## ## If @var{win} is omitted, the triangle window is used. If @var{b} is ## omitted, @code{1 / sqrt (length (@var{x}))} is used. +## @seealso{spectral_xdf} ## @end deftypefn ## Author: FL @@ -34,6 +37,10 @@ function retval = spectral_adf (c, win, b) + if (nargin < 1 || nargin > 3) + print_usage (); + endif + cr = length (c); if (columns (c) > 1) @@ -46,6 +53,8 @@ if (nargin == 1) w = triangle_lw (cr, b); + elseif (! ischar (win)) + error ("spectral_adf: WIN must be a string"); else win = str2func ([win "_lw"]); w = feval (win, cr, b); @@ -59,7 +68,8 @@ endfunction - - - - +%% Test input validation +%!error spectral_adf (); +%!error spectral_adf (1, 2, 3, 4); +%!error spectral_adf (1, 2); +%!error spectral_adf (1, "invalid");