fftshift.sci

来自「小波分解源代码」· SCI 代码 · 共 41 行

SCI
41
字号
function y = fftshift(x,dim)
//FFTSHIFT Shift zero-frequency 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(X,DIM) applies the FFTSHIFT operation along the 
//   dimension DIM.
//
//   FFTSHIFT is useful for visualizing the Fourier transform with
//   the zero-frequency component in the middle of the spectrum.
//
//   See also IFFTSHIFT, FFT, FFT2, FFTN.
//
//   Copyright Aldo I Maalouf

[lsh,rsh]=argn();
if rsh > 1
    if (prod(size(dim)) ~= 1) | floor(dim) ~= dim | dim < 1
        error('DIM must be a positive integer.')
    end
    idx = repmat((':'), 1, max(ndims(x),dim));
    m = size(x, dim);
    p = ceil(m/2);
    idx(dim) = [p+1:m 1:p];
else
    numDims = ndims(x);
    idx = list(1, numDims);
    for k = 1:numDims
        m = size(x, k);
        p = ceil(m/2);
        idx(k) = [p+1:m 1:p];
    end
end

// Use comma-separated list syntax for N-D indexing.
y = x(idx(:));
endfunction

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?