The coordinates of visualisation of the frequencies of a signal?

Hi everyone,
In tutorial:" Visualise the frequencies of a signal in real time", it visualises the frequencies of a signal in real time. However, it does not have the coordinates of frequency (x-axis) and amplitude (y-axis) domains. How could draw their coordinates?

Best regard!

Anyone could help me?

There are plenty threads on the forum, the magnifier icon lets you search for FFT to find e.g. this thread:

TL;DR: the amplitude is linear from 0 to fft.getSize(), so you might want to normalise by:

y = jmap (bin [i], 0.0f, float (fft.getSize()), float (bounds.getBottom()), float (bounds.getY()));

Now the frequency is linear as well (which is annoying, since you get plenty information about higher frequencies, but not much for lower ones).

These are the two mapping functions I use:

inline float indexToX (float index, float minFreq) const
{
    const auto freq = (sampleRate * index) / fft.getSize();
    return (freq > 0.01f) ? std::log (freq / minFreq) / std::log (2.0f) : 0.0f;
}

inline float binToY (float bin, const Rectangle<float> bounds) const
{
    const float infinity = -80.0f;
    return jmap (Decibels::gainToDecibels (bin, infinity),
                 infinity, 0.0f, bounds.getBottom(), bounds.getY());
}

Hope that helps

1 Like

Thank you!!!

btw log(x) / log(2) = log2(x) :nerd_face:

1 Like

Thanks, I missed that this existed!