Some code related with my talk about IIR filters

Hello again guys !

As I promised, here is the code for the Topology Preserving Transform FIlters that I have shown during my talk :

const float g = tanf(float_Pi * frequency / sampleRate);
const float h = 1.f / (1 + g / Q + g*g);

for (int i = 0; i < numSamples; i++)
    const float in = samples[i];
    const float yH = h * (in - (1.f / Q + g) * s1 - s2);
    const float yB = g*yH + s1;
    s1 = g*yH + yB;

    const float yL = g*yB + s2;
        s2 = g*yB + yL;

        samples[i] = yL;

I’ll do a proper class if you need it when I have a moment. The only important missing thing is the fact that s1 and s2 are the state variables of the structure and that they need to be resetted to zero before any use obviously.

I’d like also to remind you again that I am not the creator of that thing, most of the credits for it and my entire talk goes to Vadim Zavalishin and his book “The Art of V.A. Filter Design” available for free on the internet, and all the interesting talks and read I had in the past with people on the KVR DSP section forum :wink:

Tell me if you have any question by the way !


Hey Ivan - that was a great talk. I’ve been through the paper a couple of times slowly, and your talk was a good refresher. I think it is slowly sinking in. But there’s still some voodoo in there …

Hi @IvanC, thanks so much for sharing this code, the demo at your talk was very interesting.
You mentioned this is a SVF with outputs for highpass, bandpass and lowpass, however my limited DSP knowledge can’t seem to see how you extract each of these elements.

Would you just set samples[i] to either yH, yB or yL depending if you want highpass, bandpass or lowpass and then leave the rest the same?

Any pointers much appreciated!

Hello Dave :wink:

Yes, if you want a lowpass filter you just have to use the variable yL, same for bandpass and yB and for highpass with yH. You won’t need to do anything else in the code, and you would still need to calculate yB and yL if you need only yH to update the state variables properly.


Maybe this will help? Maybe not :wink:

The digital versions are complex to derive, but whoever invented the analog originals was practising pure witchcraft…

Really looking forward to watching this @IvanC.

I’ve been through The Art of V.A. Filter Design a few times and have my head round about two 2/3’s of it.

Really looking forward to seeing a talk on this subject and someone else’s take. Thanks for the quick and cool SVF code Ivan!

(Still planning on working out oversampling so the response doesn’t plummet close to nyquist as is the case with some of the naive-ish TPT filters I’ve put together…implementing decent oversampling still eludes me at the moment… )

Very interesting talk Ivan, thanks for that!

I’m currently using the IIRFilter for basic HP/LP and have ran into the issues you demonstrated in your talk. I get loud bursts when the filter changes too fast. In some other threads have seen that you’ve pushed and proposed some changes for the IIRFilter, will something that handles this behaviour get a commit as well or would you recommend I go for some kind of parameter smoothing to deal with this?


Hello ! If you try to replace your lowpass / highpass filtering code by the one I have just shared, you should be able to remove the bursts when your coefficients are modulated