Page 1 of 1

Recursive filters lockup and remedy

PostPosted: Wed Sep 20, 2017 2:54 am
by martinvicanek
Hi gang,

We all use recursive filters (biquads and such) because they are so efficient. However, one disadvantage is that if you feed such a device with invalid data (such as the result of a division by zero), it will lock up because NaNs (Not a Number) will forever feed back. In that case, the only remedy is to interrupt the audio stream.

Of course it is best to avoid NaNs in the first place, but you are not always in control. One possible workaround is to block incoming NaNs from polluting the subsequent signal path. In the schematic below, the NaN Blocker replaces NaNs by zeros, while passing valid stream data unchanged.

If you have a complex schematic with many recursive components, it might be difficult to place potentially many NaN blockers at the right spots. Then you might analyze the audio stream at the end and clear audio on NaN detection there. The schematic below has a module which does exactly this.

Let me repeat: avoid NaNs in the first place if possible. A division by zero may be due to lack of a proper initialization (happened to me before).

Have fun!
NaN Remedy Hack.fsm
(28.32 KiB) Downloaded 922 times

Edit; Upgraded version to take care of division by zero.
NaN Inf Remedy Hack.fsm
(28.75 KiB) Downloaded 908 times

Re: Recursive filters lockup and remedy

PostPosted: Wed Sep 20, 2017 8:25 am
by Spogg
I've had that happen!

So much so I've had to choose alternative filters in some cases, so this could be very useful for me.

I've also had instances of delays causing a lockup sometimes. I found experimentally that using one of your DC blockers (a HPF set to 20Hz) can sometimes stop this happening. Could this behaviour in a delay also be a NaN issue?

Thanks for sharing this Martin. You are a real treasure to have around mate.

Spogg

Re: Recursive filters lockup and remedy

PostPosted: Wed Sep 20, 2017 8:40 am
by martinvicanek
Yes, delays are also prone to lockups if they use feedback as in an echo effect. Other candidates are:
-fractional delays with an allpass interpolator
- comb fiters
- recursive oscillators (includes harmonic oscs and everything based on a naive saw!)
- ring buffers
Simply all recursive structures.

Hm, it is surprising that a highpass filter should help, as the HPF is itself a recursive beast and thus adds to the problem. :o

Re: Recursive filters lockup and remedy

PostPosted: Wed Sep 20, 2017 11:55 am
by Spogg
martinvicanek wrote:
Hm, it is surprising that a highpass filter should help, as the HPF is itself a recursive beast and thus adds to the problem. :o


I think maybe the delays were responding badly to an overall dc offset in the audio, but I don't know for sure. Next time I come across the issue I'll try your NaN blocker first and report back...

Cheers

Spogg