In particular, note that the â€śoriginâ€ť for a discrete Fourier transform (DFT) is at the *first* index (with periodic boundaries so that it â€śwraps aroundâ€ť), which is *not* the middle of your input array. If you center the Gaussian at the middle of your input array, for an even length, then by the shift theorem it multiplies the k-th output by (-1)áµŹ, which explains the sign alternation that you observed. (The `fftshift`

function can shift the origin from the center to the beginning of the array and back.)

(If you google â€śfft gaussianâ€ť you will see that this is a common confusion for people using FFT functions in many languages.)

Also, you should technically understand that an FFT computes the DFT, not a continuous Fourier transform. The DFT of a sampled Gaussian is not quite a sampled Gaussian, because of the truncated tails. This is a small effect if the width of the Gaussian is much smaller than your DFT windows, however. (To get an exact relation, you would compute the DFT of an infinite series of periodic Gaussians, one per sampling window, adding up all of the tails.)

In general, if you want to use an FFT you need to understand what it computes and how it relates to the continuous Fourier transform, Fourier series, discrete-time Fourier transform, or whatever else you want to compute. There are lots of books and other materials on this subject, e.g. Brighamâ€™s book or Oppenheim and Schafer.