仅为自己的学习记录,本人比较懒,不写注释了。欢迎指出问题和提问!
import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft,ifft
from mpl_toolkits.mplot3d import Axes3D
def center(data,l):
for i in range(l):
for j in range(l):
data[i][j] = pow(-1,i+j)*data[i][j]
return data
def function(x):
if x==0:
return 1
#elif x<4 and x>3:
# return 1
else:
return 0
if __name__ == '__main__':
xs = np.linspace(-5,5,100)
y = []
for x in xs:
y.append(function(x))
yy = fft(y)
yyreal = np.real(yy)
yyimag = np.imag(yy)
xx = np.linspace(0,100,100)
fig = plt.figure()
plt.subplot(334)
yyreal = np.hstack((yyreal,yyreal))
plt.plot(yyreal)
plt.subplot(335)
yyimag = np.hstack((yyimag,yyimag))
plt.plot(yyimag)
plt.subplot(331)
#y = np.hstack((y,y))
plt.plot(y)
plt.subplot(336)
ax = fig.gca()
ax.plot(yyreal,yyimag)
plt.subplot(337)
ll = np.power(yyreal,2)+np.power(yyimag,2)
plt.plot(ll)
#plt.scatter(yyreal,yyimag)
#plt.subplot(335)
#ax1 = Axes3D(fig)
#ax1.plot3D(yyreal,yyimag,xx)
plt.show()