import numpy as np
import matplotlib.pyplot as plt
np.random.seed(19680801)
dt = 0.01
t = np.arange(0,30,dt)
nse1 = np.random.randn(len(t))
nse2 = np.random.randn(len(t))
s1 = np.sin(2*np.pi*10*t)+nse1
s2 = np.sin(2*np.pi*10*t)+nse2
fig,axs = plt.subplots(2,1)
axs[0].plot(t,s1,t,s2)
axs[0].set_xlim(0,2)
axs[0].set_xlabel('time')
axs[0].set_ylabel("s1 and s2")
axs[0].grid(True)
#plt.cohere(x,y,NFFT=256,Fs)绘制X-Y的相关性函数
cxy,f=axs[1].cohere(s1,s2,256,1./dt)
axs[1].set_ylabel('coherence')
fig.tight_layout()
plt.show()
matplotlib学习——案例四:绘制两个信号的相干性(Plotting the coherence of two signals)
最新推荐文章于 2024-05-16 16:02:35 发布