# HG changeset patch # User Mike Miller # Date 1376395233 14400 # Node ID 86c45a04990f7fc86f2cf7f8f0ce382936f3d394 # Parent 2736bc7bf8d993070141512c3ac2396f597b2665 spectral_xdf.m: Add input validation, add %!tests, and fix docstring * spectral_xdf.m: Add input validation, add %!tests, and fix docstring. diff -r 2736bc7bf8d9 -r 86c45a04990f scripts/signal/spectral_xdf.m --- a/scripts/signal/spectral_xdf.m Tue Aug 13 07:52:40 2013 -0400 +++ b/scripts/signal/spectral_xdf.m Tue Aug 13 08:00:33 2013 -0400 @@ -17,7 +17,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} spectral_xdf (@var{x}, @var{win}, @var{b}) +## @deftypefn {Function File} {} spectral_xdf (@var{x}) +## @deftypefnx {Function File} {} spectral_xdf (@var{x}, @var{win}) +## @deftypefnx {Function File} {} spectral_xdf (@var{x}, @var{win}, @var{b}) ## Return the spectral density estimator given a data vector @var{x}, ## window name @var{win}, and bandwidth, @var{b}. ## @@ -26,6 +28,7 @@ ## ## 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_adf} ## @end deftypefn ## Author: FL @@ -33,6 +36,10 @@ function retval = spectral_xdf (x, win, b) + if (nargin < 1 || nargin > 3) + print_usage (); + endif + xr = length (x); if (columns (x) > 1) @@ -45,6 +52,8 @@ if (nargin == 1) w = triangle_sw (xr, b); + elseif (! ischar (win)) + error ("spectral_xdf: WIN must be a string"); else win = str2func ([win "_sw"]); w = feval (win, xr, b); @@ -60,3 +69,8 @@ endfunction +%% Test input validation +%!error spectral_xdf (); +%!error spectral_xdf (1, 2, 3, 4); +%!error spectral_xdf (1, 2); +%!error spectral_xdf (1, "invalid");