Python Spectrograms (scipy.signal.spectrogram function)

26 Views Asked by At

Trying to move my spectrogram code from Matlab to Python, but I am getting incorrect values and I am not sure why.

In Matlab, I have:

sound = audioread(x); 
[S, F, T] = spectrogram(sound(:,1),1000,500,1000,44100); %get channel 1
S_dB = mag2db(abs(S));

And all of the dB values in Matlab are <0, which makes sense as my recording device used 0dB as the relative maximum.

In Python, I have:

f, t, Sxx = signal.spectrogram(data, fs=44100, window=('hamming'), nperseg=1000, noverlap=500, nfft=1000, detrend = 'constant', return_onesided=True, scaling='density', axis=-1, mode='psd')
dB = control.mag2db(np.abs(Sxx)) #get magnitude of signal and convert to dB

The Python Sxx matrix contains values all above 0 dB, so I am unsure what went wrong. I am just trying to get the Sxx matrix in Python to be equal to the S matrix created in Matlab. The time and frequency arrays are the same, and from what I read Matlab uses a hamming window by default and returns the PSD of each segment by default. The noverlap and NFFT values are the same, so I am not sure what other difference is causing this. Any advice helps, thanks!

0

There are 0 best solutions below