Problem with FFT amplitude plot
3 views (last 30 days)
Show older comments
I have a dataset of nearly 3 hour duration. There are 30 sec interval of data points. I want to find the amplitude spectrum of data after performing FFT. And x axis will be periods in minute. But after applying fft I am not getting desired results.
If you can help me in this regard I will be grateful...and also Thanks in advance
2 Comments
dpb
on 8 Aug 2020
See the example PSD calculation via FFT in the documenation for FFT
doc fft
There's nothing anybody can tell you about any specific problem you're having from the above general description -- no data, no code, no nothing...
Answers (3)
Star Strider
on 14 Aug 2020
To see the frequency peaks, it is necessary first to remove the D-C offset by subtyracting the mean of the signal:
D1 = readmatrix('data.xlsx');
t = D1(:,1);
data = D1(:,2);
figure
plot(t, data)
grid
L = numel(t);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
datam = data - mean(data);
FTdata = fft(datam)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
[pk,ix] = max(abs(FTdata(Iv)));
figure
plot(Fv, abs(FTdata(Iv)))
hold on
plot(Fv(ix), pk, '^r')
hold off
grid
text(Fv(ix), pk, sprintf('\\leftarrow Frequency = %7.3f\n Amplitude = %7.3f', Fv(ix), pk), 'HorizontalAlignment','left')
producing:
Now, the main peak is clearly visible. (Note that there is some variation in the sampling times, so it would be best to use the resample function to make them all equal and therefore impprove the precision of the result.)
.
0 Comments
Antonio Ciociola
on 8 Aug 2020
It's hard to understand the problem without data and code.
The error that you get seems related to the amplitude of the spectrum so it's possible that you have forgotten to normalize the spectrum dividing by the number of samples.
Xs = (1/length(x))*fft(x);
0 Comments
Moon Datta
on 9 Aug 2020
5 Comments
Antonio Ciociola
on 14 Aug 2020
Look at the answer that Star Strider. He suggests to remove the DC offset to see the frequency peaks but it seems that you have another problem.
The image that you've showed seems to suggest that you have a signal without DC component and with some higher frequency components.
Looking at the photo that Star Strider posted you could get the same consideration made before:
"Look at the result that I get. Is it useful? In my opinion this plot it's "telling" that the signal has a quasi zero frequency...and it seems quite correct because looking at the signal it has very slow variation and poor periodicity."
And it's different from the result showed in the photo that you posted above.
So the question is...are you sure that the result in the photo it's obtained with the same data? Maybe you need to observe the signal for a long time to appreciate it's periodicity.
See Also
Categories
Find more on Fourier Analysis and Filtering 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!