Area under FFT curve

22 次查看(过去 30 天)
Nasrin Akter
Nasrin Akter 2020-4-3
I need to calculate the area under curve for the fundamental frequency and some harmonics in an FFT curve. I have attached the FFT curve.
For FFT I used below code:
Fs=125;
L=length(A(1250000:2500000));
n=pow2(nextpow2(L));
f=Fs*(0:1/n:1-(1/n));
df=log10(abs(fft(A(1250000:2500000).*hanning(L),n)));
I need to calculate the area under the curve for a certain bandwidth. For example, the fundamental frequency is 1.5 MHz and I need the area between 1.4 MHz and 1.6 MHz. I tried to use cumtrapz function using below code:
Int = cumtrapz(f,df);
Intv = @(a,b) max(Int(f<=b)) - min(Int(f>=a));
SegmentArea1 = Intv(1.5-.1, 1.5+.1)
SegmentArea2 = Intv(3-.1, 3+.1)
But it gives the same value for SegmentArea1 and SegmentArea2. I also tried to use trapz using:
trapz(df(find(abs(f-1.4)<0.0001):find(abs(f-1.6)<0.0001)))
but i got a negative value.
Am I using the correct functions or am I doing something wrong? Is there any other way to do it?

回答(1 个)

Star Strider
Star Strider 2020-4-3
Calculate the areas of only the ‘positive frequencies’ half of the fft output, not the entire output. If the data are all positive (for example, the absolute value of the fft), negative values are usually because the independent variable (frequencies in an fft) are going from the Nyquist frequency to 0, rather than from 0 to the Nyquist frequency.
  10 个评论
Nasrin Akter
Nasrin Akter 2020-4-5
Thank you. I have one more question. Is it possible to do baseline correction on a FFT signal? If yes, how?
Star Strider
Star Strider 2020-4-5
My pleasure.
I doubt that there is any need to do a baseline correction of the fft output. If you want to remove the D-C offset (0 Hz peak) from the original time-domain signal (in order to see the other peaks more clearly), subtract the mean of the signal from the signal before doing the fft.
Depending on what the problem is with the fft output, the detrend function may be the best option.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by