如何使用 Python 中的 Matplotlib 繪製角度譜?


要繪製角度譜,我們可以採取以下步驟 −

  • 設定影像大小,並調整子圖之間的和周圍的內邊距。
  • 獲取隨機種子值。
  • 初始化取樣頻率的 dt 以及取樣頻率。
  • 建立 t 的隨機資料點。
  • 要生成噪聲,請使用 numpy 獲取 nse、r、cnses。
  • 使用 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 月 17 日

459 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.