makePeakFilter: logaritmic gain from 0 to 60 db?


is there a way to make the gainFactor of a Peak Filter (IIR, using makePeakFilter()) logaritmic and going from 0db to 60db? Here’s the actual code I have:

ilterIIR.coefficients = *juce::dsp::IIR::Coefficients<float>::makePeakFilter(getSampleRate(), 1000.0f, 1.0f, gain);

where gain going from value 0 to 60 linearly.
As filter says, it start to “grown” from 1.0 value (i.e. gain = 0.5 is a negative peak).
So also this need to be compensate (i.e. start from 1.0, converting logaritmically to 0-60).

If I put a gain = 40 on the code, I see a peak with actual gain of +31db (i.e. from -60db to -29db), not 40:

Thanks for any tips.

Put it easyly: if I do this

juce::dsp::IIR::Coefficients<float>::makePeakFilter(getSampleRate(), 1000, 1.0f, 60);

I don’t see a peak at 1000 of +60db.

On the code of gainFactor I see it use sqrt, but feeding a 60 * 60 gain result on this:

Which is not a +60db (but +5db more). The same doing 60.0f * 60.0f - 1.0f (compensating the init value).

What’s wrong?

The gain factor in makePeakFilterCoefficients is linear (linear gain of 40 = 32dB). To go from dB use decibelsToGain.

The math is pow(10.0, dBvalue / 20.0).

1 Like

I see. Thanks @holy-city !