IIR Filter samplerate and frequency

I’m wondering if the frequency you set with IIRCoefficients depends on the samplerate. Lets say i init a filter with…
makeHighShelf (44100, 15000, 0.1, 12.0);

will it sound the same if i init it with lets say…
makeHighShelf (192000, 15000, 0.1, 12.0);

will i get the same results or would i need to use a higher frequency with a 192000 samplerate? i’m asking because i of this jassert here in IIRCoefficients::makeHighShelf…
jassert (cutOffFrequency > 0.0 && cutOffFrequency <= sampleRate * 0.5);

that would mean i get an assert when i did this…
makeHighShelf (22050, 15000, 0.1, 12.0);

would that mean to get the same results like the 44100 samplerate version i would have to do this…
makeHighShelf (192000, 65306, 0.1, 12.0);

You might have heard of the nyquist theorem which says that the highest frequency a sampled signal can contain is 1/2 samplerate. So it should be logical that you also can’t run a filter at a given samplerate and let it operate above nyquist - this is the reason for the jassert.

And yes, the coefficients will differ if you design two filters with the same frequency responses but for different samplerates.

As you can see in the code the only thing done with the cutoff frequency is multiplying it by tau/sample-rate thus converting it to radians-per-sample:

auto omega = (2 * MathConstants<NumericType>::pi * jmax (cutOffFrequency, static_cast<NumericType> (2.0))) / static_cast<NumericType> (sampleRate);

So, yeah. Personally I would like interfaces which just work in terms of radians per sample.

So do like this?
srFactor = curSampleRate / 44100.0;
Then multiply cutoff freq with this.

I’ve seen filter implementations that start behaving slightly different when just approaching the nyquist frequency. Theoretically they shouldn’t, but math can be tricky.

Why? And what’s special about 44100?

I usually work on samplerate 44100.
So this value is depends on the situation.

If use “srFactor” like this,
makeHighShelf (curSampleRate, 15000 * srFactor, 0.1, 12.0);
It adjusts cutoff freq automatically.

Actually I don’t know this is correct or not.
I just came up with it.

With all respect, but without first learning the basics of filter design (with keywords like biquad, feedforward, feedbackward, IIR, etc.) I’m afraid you will not be able to use the Juce filters in a correct way…

1 Like

Thanks guys for clearing this up.