MATLAB 中的fft 后为何要用fftshift? 分类: Matlab 2011-08-15 10:52 581 人阅读 评论(0) 收藏 举报 fft 是一维傅里叶变换,即将时域信号转换为频域信号 fftshift 是针对频域的,将 FFT 的DC 分量移到频谱中心 即对频域的图像,(假设用一条水平线和一条垂直线将频谱图分成四块)对这四块进行对角线的交换与反对角线的交换 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. fftshift 就是对换数据的左右两边比如 x=[1 2 3 4] fftshift(x) ->[3 4 1 2] IFFTSHIFT Inverse FFT shift.(就是fftshift 的逆) x=[1 2 3 4 5]; y=fftshift(x) y = 4 5 1 2 3 ifftshift(y) ans = 1 2 3 4 5 IFFTSHIFT undoes the effects of FFTSHIFT. 注意:在使用matlab 的fft 及fftshift 时,应注意。 假定采样频率 fs,采样间隔 dt,采样点数 N。 fft 后,频率为(0:N-1)/N/dt 进行 fftshift 后,频率为 if mod(N,2)==0 n1=(0:N-1)-N/2; else n1=(0:N-1)-(N-1)/2; end 实际上,频率为 N 点为周期的,所以 (0:N-1) 所以,对于频率 0,1,2,3,4,实际上为 0,1,2,-2(3-5),-1(4-5)。 fftshift 后的频率为 -2,-1,0,1,2 对于二维 fftshift,其与直接用下面的结果一样 if mod(tempN,2)==0 kx =(0:tempM-1)/tempM/dx -tempM/2/tempM/dx ;% kx =kx *2*pi else kx =(0:tempM-1)/tempM/dx -(tempM-1)/2/tempM/dx ;% kx =kx *2*pi end kx=kx*2*pi; if mod(tempM,2)==0 ky=(0:tempN-1)/tempN/dy-tempN/2/tempN/dy;% kx=kx*2*pi else ky=(0:tempN-1)/tempN/dy-(tempN-1)/2/tempN/dy;% kx=kx*2*pi end ky=ky*2*pi; temp1=sqrt(kx.^2+ky.^2); k1=temp1; [kx,ky]=meshgrid(kx,k...