在Matplotlib中绘制功率谱密度
要在Matplotlib中绘制功率谱密度,可以按照以下步骤进行−
- 设置图形大小并调整子图之间和周围的填充。
- 初始化一个变量 dt 。
- 使用numpy创建 t,nse,r,cnse,s,r 数据点。
- 创建图形和一组子图。
- 使用 plot() 方法绘制 t 和 s 数据。
- 绘制功率谱密度。
- 使用 show() 方法显示图形。
示例
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
dt = 0.01
t = np.arange(0, 10, dt)
nse = np.random.randn(len(t))
r = np.exp(-t / 0.05)
cnse = np.convolve(nse, r) * dt
cnse = cnse[:len(t)]
s = 0.1 * np.sin(2 * np.pi * t) + cnse
fig, (ax0, ax1) = plt.subplots(2, 1)
ax0.plot(t, s)
ax1.psd(s, 512, 1 / dt)
plt.show()