Graphing Fourier Transformation in python

时间:2018-03-06 13:01:49

标签: python fft gaussian

I am trying to graph the Fourier transformation a square function, triangle function, Gaussian function e^B[-(t-t')^(2)]/2sigma^(2). I am getting an error for the i range in (N)

For a square function

import numpy as np
import matplotlib.pyplot as plt
import scipy.fftpack

# Number of samplepoints
N = 1024
f=2.56
# sample spacing
T = 1.0 / f
y = []
for i in range (N):
    for i % N/(3.125/2) ==0:
        if count %2 ==0:
            y=np.append(y,0)
        else:
            y=np.append(y,1)
        count +=1 



yf = scipy.fftpack.fft(y)
xf = np.linspace(-1.0/(2.0*T), 1.0/(2.0*T), N/2)

fig, ax = plt.subplots()
ax.plot(xf, 2.0/N * np.abs(yf[:N//2]))
plt.show()

0 个答案:

没有答案