频谱泄漏
import math from scipy.fftpack import fft import scipy.signal as signal import matplotlib.pyplot as plt if __name__ == '__main__': sample_number = 1024 fs = 1000 x = [math.sin(2*math.pi*100*i/fs) for i in range(0, sample_number)] # x = x * signal.hanning(1024,sym=0) y = fft(x) result = abs(y)*2/sample_number print(max(result)) plt.plot(result) plt.show()
代码结果为0.7-0.8左右,并不是期望的1,将sample_number增大为2048,4098,8192...并不能减少其发生的频谱泄漏
这是因为频谱的分辨率为 fs/sample_number= 1000/1024 = 0.9765625Hz,而100Hz并不是0.9765625Hz的整数倍,所以发生泄漏。解决这个问题的办法之一是改变sample_number或者fs的大小,保证m*fs/sample_number = 100,其中m = 0,1,2,3.....