import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from PIL import Image, ImageSequence
fig = plt.figure() #建立一个画板
ax = fig.add_subplot(1,1,1)
x = np.linspace(0,1,500)
xdata = np.linspace(0,1,21)
ydata = np.cos(80*np.pi*xdata)
sample, = ax.plot([],[],'o')
line1, = ax.plot(x,np.cos(80*np.pi*x),'r--',lw=0.5)
ax.grid()
ax.set_xlim(0, 1)
def run(data):
xdata = np.linspace(0,1,data)
ydata = np.cos(80*np.pi*xdata)
if data<=81:
sample.set_data(xdata,ydata)
sample.set_color('r')
else:
sample.set_data(xdata,ydata)
sample.set_color('k')
return sample,
ani = animation.FuncAnimation(fig,run,frames=np.arange(41,162,2),blit=False,interval=600,repeat=True)
plt.show()
用Python编写程序,证明采样定理(香农采样定律、奈奎斯特采样定律)
请用动画描述这一定理。分为两种情况f s≥2f max和f s<2f max。对上边代码进行完善,使其更符合要求,效果更清晰