Something is wrong in the Fourier transform...

6 次查看(过去 30 天)
Hello! I have data, which are time-series of the magnetic field. It consists of 365 values per year for 8 years. I need to calculate a Fourier transform of the data, in order to show that there is a yearly cycle in the data. My code is this (Given the 'component' array):
n = length(component);
Ts = 1; % Sampling Interval (day)
Fs = 1/Ts; % Sampling Frequency (samples/day)
Fn = Fs/2; % Nyquist Frequency
nfft = 2^nextpow2(n);
Hn = detrend(component); % Remove long-period trend in order to eliminate 0 frequency
ft = fft(Hn,nfft)/n;
Fv = linspace(0, 1, fix(n/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
Both the field and the Fourier spectrum are shown in the picture. I made it in such a fashion that in subplot with Fourier we have cycles per day on X-axis. So, if we divide 1/x, we should get period. It should be 365 days. The field is obviously dominated by the yearly cycle, but what I get for the period is 265 days. The spectrum also says that there is minimum in frequency for 0.0025, which is exactly a yearly signal. So, it is absolutely wrong and the opposite of what is evidently right. Where is the mistake?

回答(2 个)

Star Strider
Star Strider 2018-1-11
When you zero-padded ‘Hn’, you changed the frequency resolution of the Fourier transform.
See if changing ‘Fv’ to:
Fv = linspace(0, 1, fix(nfft/2)+1)*Fn; % Frequency Vector
produces the correct frequency vector.

David Goodmanson
David Goodmanson 2018-1-11
编辑:David Goodmanson 2018-1-11
Hi Artem,
Although Star Strider's fix should work all right, if you have exactly 8 complete years of data I think you will get more accurate results if you forget about nextpow and just do the fft on the original 2920 points (or maybe 2922 for leap years). That's because the zerofilling necessary to go to 2^12 = 4096 points messes up the periodicity in the data. As a result, a perfect one year cycle must be expressed by one or two imperfect frequencies in the new frequency grid (close to one year but not quite), plus a bunch of smaller but extraneous frequency components.
I don't know how 2^n got to be so entrenched. For 2920 samples the fft is lightning fast anyway, and for much bigger ffts it's not so clear that going to 2^n points is actually any faster. It gets too slow to do an fft on a huge prime number of points, but aside from that I think nexpow has very little to offer.
  1 个评论
Star Strider
Star Strider 2018-1-11
The ‘2^n’ got entrenched because the original Cooley-Tukey algorithm required it. See for example 1.4 Fast Fourier Transform (FFT) Algorithm - Purdue University (link).
We were required to understand and if necessary diagram the algorithm back in the Precambrian.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by