0
$\begingroup$

I'm working on creating a simple program to render spectrograms like this one. In this plot, the X-axis is time, the Y-axis is frequency, and the color represents the magnitude of the DFT at that frequency and time.

I have most of this working, but I'm not exactly sure how to interpret the magnitude value. I'm computing it as follows:

real * real + imaginary * imaginary

(Note that I'm not square rooting it, since Wikipedia indicates that the spectrogram should be related to the square of the magnitude.)

I've seen certain spectrograms which work with magnitude on the dBFS scale. What's the process to translate these magnitudes to this scale? Or, alternatively, is there some easier way to go about this?

$\endgroup$
1
$\begingroup$

One common practice is to take the log of the squared magnitude of the DFT frames, as in log(re*re+im*im), scale that, and use the scaled log as an integer index into an RGB color lookup table ("hotter" colors for larger magnitudes). The scale is determined so that the range in your data fits within the color index table.

A log scale is used, since it's a closer match to human perception of loudness than a linear scale.

A square root is un-needed, as that's the same as adjusting the scale after the log by 0.5.

| improve this answer | |
$\endgroup$
  • $\begingroup$ That's more or less the idea I had at first, but it's not clear to me what is the possible range of log(re*re + im*im)? I need to know that range in order to scale the numbers to a different range. $\endgroup$ – CmdrMoozy Aug 30 '14 at 21:22
  • $\begingroup$ The scale depends on the gain or max volume of the samples of audio input. Can be either computed or just measured from actual data. Or left for user adjustment. $\endgroup$ – hotpaw2 Aug 30 '14 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.