绘制两个信号的相干性

举例说明如何绘制两个信号的相干性。

绘制两个信号的相干性图示

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. # Fixing random state for reproducibility
  4. np.random.seed(19680801)
  5. dt = 0.01
  6. t = np.arange(0, 30, dt)
  7. nse1 = np.random.randn(len(t)) # white noise 1
  8. nse2 = np.random.randn(len(t)) # white noise 2
  9. # Two signals with a coherent part at 10Hz and a random part
  10. s1 = np.sin(2 * np.pi * 10 * t) + nse1
  11. s2 = np.sin(2 * np.pi * 10 * t) + nse2
  12. fig, axs = plt.subplots(2, 1)
  13. axs[0].plot(t, s1, t, s2)
  14. axs[0].set_xlim(0, 2)
  15. axs[0].set_xlabel('time')
  16. axs[0].set_ylabel('s1 and s2')
  17. axs[0].grid(True)
  18. cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
  19. axs[1].set_ylabel('coherence')
  20. fig.tight_layout()
  21. plt.show()

下载这个示例