Best way to smooth out filter behaviour when changing cutoff?

DSP, Plug-in and Host development discussion.
MusterMyMan
KVRer
12 posts since 29 May, 2019

Post Mon Jul 15, 2019 11:50 am

Here's my situation: When a filter's cutoff is changed instantaneously, e.g. LPF 100 Hz to LPF 500 Hz, I'd like it to instead transition smoothly to the new cutoff. To get around having to recalculate all the coefficients every sample (or every few samples) I've tried linear interpolation on the individual biquad coefficients but the filter gets unstable quickly, especially with large differences in cutoff frequency, high orders and short interpolation times. Is there any other way that would be computationally more efficient than using the BLT over and over again?

matt42
KVRian
1121 posts since 9 Jan, 2006

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Mon Jul 15, 2019 12:06 pm

Biquads dont modulate well generally. Perhaps try a ZDF/TPT style filter. There's are some papers on the cytomic website that detail implications of common second order filters, including LPF. These are very stable under modulation and you can interpolate the coefficients at audio rate.

If you stick with biquads you can linearly interpolate the coefficients, iirc, but you shouldn't update them at audio rate. Perhaps try every 16, or 32 samples to avoid it blowing up.

I notice you mention high orders. Classical direct forms especially will become more unstable as the order increases, so you should break higher order filters down in to multiple second order stages plus a first order stage in the case of odd order filters.

MusterMyMan
KVRer
12 posts since 29 May, 2019

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Mon Jul 15, 2019 12:44 pm

Thanks, I'll look into these papers!
Mh, yeah. Maybe small linear interpolation would be a good compromise, good idea!
No worries, I already have just biquads and one first-order filter, if needed. Still, the linear interpolation produces more pops at higher orders (i.e. more biquads).

Wild Hades
KVRist
181 posts since 6 Sep, 2007

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Mon Jul 15, 2019 1:26 pm

Instead of interpolating the coefficients, interpolating the parameter that changes usually works pretty well.
For example, if you have a frequency change from 100Hz to 500Hz, smooth out the update by linearly changing the frequency a bit for every sample, like 101 -> 102 -> 103 -> ... -> 500 in like 0.1s period.
In my experience with analog derived filters (using BLT) this works way better than interpolating the coefficients, although the problem is that you loose sample-accurate automation (in case you need it) and the CPU consumption increases during the transition.
Got it to work without artifacts up to 5th order filters (like guitar amp tonestacks, for example) without the need of factorizing into biquads and bilinears.
matt42 wrote:
Mon Jul 15, 2019 12:06 pm
Classical direct forms especially will become more unstable as the order increases, so you should break higher order filters down in to multiple second order stages plus a first order stage in the case of odd order filters.
True, but forget about interpolation/smoothing if you go that route, the moment you hit a change between two distinct poles and two complex conjugate ones (or viceversa) you're going to get a discontinuity no matter how long your smoothing period is.
Handle such cases correctly to minimize the artifacts is far from trivial.

matt42
KVRian
1121 posts since 9 Jan, 2006

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Mon Jul 15, 2019 2:00 pm

Wild Hades wrote:
Mon Jul 15, 2019 1:26 pm
True, but forget about interpolation/smoothing if you go that route, the moment you hit a change between two distinct poles and two complex conjugate ones (or viceversa) you're going to get a discontinuity no matter how long your smoothing period is.
Handle such cases correctly to minimize the artifacts is far from trivial.
I'm guessing you mean two poles on the real axis modulating in to a conjugate pair? What's the reason that would be worse than other forms of modulation? I'm genuinely curious. For something like a butterworth LPF I guess that wouldn't be an issue, but with things like a 4 pole ladder transformed as a pair of biquads you could run in to that (just a couple of LPF cases that came to mind)

MusterMyMan
KVRer
12 posts since 29 May, 2019

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Mon Jul 15, 2019 2:29 pm

Wild Hades wrote:
Mon Jul 15, 2019 1:26 pm
Instead of interpolating the coefficients, interpolating the parameter that changes usually works pretty well.
I was hoping to be able to avoid that route, as it would be more computationally intensive. But I guess I have no other choice. I don't need it to be perfect, just not super audible.

MusterMyMan
KVRer
12 posts since 29 May, 2019

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Mon Jul 15, 2019 4:00 pm

Reporting back: Interpolating the cutoff did indeed work very well. There doesn't seem to be too big of a performance hit either, so I can only recommend! I've found to interpolate over 70ms to be a good compromise between reasonably low latency and few artifacts.

Wild Hades
KVRist
181 posts since 6 Sep, 2007

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Mon Jul 15, 2019 4:04 pm

matt42 wrote:
Mon Jul 15, 2019 2:00 pm
What's the reason that would be worse than other forms of modulation? I'm genuinely curious. For something like a butterworth LPF I guess that wouldn't be an issue, but with things like a 4 pole ladder transformed as a pair of biquads you could run in to that (just a couple of LPF cases that came to mind)
If you modulate a parameter that changes some coefficients of a high order filter without factorization, you'll just need to make sure that the modulation step is small enough, no need to care about the filter history, for example.
When you factorize a high order filter and two real poles become a complex conjugate pair, you'll need to somehow track the poles that are changing in order to understand what factors are involved and how to initialize the memory of the new biquad filter, or else you'll end up with a spike.
If an abrupt parameter change causes multiple poles to modulate from real to cc or from cc to real, things get even worse.

matt42
KVRian
1121 posts since 9 Jan, 2006

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Tue Jul 16, 2019 12:45 am

Thanks for the reply, Wild Hades. If I understand right, you mean in cases where the normalised transfer function can't be factorised into discrete second and first order transfer function sections, say in the case of some 4th order ladders. Then we would run into the problem of keeping track of which real poles would be correctly paired, so that we would have the correct complex conjugate pairings when, say, we increase the resonance?

To clarify my earlier post I'd probably only break down higher order filters when the normalised transfer function can easily be defined as lower order stages, which is typical for classical filter types. For stuff like ladder filters I would go for a zdf design, and actually any filter that would be modulated I would most likely do the same.

mystran
KVRAF
5325 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Thu Jul 18, 2019 9:25 am

matt42 wrote:
Mon Jul 15, 2019 12:06 pm
Biquads dont modulate well generally. Perhaps try a ZDF/TPT style filter. There's are some papers on the cytomic website that detail implications of common second order filters, including LPF. These are very stable under modulation and you can interpolate the coefficients at audio rate.
The usual ZDF-SVF in particular is very nice in terms of interpolation, because you can also pre-calculate the divisions and linearly interpolate the resulting reciprocal terms without causing any significant issues. While it's "wrong" in theory, it works remarkably well in practice and this makes it similar to a direct form biquad in terms of per-sample computational cost even under interpolation.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

mystran
KVRAF
5325 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Thu Jul 18, 2019 9:44 am

matt42 wrote:
Tue Jul 16, 2019 12:45 am
Thanks for the reply, Wild Hades. If I understand right, you mean in cases where the normalised transfer function can't be factorised into discrete second and first order transfer function sections, say in the case of some 4th order ladders. Then we would run into the problem of keeping track of which real poles would be correctly paired, so that we would have the correct complex conjugate pairings when, say, we increase the resonance?
In the LTI sense you can ALWAYS factor a transfer function into biquads (+one-pole for the odd-order case). In the transistor ladder / OTA cascade case the poles can be trivially computed on the s-plane as simple linear function as they spread out from a single position in a cross-shape.

Ignoring that special case though, what you usually would like to do is factor the transfer function into biquads while keeping the resonance as a free parameter. This way you never need to track any pole-pairing as you get it automatically when you compute the actual biquad coefficients. Whether any given biquad then gives you a complex conjugate pair or two real poles is simply a matter of the biquad Q factor, but the poles will always transition smoothly either way.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

matt42
KVRian
1121 posts since 9 Jan, 2006

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Fri Jul 19, 2019 11:29 am

Thanks mystran, you make good points as usual. The only reason I mentioned a ladder type scenario was that I wasn't sure if I was following Wild Hades correctly, so I was asking if that was in the ball park of the type of situation he had in mind. (Obviously even if you take advantage of the simple geometry of the poles and don't bother with the non-linear q to pole distance relationship designing a filter that way is going to a reasonable amount of effort just to get to possibly one of the worse structure for a synth filter).

Not that it's that important, but the filter that came to mind that would have real poles moving around on the real axes before converging and then splitting off as complex conjugates was a diode ladder

juha_p
KVRian
548 posts since 21 Feb, 2006 from FI

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Sat Jul 20, 2019 10:15 pm

Just wondering if s to z calculation method which P. Pupalaikis introduces in his paper "Bilinear Transformation Made Easy" (PDF) could suite better for this type of dynamic filter generation...? Code example.

matt42
KVRian
1121 posts since 9 Jan, 2006

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Sun Jul 21, 2019 2:04 am

Only had a quick look, so could easily have missed something. But isn't it a method to perform the BLT while avoiding the typical algebraic manipulation? It still arrives at a z-domain transfer function that would, presumably, need implementing with a direct form biquad and suffer from the same modulation instability mentioned in the original post. I think the advantage of the method is if you need to handle different transfer functions on the fly (not having to do all the algebraic rearrangement).

From the abstract:
This formula obviates the need for any algebraic manipulation of the analog prototype filter and is ideal for use in embedded systems that must take in any general analog filter specification and dynamically generate digital filter coefficients directly usable in difference equations.

juha_p
KVRian
548 posts since 21 Feb, 2006 from FI

Re: Best way to smooth out filter behaviour when changing cutoff?

Post Sun Jul 21, 2019 12:17 pm

Hmm... (didn't test anything so dunno if this has much to do with the issues in linear interpolation of coefficients mentioned by OP but) an example of biquad LPF (BLT, fs= 44100Hz, Q=1/sqrt(2))

s- domain coefficients and approximation equations (fc = 1-22050 Hz)
Image

z domain coefficients and approximation equations (fc = 1-22050 Hz)
Image

Dunno what polynomial type LibreOffice uses but, in case of z- domain coefficient approximation, it needs degree of around 13 to get R^2 = 1 (one could split the range to get the polynomial degree down).

Return to “DSP and Plug-in Development”