changeset 13233:914c0b103a3d stable

fftshift.m: Better explain operation in docstring (Bug #33581). * fftshift.m: Improve docstring. Validate dimension input is truly a positive integer.
author Rik <octave@nomad.inbox5.com>
date Mon, 26 Sep 2011 11:43:20 -0700
parents 9b98affe52b9
children 00c5d8d3ee00
files scripts/signal/fftshift.m
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/signal/fftshift.m	Mon Sep 26 11:19:41 2011 -0700
+++ b/scripts/signal/fftshift.m	Mon Sep 26 11:43:20 2011 -0700
@@ -24,13 +24,15 @@
 ## center of the vector or matrix.
 ##
 ## If @var{x} is a vector of @math{N} elements corresponding to @math{N}
-## time samples spaced of @math{Dt} each, then @code{fftshift (fft
-## (@var{x}))} corresponds to frequencies
+## time samples spaced by @math{dt}, then
+## @code{fftshift (fft (@var{x}))} corresponds to frequencies
 ##
 ## @example
-## f = ((1:N) - ceil(N/2)) / N / Dt
+## f = [ -(ceil((N-1)/2):-1:1)*df 0 (1:floor((N-1)/2))*df ]
 ## @end example
 ##
+## where @math{df} = 1 / @math{dt}.
+##
 ## If @var{x} is a matrix, the same holds for rows and columns.  If
 ## @var{x} is an array, then the same holds along each dimension.
 ##
@@ -44,15 +46,13 @@
 
 function retval = fftshift (x, dim)
 
-  retval = 0;
-
   if (nargin != 1 && nargin != 2)
     print_usage ();
   endif
 
   if (nargin == 2)
-    if (!isscalar (dim))
-      error ("fftshift: dimension must be an integer scalar");
+    if (! (isscalar (dim) && dim > 0 && dim == fix (dim)))
+      error ("fftshift: dimension DIM must be a positive integer");
     endif
     nd = ndims (x);
     sz = size (x);
@@ -84,6 +84,7 @@
 
 endfunction
 
+
 %!test
 %!  x = [0:7];
 %!  y = fftshift (x);