Fast Fourier Transform
Discrete Fourier Transform (DFT)
As mentioned before, the Fourier transform of is
In many applications, it's difficult to find the functional form of , and even if it can be found, it's often not possible to find a closed-form solution for the integral. Therefore, in most cases, we use numerical methods to calculate the Fourier transform, with the most common method being the Discrete Fourier Transform (DFT).
Assuming the signal is sampled at points within an interval, with values , its DFT is defined as:
Note in the above equation, the value remains unchanged when increases by , so the main transformation values are .
Comparing the integral formula with the definition of DFT, we find some similarities. Since DFT deals with sampled signal values limited to points within an interval, we can consider the values calculated by DFT as approximate sampling values of .
According to the sampling theorem mentioned earlier, if the sampling rate is , then the signal frequency that can be restored ranges between [-, ], divided evenly into parts, each part size being
Here, is the sampling time interval, hence is the total time of the entire sampling interval. Some key properties of the DFT mentioned above are summarized as follows:
- Converts time sampling points into frequency sampling points , where is periodic with a period of .
- If the sampling rate is , the highest frequency value that can be determined is .
- The interval between sampling frequencies is the reciprocal of the total sampling time length.
DFT has many other important properties, three of which are listed below:
- DFT operation is linear, i.e., DFT() = DFT() + DFT().
- If is real, then , where * denotes the complex conjugate.
- Based on the DFT formula above, the inverse DFT is obtained as follows:
Fast Fourier Transform (FFT)
In calculating the DFT, many symmetries and conjugate properties in the formula can be used to speed up the computation process. This method of fast computation is known as the Fast Fourier Transform, abbreviated as FFT. FFT has various computational forms, but essentially, it is an algorithm for quickly calculating the DFT. The inverse of FFT is called the Inverse FFT, or IFFT.
In signal processing, we often use the Fast Fourier Transform (FFT) to calculate its spectrum. When using FFT, remember the following key points:
Assuming the signal segment used for analysis has points, and its sampling interval is , then the total length of this signal segment is , and the sampling rate is .
According to the sampling theorem, the observable frequency range is , where .
time-domain points become frequency-domain points after FFT, hence the frequency resolution, or the interval between adjacent frequency points, is . Simply put, the reciprocal of the total sampling time is the distance between frequency sampling points, which is the frequency resolution.
Remember half of the sampling rate is the maximum observable frequency; the reciprocal of the total sampling length is the frequency resolution.
For real functions, after performing FFT, the values for positive and negative frequencies will be complex conjugates of each other.
Now, let's observe the spectrum of the hat function. The graph of the rect(t) function is as follows:
The steps to observe its spectrum using MATLAB/Octave are as follows:
- Assuming the sampling range is from -1.5 to 1.5, taking a point every 0.1, calculate the time-domain signal:
t1 = -1.5:0.1:-0.6;
t2 = -0.4:0.1:0.4;
t3 = 0.6:0.1:1.5;
t = [t1 -0.5 t2 0.5 t3];
s = [zeros(size(t1)) 0.5 ones(size(t2)) 0.5 zeros(size(t3))];
plot(t, s);
This code snippet is a bit cumbersome but easy to understand. Run it to see if the result is correct.
- To calculate the spectrum, directly use the fft function to transform the above time-domain signal to the frequency domain. Note that the result will be complex, and we first observe its amplitude.
sf = fft(s);
plot(abs(sf));
Note that in the above program, when plotting, only the y-axis is provided, the x-axis will be the number of points, resulting in the following:
- As mentioned earlier, for the FFT of a real function, the positive and negative frequencies will be complex conjugates of each other. Actually, in the graph we see now, the right half should be moved to the negative side. MATLAB has a fftshift function that does just that. Additionally, the maximum frequency is half the sampling rate=5, the interval is the reciprocal of the total length=1/3, we need to add the x-axis (frequency) back.
sf = fft(s);
sf = abs(fftshift(sf));
f = -5:1/3:5;
plot(f, sf);
grid on;
Finally, the corrected graph is obtained as shown below, which is the amplitude of the sinc function.
The complete code is as follows:
t1 = -1.5:0.1:-0.6;
t2 = -0.4:0.1:0.4;
t3 = 0.6:0.1:1.5;
t = [t1 -0.5 t2 0.5 t3];
s = [zeros(size(t1)) 0.5 ones(size(t2)) 0.5 zeros(size(t3))];
sf = fft(s);
sf = abs(fftshift(sf));
f = -5:1/3:5;
plot(f, sf);
grid on;
Exercise 4
The spectrum graph above does not look very smooth. Please modify the program's parameters to make the plotted spectrum smoother.