Plot the frequency spectrum

数学形式

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。你的数据采样间隔 ,采样 次,采样周期

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

N = len(x)  # Number of samples
T = 1.0 / 200.0 # Sampling interval (1/200 Hz)
yf = np.fft.fft(x) # Compute the FFT 频率分量
xf = np.fft.fftfreq(N, T)[:N // 2] # 获取实际频率作为横轴

# Plot the frequency spectrum
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