I use the matplotlib specgram function to create a spectrogram. I tried to turn on the color bar to the right of the spectrogram to give an idea of ββthe db-to-color display.
For some reason, the dBs indicated by the color bar do not make sense.
Perhaps I did not generate the colorbar correctly? Perhaps there is some kind of parameter that I need to pass to the specgram?
The signal that I generate is a 1 kHz sine wave, 2 VDC. current taken at 32 Hz.
I expect the dark red peak on the spectrogram to correspond to 0 dB (which means that + 1V is my reference)
Can anyone understand what is wrong with my approach?
def plot_specgram(data, title='', x_label='', y_label='', fig_size=None): fig = plt.figure() if fig_size != None: fig.set_size_inches(fig_size[0], fig_size[1]) ax = fig.add_subplot(111) ax.set_title(title) ax.set_xlabel(x_label) ax.set_ylabel(y_label) pxx, freq, t, cax = plt.specgram(data, Fs=32000) fig.colorbar(cax).set_label('Intensity [dB]') plot_specgram(a,title='Spectrogram', x_label='time (in seconds)', y_label='frequency', fig_size=(14,8))
This is what I get as a result of the spectrogram:

source share