*** scripts/signal/fftshift.m.orig 2004-03-29 18:30:51.000000000 +0200 --- scripts/signal/fftshift.m 2004-03-29 18:37:10.000000000 +0200 *************** *** 19,24 **** --- 19,25 ---- ## -*- texinfo -*- ## @deftypefn {Function File} {} fftshift (@var{v}) + ## @deftypefnx {Function File} {} fftshift (@var{v}, @var{dim}) ## Perform a shift of the vector @var{v}, for use with the @code{fft} ## and @code{ifft} functions, in order the move the frequency 0 to the ## center of the vector or matrix. *************** *** 31,62 **** ## f = ((1:N) - ceil(N/2)) / N / Dt ## @end example ## ! ## If @var{v} is a matrix, the same holds for rows and columns. ## @end deftypefn ## Author: Vincent Cautaerts ## Created: July 1997 ## Adapted-By: jwe ! function retval = fftshift (V) retval = 0; ! if (nargin != 1) ! usage ("usage: fftshift (X)"); endif ! if (isvector (V)) ! x = length (V); ! xx = ceil (x/2); ! retval = V([xx+1:x, 1:xx]); ! elseif (ismatrix (V)) ! [x, y] = size (V); ! xx = ceil (x/2); ! yy = ceil (y/2); ! retval = V([xx+1:x, 1:xx], [yy+1:y, 1:yy]); else ! error ("fftshift: expecting vector or matrix argument"); endif endfunction --- 32,89 ---- ## f = ((1:N) - ceil(N/2)) / N / Dt ## @end example ## ! ## If @var{v} is a matrix, the same holds for rows and columns. If ! ## @var{v} is an array, then the same holds along each dimension. ! ## ! ## The optional @var{dim} argument can be used to limit the dimension ! ## along which the permutation occurs. ## @end deftypefn ## Author: Vincent Cautaerts ## Created: July 1997 ## Adapted-By: jwe ! function retval = fftshift (V, dim) retval = 0; ! if (nargin != 1 && nargin != 2) ! usage ("usage: fftshift (X, dim)"); endif ! if (nargin == 2) ! if (!isscalar (dim)) ! error ("fftshift: dimension must be an integer scalar"); ! endif ! nd = ndims (V); ! szd = size (V, dim); ! szd2 = ceil (szd / 2); ! idx = repmat ( ":,", nd, 1); ! idx (nd, : ) = ": "; ! if (dim == nd) ! idx (dim, :) = "[szd2+1:szd, 1:szd2]"; ! else ! idx (dim, :) = "[szd2+1:szd, 1:szd2],"; ! endif ! retval = eval ([" V (", transpose(transpose(idx)(:)), ");"]); else ! if (isvector (V)) ! x = length (V); ! xx = ceil (x/2); ! retval = V([xx+1:x, 1:xx]); ! elseif (ismatrix (V)) ! nd = ndims (V); ! sz = size (V); ! sz2 = ceil (sz ./ 2); ! cmd = ["retval = V ([", num2str(sz2(1)+1), ":", num2str(sz(1)), ", 1:", num2str(sz2(1)), "]"]; ! for i=2:nd ! cmd = [cmd, ",[", num2str(sz2(i)+1), ":", num2str(sz(i)), ", 1:", num2str(sz2(i)), "]"]; ! endfor ! cmd = [cmd, ");"]; ! eval (cmd); ! else ! error ("fftshift: expecting vector or matrix argument"); ! endif endif endfunction