First, the introduction of rapid Fourier
The Fourier principle indicates that any sequence or signal of continuous measurement can be expressed as an infinite superposition of cosine (or sine) wave signals of different frequencies. FFT is a fast algorithm for discrete Fourier transform, which can transform a signal into frequency domain. What is the use of it in practical applications?
1. Some signals in the time domain is difficult to see what characteristics, but if transformed into the frequency domain, it is easy to see the characteristics (frequency, amplitude, initial phase);
2.FFT can extract the spectrum of a signal, perform spectrum analysis, and prepare for subsequent filtering.
3. After a fast Fourier transform of the input and output signals of a system, a preliminary understanding of the system can be made by comparing the two.
Suppose sampling frequency FS, signal frequency f, signal length L, sample number N. Then the result of the FFT is a complex number of n points. Each point corresponds to a frequency point. The modulus of this point is the amplitude characteristic under the frequency value.
How does it relate to the magnitude of the original signal?
1. Assuming that the original signal peak is a, then the result of the FFT of each point (except the first point of the DC component) of the modulus of A is n/twice times, and the first point is the DC component (that is, 0Hz), its modulus is the DC component n times;
2. The phase of each point is the phase of the signal at that frequency. The first point represents the DC component, its phase is the initial phase of the frequency, matlab with a cos base, if the signal sine sin (t), then become a cos (T-PI/2) can be.
The sampling frequency FS is divided into n equal parts by N-1 points, and the frequency of each point increases sequentially. in order to facilitate the FFT operation, n is usually greater than 2 of the signal length l of the whole number of square.
For example, the frequency represented by a point n is: fn= (n-1) *fs/n. As can be seen from the above formula, FN can tell the frequency is fs/n. If the sampling frequency of FS is 1024Hz and the sample count is 1024 points, you can tell the 1Hz.
Sample rate of 1024Hz sampling 1024 points, just 1 seconds, that is, sampling 1 seconds of time signal and do FFT, the results can be analyzed to 1Hz. If the signal is sampled for 2 seconds, then N is 2048, and the FFT is done, the result can be analyzed to 0.5Hz.
If you want to increase the frequency resolution, you must increase the number of sampling points, which is the sampling time. Frequency resolution and sampling time are reciprocal relationships.
Fake after setting the FFT, a point n is expressed in complex a+bi, the modulus of the complex is an=sqrt (A*a+b*b), and the phase is pn=atan2 (b,a). Based on the above results, it is possible to calculate the expression of the corresponding signal of N point (n≠1, and N<=N/2): an/(N/2) *cos (2*PI*FN*T+PN), 2*an/n*cos (2*PI*FN*T+PN), and for the signal of N=1 Point, is the DC component, the amplitude is a1/n.
Because of the symmetry of the FFT results, we usually only use the results of the first half, which is less than half the sample frequency.
Ii. examples
Suppose we have a signal that contains a 5V DC component with a frequency of 50Hz, a phase of 30 degrees, an AC signal with a amplitude of 7V, and an AC signal with a frequency of 90Hz, a phase of 90 degrees, and a amplitude of 3V. The mathematical expression is:
x = 5 + 7*cos (2*pi*15*t-30*pi/180) + 3*cos (2*pi*40*t-90*pi/180).
We sampled this signal at a sample rate of 128Hz and sampled 256 points in total. According to our analysis above, fn= (n-1) *fs/n, we can know that the spacing between every two points is 0.5Hz. Our signal has 3 frequencies: 0Hz, 15Hz, 40Hz
For programming convenience, because the amplitude of the DC component is a1/n, the other point amplitude is an/(N/2), so the DC component is divided by 2.
The average FFT uses the same number of data points as the original containing the signal data points l, such a spectral map has a high quality, can reduce the effect of 0 or truncation.
Third, MATLAB code
Fs = 128; % Sample Frequency
T = 1/fs; % Sample Time
L = 256; % signal length
t = (0:l-1) *t; % Time
x = 5 + 7*cos (2*pi*15*t-30*pi/180) + 3*cos (2*pi*40*t-90*pi/180); %cos as base source signal
y = x + randn (size (t)); % Add noise
Figure
Plot (T,y)
Title (' Plus Noise signal ')
Xlabel (' time (s) ')
N = 2^nextpow2 (L); % sample points, the greater the number of sampling points, the more accurate the resolution of the frequency, n>=l, the part of the signal exceeds 0
Y = FFT (y,n)/n*2; % divided by n multiplied by 2 is the true amplitude, the greater the N, the higher the amplitude accuracy
f = fs/n* (0:1:n-1); % frequency
A = ABS (Y); % Amplitude Value
P = Angle (Y); % Phase Value
Figure
Subplot (211);p lot (f (1:N/2), A (1:N/2)); % function The data structure of the FFT return value is symmetric, so we only take the first half
Title (' Amplitude Spectrum ')
Xlabel (' Frequency (Hz) ')
Ylabel (' amplitude value ')
Subplot (212);p lot (f (1:N/2), P (1:N/2));
Title (' Phase Spectral frequency ')
Xlabel (' Frequency (Hz) ')
Ylabel (' phase ')
The original signal is x = 5 + 7*cos (2*pi*15*t-30*pi/180) + 3*cos (2*pi*40*t-90*pi/180);
It can be seen that the amplitude spectrum in 15Hz (corresponding to the mathematical expression of 15Hz), the amplitude of 7.063 (corresponding to 7), the phase spectrum of the initial phase-0.5072 (corresponding to the -30*pi/180)
40Hz in the amplitude spectrum (corresponds to 40Hz in mathematical expressions), amplitude 3.082 (corresponds to 3), initial phase in phase spectrum-1.57 (corresponds to -90*pi/180)
The following verifies that the fast Fourier transform in MATLAB is based on the Cos.
1. The original signal is changed to: x = 5 + 7*sin (2*pi*15*t-30*pi/180) + 3*sin (2*pi*40*t-90*pi/180); The original signal of the bottom of the%sin
The amplitude spectrum clearly corresponds to the correct, just verify the phase spectrum. Since sin (t + p1) =cos (t + p1-pi/2),
-30*PI/180-PI/2 =-2.0944, which corresponds to 2.093 of the phase spectrum
-90*PI/180-PI/2 =-3.1416, which corresponds to 3.057 of the phase spectrum
If you want to improve the accuracy of the results, you can increase the signal length L and the sampling point N.
2. If the original signal is x = 5 + 7*cos (2*pi*15*t-30*pi/180) + 3*sin (2*pi*40*t-90*pi/180); %sin and Cos as the base of the original signal
also verified correctly.
Fast Fourier transform of MATLAB