如何在 Python 中的 Matplotlib 中绘制相位频谱?


要绘制相位频谱,我们可以采取以下步骤 -

  • 设置图表的大小并将图表间及周围的填充调整好。
  • 获取随机种子值。
  • 初始化采样间隔的**dt**并找出采样频率。
  • 为**t**创建随机数据点。
  • 使用 numpy 生成噪声,**获得 nse、r、cnse**和**s**。
  • 使用**subplots()**方法创建一个图表和一组子图表。
  • 设置图表的标题。
  • 绘制相位频谱。
  • 使用**show()**方法显示图表。

示例

import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

np.random.seed(0)
dt = 0.01 # sampling interval
Fs = 1 / dt # sampling frequency
t = np.arange(0, 10, dt)

# generate noise:
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(4 * np.pi * t) + cnse

fig, axs = plt.subplots()
axs.set_title("Phase Spectrum ")
axs.phase_spectrum(s, Fs=Fs, color='C2')

plt.show()

输出

更新于:2021 年 6 月 16 日

1K+ 浏览次数

开启你的 职业生涯

完成课程即可获得认证

开始
广告
© . All rights reserved.