1## Copyright (C) 1997, 1998, 2000, 2002, 2004, 2005, 2006, 2007, 2009
4## This file is part of Octave.
6## Octave is free software; you can redistribute it and/or modify it
7## under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
11## Octave is distributed in the hope that it will be useful, but
12## WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14## General Public License for more details.
16## You should have received a copy of the GNU General Public License
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
21## @deftypefn {Function File} {} fftshift (@var{v})
22## @deftypefnx {Function File} {} fftshift (@var{v}, @var{dim})
23## Perform a shift of the vector @var{v}, for use with the @code{fft}
24## and @code{ifft} functions, in order the move the frequency 0 to the
25## center of the vector or matrix.
27## If @var{v} is a vector of @math{N} elements corresponding to @math{N}
28## time samples spaced of @math{Dt} each, then @code{fftshift (fft
29## (@var{v}))} corresponds to frequencies
32## f = ((1:N) - ceil(N/2)) / N / Dt
35## If @var{v} is a matrix, the same holds for rows and columns. If
36## @var{v} is an array, then the same holds along each dimension.
38## The optional @var{dim} argument can be used to limit the dimension
39## along which the permutation occurs.
42## Author: Vincent Cautaerts <vincent@comf5.comm.eng.osaka-u.ac.jp>
46function retval = fftshift (V, dim)
50 if (nargin != 1 && nargin != 2)
56 error ("fftshift: dimension must be an integer scalar");
60 sz2 = ceil (sz(dim) / 2);
65 idx{dim} = [sz2+1:sz(dim), 1:sz2];
71 retval = V([xx+1:x, 1:xx]);
78 idx{i} = [sz2(i)+1:sz(i), 1:sz2(i)];
82 error ("fftshift: expecting vector or matrix argument");