I am trying to translate a MATLAB script into a python script. However, I got completely different outputs from the MATLAB spectrogram and the matplotlib.mlab.specgram(). I checked other questions, however, they didn't help my problem. Could you please check my code?
MATLAB code
nfft = 2048;
window = hamming(nfft);
noverlap = nfft * 0.75;
X = spectrogram(data, window, noverlap, nfft);
X_abs = abs(X);
MATLAB result (First 3 time (columns) and 6 frequency (rows) of X_abs)
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 code
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 result (First 3 time (columns) and 6 frequency (rows) of X_abs)
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
As you can see, they output completely different values...I am not sure why they do. Could I ask for any advice or comment?