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:
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:
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?