You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 7, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 7, 2024. It is now read-only.
plot_spectrogram() doesn't show dB re. 2e-5 Pa #211
I believe the plot_spectrogram() function doesn't output dB relative to the reference acoustic pressure (2e-5 Pa). This can be misleading as the colorbar label is "SPL in dB".
@duracell013 can you provide steps (or more preferably code) as to how you are creating your plot? It looks like the plot_spectrogram() method within _signal.pyx doesn't modify the data array at all, in other words, the input data to this method should already represent the SPL in dB, if that is what you are seeking to plot.
@FRidh Can you elaborate as to where the "data" variable from line 679 of _signal.pyx is generated? np.squeeze(self) is not very descriptive, and without understanding the whole Signal class or how the input attribute "numpy.ndarry" on line 16 is provided, I don't think I'd be able to help troubleshoot this very far. In short, how can we modify the "data" ndarray or where is it being modified prior to being sent to the Signal class?
The Signal class is a subclass of the numpy array and thus self is also an array. Squeezing is done because plot_spectrogram can handle only one-channel signals.
I believe the plot_spectrogram() function doesn't output dB relative to the reference acoustic pressure (2e-5 Pa). This can be misleading as the colorbar label is "SPL in dB".
Correct, the values are re. 1, so there is a shift in decibel.
In my opinion the way forward is that the spectrogram method gets a reference kwarg (see how it is done with the other methods) which defaults to 1 (so we don't break anything, and remain neutral as to what type of signal we're talking about). The plot_spectrogram method ideally reuses the spectrogram method but it should be investigated how this impacts performance.
@FRidh I dont see the conversion to dB in the plot_spectrogram function. I understand that the input data of specgram is in Pa, so I would expect the output to be in Pa. Am I missing something here?
@duracell013 , maybe @FRidh has already answered your question, in which case no need to further debug, but your code doesn't seem to show any plot when run on my machine. It flashes a plot window and immediately closes. I tried tinkering a bit (adding plt.show()), but nothing showing yet. One thing I did notice was that your scipy spectrogram is in 'psd' mode, while this library is using 'magnitude'. In addition to the reference pressure being different, this may also add to any differences you are seeing.
@FRidh , yes I'm sorry, I definitely mistook the ndarray inheritance as an input parameter. Thanks for pointing that out kindly :) . I'm not a native python programmer (or O.O. programmer for that matter) so these things trick me once and a while.
I think I understand your method for moving this forward. I'll send a PR to see if it agrees with what you were thinking.
Activity
topherbuckley commentedon Feb 28, 2018
@duracell013 can you provide steps (or more preferably code) as to how you are creating your plot? It looks like the plot_spectrogram() method within _signal.pyx doesn't modify the data array at all, in other words, the input data to this method should already represent the SPL in dB, if that is what you are seeking to plot.
@FRidh Can you elaborate as to where the "data" variable from line 679 of _signal.pyx is generated? np.squeeze(self) is not very descriptive, and without understanding the whole Signal class or how the input attribute "numpy.ndarry" on line 16 is provided, I don't think I'd be able to help troubleshoot this very far. In short, how can we modify the "data" ndarray or where is it being modified prior to being sent to the Signal class?
duracell013 commentedon Feb 28, 2018
@topherbuckley Here is a sample code which plots the spectrogram with the acoustics package and with scipy.signal.spectrogram().
FRidh commentedon Feb 28, 2018
The Signal class is a subclass of the numpy array and thus self is also an array. Squeezing is done because plot_spectrogram can handle only one-channel signals.
FRidh commentedon Feb 28, 2018
Correct, the values are re. 1, so there is a shift in decibel.
In my opinion the way forward is that the
spectrogrammethod gets areferencekwarg (see how it is done with the other methods) which defaults to 1 (so we don't break anything, and remain neutral as to what type of signal we're talking about). Theplot_spectrogrammethod ideally reuses thespectrogrammethod but it should be investigated how this impacts performance.duracell013 commentedon Feb 28, 2018
@FRidh I dont see the conversion to dB in the
plot_spectrogramfunction. I understand that the input data ofspecgramis in Pa, so I would expect the output to be in Pa. Am I missing something here?FRidh commentedon Feb 28, 2018
The
specgramfunction in matplotlib does the conversion to decibel.duracell013 commentedon Feb 28, 2018
I see, thanks!
topherbuckley commentedon Mar 1, 2018
@duracell013 , maybe @FRidh has already answered your question, in which case no need to further debug, but your code doesn't seem to show any plot when run on my machine. It flashes a plot window and immediately closes. I tried tinkering a bit (adding plt.show()), but nothing showing yet. One thing I did notice was that your scipy spectrogram is in 'psd' mode, while this library is using 'magnitude'. In addition to the reference pressure being different, this may also add to any differences you are seeing.
@FRidh , yes I'm sorry, I definitely mistook the ndarray inheritance as an input parameter. Thanks for pointing that out kindly :) . I'm not a native python programmer (or O.O. programmer for that matter) so these things trick me once and a while.
I think I understand your method for moving this forward. I'll send a PR to see if it agrees with what you were thinking.