how to

Plot the frequency spectrum

Oct 8, 2024
notesjulyfun数学基础
1 Minutes
169 Words

数学形式

𝐹(𝜔)=+𝑓(𝑡)𝑒𝑖𝑡𝑥d𝑡

𝑓(𝑡)=1[𝐹(𝜔)]=12𝜋+𝐹(𝑤)𝑒𝑖𝑤𝑡d𝜔

ref: https://the-art-of-programming-by-july.readthedocs.io/en/latest/ebook/zh/%E5%82%85%E9%87%8C%E5%8F%B6%E5%8F%98%E6%8D%A2%E7%AE%97%E6%B3%95%E3%80%81%E4%B8%8A/

FFT 求频谱相关

FFT 就是快速 DFT。你的数据采样间隔 𝑇𝑠,采样 𝑁 次,采样周期 𝑇0=𝑁𝑇𝑠

做 FFT 并绘制,你将得到最大频率 12𝑇𝑠,基准频率(分度值)为 1𝑁𝑇𝑠 的频谱:

1
N = len(x) # Number of samples
2
T = 1.0 / 200.0 # Sampling interval (1/200 Hz)
3
yf = np.fft.fft(x) # Compute the FFT 频率分量
4
xf = np.fft.fftfreq(N, T)[:N // 2] # 获取实际频率作为横轴
5
6
# Plot the frequency spectrum
7
plt.plot(xf, 2.0 / N * np.abs(yf[:N // 2])) # Normalize and plot

ref: https://zhuanlan.zhihu.com/p/620462217 含有 FFT 算法证明

verified using sin wave (generate + fft) on 24.8.21

Article title:Plot the frequency spectrum
Article author:Julyfun
Release time:Oct 8, 2024
Copyright 2025
Sitemap