The FFT visualization tutorials‘s DB Mapping?

Hi there,
In the tutorial: Visualise the frequencies of a signal in real time, why minus the item: Decibels::gainToDecibels ((float) fftSize)) in the drawNextFrameOfSpectrum function ?
Why transform the fftSize=2048 into DBFS?

Best Regards!

void drawNextFrameOfSpectrum()
{
    // first apply a windowing function to our data
    window.multiplyWithWindowingTable (fftData, fftSize);

    // then render our FFT data..
    forwardFFT.performFrequencyOnlyForwardTransform (fftData);

    auto mindB = -100.0f;
    auto maxdB =    0.0f;

    for (int i = 0; i < scopeSize; ++i)
    {
        auto skewedProportionX = 1.0f - std::exp (std::log (1.0f - i / (float) scopeSize) * 0.2f);
        auto fftDataIndex = jlimit (0, fftSize / 2, (int) (skewedProportionX * fftSize / 2));
        auto level = jmap (jlimit (mindB, maxdB, Decibels::gainToDecibels (fftData[fftDataIndex])
                                               - Decibels::gainToDecibels ((float) fftSize)),
                           mindB, maxdB, 0.0f, 1.0f);

        scopeData[i] = level;
    }
}

The values you get back from an FFT are always scaled by the FFT length. So in order to get the true DBFS values, you need to divide them by the length. The code basically does this in a very inefficient way -> in the log domain: log(a/b) = log(a) - log(b)

1 Like