如何使用Python在Matplotlib中繪製訊號?
要獲取訊號圖,我們可以按照以下步驟操作 −
- 設定圖片大小並在子圖周圍和之間調整填充。
- 獲取隨機種子值。
- 初始化dt用於取樣間隔並找到取樣頻率。
- 建立t的隨機資料點。
- 使用numpy生成噪聲,獲取nse、r、cnse和s。
- 使用subplots()方法建立圖片和一組子圖。
- 設定圖表的標題。
- 繪製t和s資料點。
- 設定x和y標籤。
- 使用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("Signal")
axs.plot(t, s, color='C0')
axs.set_xlabel("Time")
axs.set_ylabel("Amplitude")
plt.show()輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP