【Get深一度】MATLAB中对信号做 fft 后为何还要做 fftshift ?

来源:互联网 发布:台州房销售数据下载 编辑:程序博客网 时间:2024/05/18 00:29

FFTSHIFT: FFT shift & IFFTShift:Inverse FFT shift.

    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.


  • fftshift将频域零频分量搬移到频谱中心
  • 针对矢量信号,fftshift交换X的左右两半,如下:
  • x=[1 2 3 4]
    fftshift(x) ->[3 4 1 2]
  • x=[1     2     3     4     5];

    y=fftshift(x)

    y =

        4     5     1     2     3

    ifftshift(y)

    ans =

         1     2     3     4     5



  • 针对矩阵,fftshift 互换一、三象限和二、第四象限。  即对频域的图像,(假设用一条水平线和一条垂直线将频谱图分成四块)对这四块进行对角线的交换和反对角线的交换。 

   
    IFFTSHIFT undoes the effects of FFTSHIFT.


注意:在使用matlab的fft及fftshift时,应注意。

假定采样频率fs,采样间隔dt,采样点数N。

fft后,频率为(0:N-1)/N/dt


%%%%%%%%%%%

fft及fftshift示例:

clf;

fs=100;N=256;   %采样频率和数据点数

n=0:N-1;t=n/fs;   %时间序列

x=0.5*sin(2*pi*15*t)+2*sin(2*pi*40*t); %信号

y1=fft(x,N);    %对信号进行快速Fourier变换

y2=fftshift(y1);

mag1=abs(y1);     %求得Fourier变换后的振幅

mag2=abs(y2);    

f1=n*fs/N;    %频率序列

f2=n*fs/N-fs/2;%这个未必正确

subplot(3,1,1),plot(f1,mag1,'r');   %绘出随频率变化的振幅

xlabel('频率/Hz');

ylabel('振幅');title('图1:usual FFT','color','r');grid on;

subplot(3,1,2),plot(f2,mag1,'b');   %绘出随频率变化的振幅

xlabel('频率/Hz');

ylabel('振幅');title('图2:FFT without fftshift','color','b');grid on;

subplot(3,1,3),plot(f2,mag2,'c');   %绘出随频率变化的振幅

xlabel('频率/Hz');

ylabel('振幅');title('图3:FFT after fftshift','color','c');grid on;


0 0
原创粉丝点击