FFT is a one-dimensional Fourier transformation that converts time-domain signals to frequency-domain signals.
Fftshift
Is for the frequency domain, moving the DC component of FFT to the spectrum Center
That is, for the image in the frequency domain (assuming that a horizontal line and a vertical line are used to divide the spectrum into four blocks), the diagonal line switching and the inverse diagonal line switching are performed on the four blocks.
FftshiftShift zero-frequency component to center of spectrum.
For vectors, fftshift (x) swaps (switching) the left and right halves
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
Dimension dim.
Fftshift is useful for visualizing the Fourier transform
The zero-frequency component in the middle of the spectrum.
Fftshift refers to swap the left and right sides of the data, for example
X = [1 2 3 4]
Fftshift (x)-> [3 4 1 2]
Ifftshift inverse FFT shift. (that is, the inverse of 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.
Note: When Using FFT and fftshift of Matlab, pay attention to them.
Assume that the sampling frequency is FS, the sampling interval is DT, and the number of sampling points is N.
After FFT, the frequency is (0: N-1)/n/dt
After fftshift, the frequency is
If Mod (n, 2) = 0
N1 = (0: N-1)-N/2;
Else
N1 = (0: N-1)-(N-1)/2;
End
In fact, the frequency is N points, so
(0: N-1)
Therefore, for frequencies 0, 1, 2, 4, it is actually 0, 1, 2,-2 (3-5),-1 (4-5 ).
The fftshift frequency is
-2,-1, 0, 1, 2
For two-dimensional fftshift, it is the same as directly using the following results
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, KY );
For example, the following program indicates that the above two are the same:
DX = 50e3;
DY = 50e3;
%
Tempn = 41;
Tempm = 41;
%
% Determining the wavenumber kx and KY
If Mod (tempm, 2) = 0
Kx = (0: tempM-1)-tempm/2; % kx = kx * 2 * pi
Else
Kx = (0: tempM-1)-(tempM-1)/2; % kx = kx * 2 * pi
End
Kx = kx * 2 * PI/tempm/dx;
If Mod (tempn, 2) = 0
Ky = (0: tempN-1)-tempn/2; % kx = kx * 2 * pi
Else
Ky = (0: tempN-1)-(tempN-1)/2; % kx = kx * 2 * pi
End
Ky = Ky * 2 * PI/tempn/dy;
[Kxx, kyy] = meshgrid (kx, KY );
K00 = SQRT (kx. ^ 2 + Ky. ^ 2 );
%
If Mod (tempm, 2) = 0
Temp1 = tempm/2-1;
Temp2 = (temp1 + 1) :( tempM-1 );
Temp2 = temp2-tempM;
Temp3 = [0: temp1, temp2];
Kx = temp3/tempm/dx; % kx = kx * 2 * pi
Else
Temp1 = (tempM-1)/2;
Temp2 = (temp1 + 1) :( tempM-1 );
Temp2 = temp2-tempM;
Temp3 = [0: temp1, temp2];
Kx = temp3/tempm/dx; % kx = kx * 2 * pi
End
Kx = kx * 2 * PI;
If Mod (tempn, 2) = 0
Temp1 = tempn/2-1;
Temp2 = (temp1 + 1) :( tempN-1 );
Temp2 = temp2-tempN;
Temp3 = [0: temp1, temp2];
Ky = temp3/tempn/dy; % kx = kx * 2 * pi
Else
Temp1 = (tempN-1)/2;
Temp2 = (temp1 + 1) :( tempN-1 );
Temp2 = temp2-tempN;
Temp3 = [0: temp1, temp2];
Ky = temp3/tempn/dy; % kx = kx * 2 * pi
End
Ky = Ky * 2 * PI;
[Kx, Ky] = meshgrid (kx, KY );
Kx = fftshift (kx );
Ky = fftshift (KY );
K = SQRT (kx. ^ 2 + Ky. ^ 2 );
Figure
Subplot (3, 1, 1), partition F (kxx-kx)
Subplot (3, 1, 2), partition F (kyy-ky)
Subplot (3,1, 3), effecf (k00-k)
%
Examples of FFT and fftshift:
CLF;
FS = 100; n = 256; % sampling frequency and data points
N = 0: N-1; t = N/Fs; % Time Series
X = 0.5 * sin (2 * pI * 15 * t) + 2 * sin (2 * pI * 40 * t); % Signal
Y1 = FFT (x, n); % fast Fourier transformation of the signal
Y2 = fftshift (Y1 );
Mag1 = ABS (Y1); % obtains the amplitude after Fourier transformation.
Mag2 = ABS (Y2 );
F1 = N * fs/N; % Frequency Sequence
F2 = N * fs/n-fs/2; % This is not necessarily correct
Subplot (3, 1, 1), plot (F1, mag1, 'R'); % plot the amplitude that changes with frequency
Xlabel ('frequency/Hz ');
Ylabel ('amplitude '); Title ('figure 1: Usual FFT', 'color', 'R'); grid on;
Subplot (3, 1, 2), plot (F2, mag1, 'B'); % plot the amplitude that changes with frequency
Xlabel ('frequency/Hz ');
Ylabel ('amplitude '); Title ('figure 2: FFT without fftshift', 'color', 'B'); grid on;
Subplot (3, 1, 3), plot (F2, mag2, 'C'); % plot the amplitude that changes with frequency
Xlabel ('frequency/Hz ');
Ylabel ('amplitude '); Title ('figure 3: FFT after fftshift', 'color', 'C'); grid on;