changeset 17230:86c45a04990f

spectral_xdf.m: Add input validation, add %!tests, and fix docstring * spectral_xdf.m: Add input validation, add %!tests, and fix docstring.
author Mike Miller <mtmiller@ieee.org>
date Tue, 13 Aug 2013 08:00:33 -0400
parents 2736bc7bf8d9
children 95a402f56b95
files scripts/signal/spectral_xdf.m
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- 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 <Friedrich.Leisch@ci.tuwien.ac.at>
@@ -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");