Convert spectrogram output to dBFS?

160 views
Skip to first unread message

mitch moop

unread,
Feb 2, 2015, 5:28:52 PM2/2/15
to music...@googlegroups.com
Hello,

Can anyone help me figure out how to convert musicg Spectrogram output to dBFS?

With 16-bit signed integer PCM audio, and FFT length of 2048, I've tried the following but am not there yet.

I've tried the following for each amplitude in the spectrogram:
  1. Normalized spectrogram, and then: 20 * Math.log10(Math.abs(amplitude))

  2. Absolute spectrogram, and then: 20 * Math.log10( 2 * Math.abs(amplitude) / 2048)

  3. Absolute spectrogram, and then: 20 * Math.log10( Math.abs(amplitude) / 32768)

  4. Absolute spectrogram, and then: 20 * Math.log10(Math.abs(amplitude) / maximumAmplitudeInSpectrogram)

But none of these are doing what is expected.

Method 4 gets very close to what I'm expecting, but it is relative to the data in the file, so if I take an audio sample, and decrease all volumes by 10db, method 4 (being relative) would return nearly identical dBFS data from the original file and the decreased-volume version.


Part of this I'm sure is my not yet grokking the relationship between FFT output, and dBU and dBFS.  I'm also not sure what the musicg  normalized and absolute spectrogram represent.  The normalized spectrogram data is on a scale of -1 to 1, correct?  But in my test case (16-bit signed int PCM wav), what is the maximum value possible in an absolute spectrogram?

mitch moop

unread,
Feb 3, 2015, 1:38:36 PM2/3/15
to music...@googlegroups.com
After more experimentation, I believe I'm getting dBFS with the following variation on (2):
dBFS = (20 * Math.log10( 2 * Math.abs(magnitude) / 2048)) - 100

I think this is giving me what I'm looking for, and it correlates closely to what I'm seeing in other tools. And if I decrease the gain on a file by 20db, and then analyze the decreased file, the dBFS data I get back is 20db less than the original.

However, I noticed that when I view the spectrogram in Audacity (using plot spectrum), the dB values in Audacity seem to range between 4db and 9db higher than what I'm getting from musicg and the above equation.

Is there something I'm doing particularly wrong in the way I'm trying to calculate dBFS from the musicg absolute spectrogram data? (or perhaps I'm mistaken and what I'm calculating, and what Audacity is displaying, are not quite the same thing)


Full disclosure, I did post this follow-up question over at dsp.stackexchange.com, so feel free to answer over there if you'd like.
Reply all
Reply to author
Forward
0 new messages