1
votes

I've generated a graph of a FFT, with a number of individual peaks, in Python 2.7.3.

http://imgur.com/O9E0e

I understand that to calculate the area under the whole graph, I can either sum the values or use trapz, but I'm struggling when trying to restrict these calculations to a single region. For example, I'd like to calculate just the area between 105 and 120Hz, or between 145 and 155Hz.

If it helps, the code to generate this graph is:

x=arange(0,15,0.01)

y=exp(-0.3*x)*exp(x*pi*20j)+exp(-0.9*x)*exp(x*pi*25j)+exp(-0.9*x)*exp(x*pi*15j)

fft(y)
plot(fft(y))
xlabel('frequency (Hz)')
show()

I'm sure I'm probably just missing something relatively simple, but as a complete novice of programming I'd appreciate any help you can provide and a brief search of SO didn't provide any answers. Thanks.

2

2 Answers

1
votes

If you're using a simple sum (or trapezoidal) integration:

ft = np.fft.fft(y)
integral = sum(ft[105:121])

or

integral = np.trapz(ft[105:121])

seems like it should work.

>>> import numpy as np
>>> x = x=np.arange(0,15,0.01)
>>> from numpy import exp,pi
>>> y=exp(-0.3*x)*exp(x*pi*20j)+exp(-0.9*x)*exp(x*pi*25j)+exp(-0.9*x)*exp(x*pi*15j)
>>> ft = np.fft.fft(y)
>>> np.trapz(ft[105:121])
(642.14009362811771+142.9776425340925j)
>>> sum(ft[105:121])
(652.29308789751224+152.70583448308713j)
1
votes

An integral of an exponential, $\int_a^{b} \exp(x*q) = (1/q)*(\exp(b*q) - \exp(a*q))$