创建图表
现在我们将为不同的频谱表示创建图表。我们将使用 Matplotlib 的 subplots
函数创建一个 3x2 的图表网格。我们将在第一个图表中绘制时间信号,并在其余图表中绘制不同类型的频谱。
fig, axs = plt.subplots(nrows=3, ncols=2, figsize=(7, 7))
## 绘制时间信号:
axs[0, 0].set_title("信号")
axs[0, 0].plot(t, s, color='C0')
axs[0, 0].set_xlabel("时间")
axs[0, 0].set_ylabel("幅度")
## 绘制不同类型的频谱:
axs[1, 0].set_title("幅度频谱")
axs[1, 0].magnitude_spectrum(s, Fs=Fs, color='C1')
axs[1, 1].set_title("对数幅度频谱")
axs[1, 1].magnitude_spectrum(s, Fs=Fs, scale='dB', color='C1')
axs[2, 0].set_title("相位频谱 ")
axs[2, 0].phase_spectrum(s, Fs=Fs, color='C2')
axs[2, 1].set_title("角度频谱")
axs[2, 1].angle_spectrum(s, Fs=Fs, color='C2')
axs[0, 1].remove() ## 不显示空的坐标轴
fig.tight_layout()
plt.show()