Complex Nonlinearities Episode 4: Nonlinear Biquad Filters

Biquad Filters

To begin, I’d like to introduce the idea of a “biquad” filter, which is a short way for DSP engineers to refer to a 2nd-order filter. “2nd-order” means that the filter has “memory” that extends back to the two previous timesteps that it has computed. In other words, the current output of the filter depends not just on the current input, but also on the previous two inputs and outputs. DSP engineers like biquad filters a lot, because any filter can be broken down into a “cascade” of biquad filters.

Transposed Direct Form II

There are several way to implement a biquad filter, but one of my favorites is the so-called “Transposed Direct Form-II”. This a rather complicated name for a relatively simple thing, but more information on why this name exists, as well as other filter forms, can be found in Julius Smith’s wonderful Introduction to Digital Filters.

Transposed Direct Form II

Filter Shapes

There are several particular filter “shapes” that are often useful for processing audio, and all of them can be constructed using a TDF-II structure. In this article, I’m going to focus on 6 shapes: Highpass, Lowpass, High Shelf, Low Shelf, Bell, and Notch. Plots of the frequency response for each of these filters can be found below. For instructions on how to implement these filters using a biquad filter, please check out Robert Bristow-Johnson’s Audio EQ Cookbook, another indespensible resource for audio DSP engineers.

Nonlinear Resonance

In order to make any TDF-II filter exhibit nonlinear resonance, we can simply saturate the states. In the following examples, I will demonstrate three saturating nonlinearities: a soft clipper, a hard clipper, and a tanh clipper. The mathematics that describe why this works and ensure that we don’t accidentally make an unstable filter are a litle bit complex, for the more mathematically inclined reader, I recommend a more technical paper I’ve written on the topic. The resulting signal flow diagram will look something like this (the “NL” blocks represent nonlinear elements):

Transposed Direct Form II with Nonlinear Elements

Frequency Responses

To get a sense of what this modified structure does to our filter, it would be nice to look at the frequency response of the filter. Unfortunately, as I mentioned in my introductory article for this series, a nonlinear system does not have a frequency response the same way that a linear system does. However, what we can do is choose some level (often called an “operating point”), and see how our system reacts to various frequencies at that level. Below, we show the “frequency response” for a low shelf filter and a bell filter, each with tanh nonlinearities, at various operating points.

Anti-Aliasing

Now if we can measure the harmonic response of this nonlinear filter, that will be useful for us in avoiding aliasing artifacts. Below, we show the harmonic response of a 100 Hz sine wave, for a nonlinear bell filter with a center frequency at the same frequency, and a gain of 12 dB. We show this response for three types of saturating nonlinearities: hard clipper, soft clipper, and tanh clipper.

Examples

As usual, there is an example implementation of this nonlinear biquad filter available on GitHub as an audio plugin (VST, AU). Feel free to download and try it for yourself! There is also a video demo below:

Finally…

Thanks for taking the time to read about yet another interesting nonlinear signal processing method. As always, I hope you’ve been inspired to try some things for yourself. For instance, what about adding nonlinearities to some other filter forms? What about trying different nonlinear shapes, saturating and otherwise? Once you start asking these sorts of questions, the possibilities are truly beyondless.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store