What is the relation between the s output and the plot made by the spectrogram function?

I'm making a spectrogram, and wish to extract the mean power (dB) in various frequency ranges (e.g. mean power between 8-14Hz at each time point). From what I understand, the output s is a matrix of complex numbers, the real part of which is magnitude squared. Taking the square root of that, then using the mag2db function to convert to dB results in a plot which looks right, however, the units are way off. The spectrogram yields units ranging from -70 to 10 dB, while my plot ranges from 25 to 50 dB.
I'd like the two plots to be directly comparable, so any insight into how Matlab computes the spectrogram from the values of s would be helpful. Alternatively, if anyone knows a way to extract the values in the spectrogram directly, that would also be good.

4 commentaires

I tend to use the 4 output version of spectrogram and throw away the 's' output. The 4th output being the power spectrum which, if I remember correctly, is what is plotted when you use the no output argument version, albeit with some different scaling possibly.
I don't really have time to check any further now, I am just glancing at the code where I use spectrogram and my call starts as:
[~,freqs,~,p] = spectrogram( ...
This is a helpful start, but p is still not the same as what is plotted in the spectrogram. From the Matlab documentation, p is "power spectral density (PSD) or power spectrum, returned as a matrix". How do I interpret this? And how do I convert PSD to dB?
I just take 10 log10( p ) and plot that but I'm not sure about dB specifically as I don't generally work in dB.
The following
p_db = 10 * log10(p);
does indeed yield a matrix with the same values as the spectogram itself. Thank you very much!

Connectez-vous pour commenter.

Réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by