การพล็อต Magnitude Spectrum (Linear Scale)
ใช้ magnitude_spectrum() แสดง magnitude spectrum แบบ linear scale
ขั้นตอนหลัก
- ตั้งค่าขนาดรูปและ padding
- ตั้งค่า random seed, dt, Fs, t
- สร้างสัญญาณ s (เหมือน phase spectrum)
- สร้าง figure และ subplots
- ตั้งค่า title และพล็อต magnitude_spectrum(s, Fs=Fs, color='C1')
- แสดงผลด้วย 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
Fs = 1 / dt
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(4 * np.pi * t) + cnse
fig, axs = plt.subplots()
axs.set_title("Magnitude Spectrum")
axs.magnitude_spectrum(s, Fs=Fs, color='C1')
plt.show()
ความแตกต่างจาก Longitudinal
ไม่มี scale='dB' แสดงเป็น linear magnitude scale แทน