function y = ifftshift(x)
%IFFTSHIFT Inverse FFT shift.
%   For vectors, IFFTSHIFT(X) swaps the left and right halves of
%   X.  For matrices, IFFTSHIFT(X) swaps the first and third
%   quadrants and the second and fourth quadrants.  For N-D
%   arrays, IFFTSHIFT(X) swaps "half-spaces" of X along each
%   dimension.
%
%   IFFTSHIFT undoes the effects of FFTSHIFT.
%
%   See also FFTSHIFT, FFT, FFT2, FFTN.

%   J.N. Little 6-23-86
%   Revised for N-D by Steve Eddins, February 1997
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.2 $  $Date: 1997/11/21 23:23:52 $

numDims = ndims(x);
idx = cell(1, numDims);
for k = 1:numDims
    m = size(x, k);
    p = floor(m/2);
    idx{k} = [p+1:m 1:p];
end

% Use comma-separated list syntax for N-D indexing.
y = x(idx{:});
