FFT normalization with numpy
<p>Just started working with numpy package and started it with the simple task to compute the FFT of the input signal. Here's the code:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt

#Some constants
L = 128
p = 2
X = 20
x = np.arange(-X/2,X/2,X/L)
fft_x = np.linspace(0,128,128, True)

fwhl = 1

fwhl_y = (2/fwhl) \
*(np.log([2])/np.pi)**0.5*np.e**(-(4*np.log([2]) \
*x**2)/fwhl**2)

fft_fwhl = np.fft.fft(fwhl_y, norm='ortho')

ampl_fft_fwhl = np.abs(fft_fwhl)

plt.bar(fft_x, ampl_fft_fwhl, width=.7, color='b')

plt.show()
</code></pre>

<p>Since I work with an exponential function with some constant divided by pi before it, I expect to get the exponential function in Fourier space, where the constant part of the FFT is always equal to 1 (zero frequency). 
But the value of that component I get using numpy is larger (it's about 1,13). Here I have an amplitude spectrum which is normalized by 1/(number_of_counts)**0.5 (that's what I read in numpy documentation). I can't understand what's wrong... Can anybody help me?</p>

<p>Thanks!</p>

<p>[EDITED] It seems like the problem is solved, all you need to get the same result of Fourier integral and of FFT is to multiply FFT by the step (in my case it's X/L). And as for normalization as option of numpy.fft.fft(..., norm='ortho'), it's used only to save the scale of the transform, otherwise you'll need to divide the result of the inverse FFT by the number of samples. Thanks everyone for their help!</p>

<p>Here's a possible solution to your problem:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt
from scipy import fft
from numpy import log, pi, e

# Signal setup
Fs = 150
Ts = 1.0 / Fs
t = np.arange(0, 1, Ts)
ff = 50
fwhl = 1
y = (2 / fwhl) * (log([2]) / pi)**0.5 * e**(-(4 * log([2]) * t**2) / fwhl**2)

# Plot original signal
plt.subplot(2, 1, 1)
plt.plot(t, y, 'k-')
plt.xlabel('time')
plt.ylabel('amplitude')

# Normalized FFT
plt.subplot(2, 1, 2)
n = len(y)
k = np.arange(n)
T = n / Fs
frq = k / T
freq = frq[range(n / 2)]

Y = np.fft.fft(y) / n
Y = Y[range(n / 2)]

plt.plot(freq, abs(Y), 'r-')
plt.xlabel('freq (Hz)')
plt.ylabel('|Y(freq)|')

plt.show()
</code></pre>

<p>With fwhl=1:</p>

<p><a href="http://i.stack.imgur.com/JlzuG.png" rel="nofollow"><img src="http://i.stack.imgur.com/JlzuG.png" alt="enter image description here"></a></p>

<p>With fwhl=0.1:</p>

<p><a href="http://i.stack.imgur.com/c9H3t.png" rel="nofollow"><img src="http://i.stack.imgur.com/c9H3t.png" alt="enter image description here"></a></p>

<p>You can see in the above graphs how the exponential &amp; FFT plots varies when fwhl is close to 0</p>

python numpy fft