Fourier transform of a Gaussian is not a Gaussian, but thats wrong! - Python

后端 未结 5 1653
萌比男神i
萌比男神i 2020-12-30 10:46

I am trying to utilize Numpy\'s fft function, however when I give the function a simple gausian function the fft of that gausian function is not a gausian, its close but its

5条回答
  •  情话喂你
    2020-12-30 11:36

    Your result is not even close to a Gaussian, not even one split into two halves.

    To get the result you expect, you will have to position your own Gaussian with the center at index 0, and the result will also be positioned that way. Try the following code:

    from pylab import *
    N = 128
    x = r_[arange(0, 5, 5./N), arange(-5, 0, 5./N)]
    y = exp(-x*x)
    y_fft = fft(y) / sqrt(2 * N)
    plot(r_[y[N:], y[:N]])
    plot(r_[y_fft[N:], y_fft[:N]])
    show()
    

    The plot commands split the arrays in two halfs and swap them to get a nicer picture.

    Plot

提交回复
热议问题