![]() |
Exploiting MATLAB's Data Structures |
Usage: Vectorize manipulation of cell arrays.
function y = fftshift(x)
%FFTSHIFT Shift DC component to center of spectrum.
% For vectors, FFTSHIFT(X) swaps the left and right halves of
% X. For matrices, FFTSHIFT(X) swaps the first and third
% quadrants and the second and fourth quadrants. For N-D
% arrays, FFTSHIFT(X) swaps "half-spaces" of X along each
% dimension.
%
% FFTSHIFT is useful for visualizing the Fourier transform with
% the DC component in the middle of the spectrum.
%
% See also FFT, FFT2, FFTN.
% J.N. Little 6-23-86
% Revised for N-D by Steve Eddins, February 1997
% Copyright (c) 1984-97 by The MathWorks, Inc.
% $Revision: 5.2 $ $Date: 1997/02/28 20:39:48 $
numDims = ndims(x);
idx = cell(1, numDims);
for k = 1:numDims
m = size(x, k);
p = ceil(m/2);
idx{k} = [p+1:m 1:p];
end
% Use comma-separated list syntax for N-D indexing.
y = x(idx{:});
![]()
Copyright © 1997 The MathWorks, Inc.
clay@mathworks.com
$Revision$ $Date$