我正在尝试将MATLAB脚本转换为python脚本。但是,我从MATLAB频谱图和matplotlib.mlab.specgram()获得了完全不同的输出。我检查了其他问题,但是,这些问题无济于事。您能检查一下我的密码吗?
MATLAB代码
nfft = 2048;
window = hamming(nfft);
noverlap = nfft * 0.75;
X = spectrogram(data, window, noverlap, nfft);
X_abs = abs(X);
MATLAB结果 (X_abs的前3次(列)和6次频率(行))
30.1724220846775 31.0947120708528 34.6189241212563
12.2846967449186 12.9514893948274 13.8107010563694
1.20537039658088 0.614575979921346 0.724643190160887
3.49625399374313 2.48394521607334 1.43848016399582
2.83227523082322 1.76662351483948 2.35189645650400
0.568257664015496 0.743800152833193 1.78240372417488
Python代码
fs = 10000
nfft = 2048
window = numpy.hamming(nfft)
noverlap = int(nfft * 0.75)
X, _, _ = matplotlib.mlab.specgram(data, Fs=fs, window=window, noverlap=noverlap, NFFT=nfft)
X_abs = numpy.abs(X)
Python结果 (X_abs的前3次(列)和6次频率(行))
1.11910601e-04 1.18856779e-04 1.47325530e-04
1.15646041e-02 1.17253708e-02 1.17148462e-02
3.71030621e-05 4.12401562e-05 4.68934648e-05
4.22107583e-03 4.31724420e-03 4.36301850e-03
3.57208608e-07 9.28607182e-08 1.29100910e-07
8.98671692e-08 1.93129250e-07 5.93981935e-07
如您所见,它们输出的值完全不同...我不确定为什么会这样。我可以要求任何建议或意见吗?