• # How to Construct a Lowpass Filter

General and Gameplay Programming

[size="5"] How do you construct a cool low pass resonant filter?

Let's assume we want to create a filter for analog synth. The filter rolloff is 24 db/oct, which corresponds to 4th order filter. Filter of first order is equivalent to RC circuit and has max rolloff of 6 db/oct.

We will use classical Butterworth IIR filter design, as it exactly corresponds to our requirements.

A common practice is to chain several 2nd order sections, or biquads, as they commonly called, in order to achieve a higher order filter. Each 2nd order section is a 2nd order filter, which has 12 db/oct rolloff. So, we need 2 of those sections in series.

To compute those sections, we use standard Butterworth polynomials, or so called s-domain representation and convert it into z-domain, or digital domain. The reason we need to do this is because the filter theory exists for analog filters for a long time and there exist no theory of working in digital domain directly. So the common practice is to take standard analog filter design and use so called bilinear transform to convert the butterworth equation coefficients into z-domain.

Once we compute the z-domain coefficients, we can use them in a very simple transfer function, such as iir_filter() in our C source code, in order to perform the filtering function. The filter itself is the dimpliest thing in the world. The most complicated thing is computing the coefficients for z-domain.

Ok, let's look at butterworth polynomials, arranged as a series of 2nd order sections:

 * Note: n is filter order. * * n Polynomials * -------------------------------------------------------------------- * 2 s^2 + 1.4142s +1 * 4 (s^2 + 0.765367s + 1) * (s^2 + 1.847759s + 1) * 6 (s^2 + 0.5176387s + 1) * (s^2 + 1.414214 + 1) * (s^2 + 1.931852s + 1) * * For n=4 we have following equasion for the filter transfer function: * * 1 1 * T(s) = --------------------------- * ---------------------------- * s^2 + (1/Q) * 0.765367s + 1 s^2 + (1/Q) * 1.847759s + 1 *The filter consists of two 2nd order sections since highest s power is 2. Now we can take the coefficients, or the numbers by which s is multiplied and plug them into a standard formula to be used by bilinear transform.

Our standard form for each 2nd order section is:

 a2 * s^2 + a1 * s + a0 H(s) = ---------------------- b2 * s^2 + b1 * s + b0Note that butterworth nominator is 1 for all filter sections, which means s^2 = 0 and s^1 = 0

Let's convert standard butterworth polynomials into this form:

 0 + 0 + 1 0 + 0 + 1 -------------------------- * -------------------------- 1 + ((1/Q) * 0.765367) + 1 1 + ((1/Q) * 1.847759) + 1 Section 1: a2 = 0; a1 = 0; a0 = 1; b2 = 1; b1 = 0.5176387; b0 = 1; Section 2: a2 = 0; a1 = 0; a0 = 1; b2 = 1; b1 = 1.847759; b0 = 1;That Q is filter quality factor or resonance, in the range of 1 to 1000. The overall filter Q is a product of all 2nd order stages. For example, the 6th order filter (3 stages, or biquads) with individual Q of 2 will have filter Q = 2 * 2 * 2 = 8.

These a and b coefficients are used directly by the szxform() and bilinear() functions.

The transfer function for z-domain is:

 1 + alpha1 * z^(-1) + alpha2 * z^(-2) H(z) = ------------------------------------- 1 + beta1 * z^(-1) + beta2 * z^(-2)When you need to change the filter frequency cutoff or resonance, or Q, you call the szxform() function with proper a and b coefficients and the new filter cutoff frequency or resonance. You also need to supply the sampling rate and filter gain you want to achive. For our purposes the gain = 1.

We call szxform() function 2 times because we have 2 filter sections. Each call provides different coefficients.

The gain argument to szxform() is a pointer to desired filter gain variable.

double k = 1.0; /* overall gain factor */Upon return from each call, the k argument will be set to a value, by which to multiply our actual signal in order for the gain to be one. On second call to szxform() we provide k that was changed by the previous section. During actual audio filtering function iir_filter() will use this k

[size="5"]Summary:

Our filter is pretty close to ideal in terms of all relevant parameters and filter stability even with extremely large values of resonance. This filter design has been verified under all variations of parameters and it all appears to work as advertized.

Good luck with it. If you ever make a DirectX wrapper for it, post it to comp.dsp.

 * * ---------------------------------------------------------- *References: *Van Valkenburg, "Analog Filter Design" *Oxford University Press 1982 *ISBN 0-19-510734-9 * *C Language Algorithms for Digital Signal Processing *Paul Embree, Bruce Kimble *Prentice Hall, 1991 *ISBN 0-13-133406-9 * *Digital Filter Designer's Handbook *With C++ Algorithms *Britton Rorabaugh *McGraw Hill, 1997 *ISBN 0-07-053806-9 * ----------------------------------------------------------

Report Article

## User Feedback

There are no comments to display.

## Create an account

Register a new account

• 0
• 0
• 25
• 0
• 1

• 13
• 26
• 10
• 11
• 44
×