Summary and analysis of FFT and fftshift commands in MATLAB

Source: Internet
Author: User

Http://wang-yg.diandian.com/post/2011-03-12/40028916801

Note: For reprint, please indicate the source -- by author.

We know that Fourier analysis is an important technology in signal processing. MATLAB provides powerful signal processing capabilities, but we need to pay attention to some details.
The start time of the recording signal f (t) is t_start, the end time is t_end, the sampling period is t_s, and the duration of the signal can be calculated as t_end-t_start, number of sampling points n = duration/t_s + 1 due to signal discretization;
According to the relevant conclusions of the Fourier analysis, we know that the sampling in the time domain will result in a periodic frequency domain. This period is the sampling frequency f_s (based on the famous Shannon sampling theorem ).
Therefore, after MATLAB's FFT function processing, the X-coordinate of the obtained data is 0: f_s/(N-1): f_s. The related code is as follows:
% Matlab fft test code
T_s = 0.01;
T_start = 0.5; t_end = 5;
T = t_start: t_s: t_end;
Y = 0.5 * sin (2 * pI * 15 * t) + 2 * sin (2 * pI * 40 * t );
Y_f = FFT (y );
Subplot (3, 1, 1 );
Plot (T, Y); Title ('original signal ');
Duration = t_end-t_start;
Sampling_points = duration/t_s + 1;
F_s = 1/t_s;
F_x = 0: f_s/(Sampling_points-1): f_s;
Subplot (3, 1, 2 );
Plot (f_x, ABS (y_f); Title ('fft transform ');
Subplot (3, 1, 3 );
Plot (f_x-f_s/2, ABS (fftshift (y_f); Title ('shift FFT transform ');
That is to say, if we do not use fftshift, the transformed abscissa is 0: f_s/(N-1): f_s. If we use the fftshift command, the 0 frequency component will move to the coordinate center, this is exactly what the help center in MATLAB means: processing the FFT coordinates. In fact, due to the spectrumPeriodicityThis is reasonable and acceptable.

Please pay special attention to the differences in abscissa. In addition, according to the features of the function, the spectrum should only have a peak value of 15Hz and 40Hz, but the peak value appears at 60Hz and 85hz after the FFT conversion, the corresponding explanations should be obtained from the FFT calculation process.

In fact, if we use 15Hz and 60Hz to test the FFT transformation, that is, y = 0.5 * sin (2 * pI * 15 * t) + 2 * sin (2 * pI * 60 * t); the image is shown as follows, without any changes.

This phenomenon reminds us that the frequency is within f_s, that is, 0 <F <f_s, f, and f_s-F may be the frequency spectrum of the test signal, which brings us ambiguity. We can also see from the third subgraph that the fftshift at this time will bring us wrong guidance, that is, if we try to sample FFT or fftshift to analyze the frequency spectrum of the signal, it is not so reliable. The FFT line of MATLAB does not have a one-to-one ing relationship with the actual frequency of the signal. This is certainly not the expected result. Therefore, when analyzing signals, you need to pay extra attention to this issue.
In fact, this indirectly proves the rationality of the nyquest sampling theorem: the sampling frequency is twice higher than the cutoff frequency. In the above processing, the sampling frequency we use is 100Hz, as a result, when the cutoff frequency exceeds 50Hz, the mixing effect will occur, as shown in special cases: exactly the same. Therefore, this tells us that if we want to correctly display the spectrum, we need to carefully consider the relationship between the sampling frequency and the cutoff frequency. If it is too small, it is possible to have a mixture. If it is too large, the calculation cost is too high.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.