How to compute Fourier transform of a signal?
2 views (last 30 days)
Show older comments
Artem Smirnov
on 9 Nov 2017
Commented: Star Strider
on 9 Nov 2017
Hello! I have three arrays of data (see the picture). There is 1 measurement every day for 11 years. I know that for fft I need to define sampling frequency, then the time step, signal duration and then count the fft. That is what everyone says about fft on the example of harmonic functions. But in case I have 11*365 measurements, how to find the Fourier transform of this? I attach the picture with my code and the picture with the abs(ft). Why do I get things like that when the signal surely has quasi-harmonic component? Could you please help me to correct this?
0 Comments
Accepted Answer
Star Strider
on 9 Nov 2017
The problem is that the constant offset value of your signal is very high compared to the amplitude of the oscillations. I would remove the constant offset (the mean of your data) before calculating the Fourier transform. That will show the oscillations much more clearly.
Example —
n = length(H);
Ts = 1; % Sampling Interval (day)
Fs = 1/Fs; % Sampling Frequency (samples/day)
Fn = Fs/2; % Nyquist Frequency
nfft = 2^nextpow2(n);
Hn = H-mean(H); % Remove Constant Offset
ft = fft(Hn,nfft)/n;
Fv = linspace(0, 1, fix(n/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
figure(1)
plot(Fv, abs(ft(Iv))*2)
grid
I also provide the frequency vector for your data, and plotted it with respect to that.
NOTE — I do not have your data, so this is UNTESTED CODE. It should work.
2 Comments
Star Strider
on 9 Nov 2017
The frequency units will be in cycles/day. If you want them in Hz, divide ‘Fv’ by (24*60*60) (the number of seconds in a day). The rest of the code does not change, although the x-axis units could become difficult to read and interpret.
The amplitude units will be the same as the original amplitude units.
More Answers (0)
See Also
Categories
Find more on Array and Matrix Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!