1

I was given the Gaussian function g(t)=(1/sqrt(pi) * t_H)e^{-(t/t_H)^2}$ with t_H=5 and t_H=15. I plotted the two functions over the interval [-50,50] with dt=10^{-3} using python. Here is my code:

# We first create the [-50, 50] interval with dt = 10^{-3}
List_1 = []

d_t = 10 ** (-3)
for i in range(100001): 
    a = -50 + i * d_t
    List_1.append(a)
interval = np.array(List_1)

# Then we define the Gaussian function
def Gaussian(t, t_H): 
    return (1 / (np.sqrt(np.pi) * t_H)) * np.exp(-(t/t_H) ** 2)

# Here we compute the values of the Gaussian function at each point of [-50, 50]
List_2 = []
for t in interval: 
    List_2.append(Gaussian(t, 5))
tH_5 = np.array(List_2)

List_3 = []
for t in interval: 
    List_3.append(Gaussian(t, 15))
tH_15 = np.array(List_3)

# Graph plotting 
plt.plot(interval, tH_5, label='t_H=5')
plt.plot(interval, tH_15, label='t_H=15')
plt.xlabel('t')
plt.ylabel('g')
plt.title('the graph of the Gaussian functions for t_H=5 and t_H=15')
plt.legend()
plt.show()

Then I was asked to conduct discrete fourier transformation for t_H=5 and t_H=15 and plot both of them and compare them to the graph of G(w)=e^{(-w^2 * t_H^2) / 4}$. I am stuck here. Is there any help?

I want some sample codes.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
LianNuo
  • 17
  • 2
  • You should try `scipy.fft`. See [https://docs.scipy.org/doc/scipy/tutorial/fft.html](https://docs.scipy.org/doc/scipy/tutorial/fft.html). – Jason Yu Mar 01 '23 at 21:12
  • NumPy has an FFT module, there's lots of example code out there for how to use it. You'll run into an issue with your current setting. The FFT requires the origin (t=0) to be on the leftmost sample, the left half of the Gaussian should be on the right (circularly shift the array, see `np.fft.ifftshift`). – Cris Luengo Mar 01 '23 at 21:49
  • 1
    I would suggest you don't use `append` so much, you don't need lists at all here. Use `np.linspace` or `np.arange` to create `interval`, then `Gaussian(interval, 5)` should give you the whole function in one go. – Cris Luengo Mar 01 '23 at 21:50
  • Does this answer your question? [Plotting a fast Fourier transform in Python](https://stackoverflow.com/questions/25735153/plotting-a-fast-fourier-transform-in-python) – tevemadar Mar 01 '23 at 22:05

0 Answers0