home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / DATAFUN.DI$ / FFTSHIFT.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  757 b   |  27 lines

  1. function y = fftshift(x)
  2. %FFTSHIFT Move zeroth lag to center of spectrum.
  3. %    Shift FFT.  For vectors FFTSHIFT(X) returns a vector with the
  4. %    left and right halves swapped.  For matrices, FFTSHIFT(X) swaps
  5. %    the first and third quadrants and the second and fourth quadrants.
  6. %    FFTSHIFT is useful for FFT processing, moving the zeroth lag to
  7. %    the center of the spectrum.
  8.  
  9. %    J.N. Little 6-23-86
  10. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  11.  
  12. [m,n] = size(x);
  13. m1 = 1:ceil(m/2);
  14. m2 = ceil(m/2)+1:m;
  15. n1 = 1:ceil(n/2);
  16. n2 = ceil(n/2+1):n;
  17.  
  18. % Note: can remove the first two cases when null handling is fixed.
  19. if m == 1
  20.     y = [x(n2) x(n1)];
  21. elseif n == 1
  22.     y = [x(m2); x(m1)];
  23. else
  24.     y = [x(m2,n2) x(m2,n1); x(m1,n2) x(m1,n1)];
  25. end
  26.  
  27.