title: Fourier transform of a Gaussian function in Python
body: <p>I want to calculate the Fourier transform of some Gaussian function. Consider the simple Gaussian g(t) = e^{-t^2}. The Fourier transform of g(t) has a <a href="http://mathworld.wolfram.com/FourierTransformGaussian.html" rel="nofollow noreferrer">simple analytical expression </a>, such that the 0th frequency is simply root pi.</p>
  
  <p>If I try to do the same thing in Python:</p>
  
  <pre><code>N = 1000
  t = np.linspace(-1,1,N)
  g = np.exp(-t**2)
  
  h = np.fft.fft(g) #This is the Fourier transform of expression g
  </code></pre>
  
  <p>Simple enough. Now <a href="https://docs.scipy.org/doc/numpy/reference/routines.fft.html#background-information" rel="nofollow noreferrer">as per the docs</a> <code>h[0]</code> should contain the zero frequency term, which we know from the analytical expression is root pi. But instead it gives <code>746.444</code>?!</p>
  
  <p>Why the discrepancy between the analytical solution and the computational one?</p>