Basic Electroacoustics -- Fall 2000.

Introduction to Digital Filter Theory.

Q: what is a filter?

A: a filter is any body (acoustic), device (analog) or equation (digital) that attenuates (cuts) or resonates (boosts) certain frequencies in a signal (sound) that is passed through it. examples of filters you hear everyday include:

• the human voice.

• any acoustic space (a room).

• the graphic equalizer on your stereo.

• the headset on your telephone.

digital filters can be created very simply by understanding a few simple terms and some simple principles...

the main principle of digital filtering can be demonstrated with an example:

take the following information as given:

fig. A

fig. B

a square wave contains all the odd harmonics of a fundamental in a 1/n relationship (where n is the harmonic number).

a sine wave, however, contains just the fundamental.

we can imagine a filter that would be able to turn a square wave (fig. A) into a sine wave (fig. B). the acoustic result would be to cut out all the high harmonics in the square wave to leave just the fundamental. we can see from the graphs (and know from basic acoustics) that sharper edges in a signal usually mean that there is acoustic information at higher frequencies.

probably the easiest thing to do would be to somehow smooth the edges of the square wave so that its waveform resembles that of a sine wave. this would reduce the highs.

how would we do that?

what would happen if we averaged every sample in time with the last sample?

e.g. if our square wave looked like this:

1 1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 —1

our 'averaged' waveform would look like this:

0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. -1. -1. -1. -1. -1. -1. -1. -1. -1. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. -1. -1. -1. -1. -1. -1. -1. -1. -1.

not quite a sine wave, but if we keep going we get something like this....

-0.875 -0.375 0.375 0.875 1. 1. 1. 1. 1. 1. 0.875 0.375 -0.375 -0.875 -1. -1. -1. -1. -1. -1. -0.875 -0.375 0.375 0.875 1. 1. 1. 1. 1. 1. 0.875 0.375 -0.375 -0.875 -1. -1. -1. -1. -1. -1.

in mathematical terms...

in equation form what we did was this (where y is an output sample, x is an input sample, and n is the current time):

this is called a first-order filter, because it uses one delay of past values to compute the output.

BIG IMPORTANT FACT #1: in digital systems, all filters are delay lines.

the type of filter we just created was called a low-pass filter, because the particular delay line equation we used had the net effect of damping the high frequencies (and, therefore, 'passing' the low frequencies).

in order to make more complicated filters (like ones which cut a specific frequency band), more samples of delay are required. also the averaging coefficients of the equation (which in the last example were both 0.5) need to be variable. also it's often the case that the output sample (y) is fed back into the average (this is called a feedback filter or iir filter, as opposed to a feedforward or fir filter, which only uses input samples for its averaging).

in a filter equation, the amount of strength (the multiplier) you give to each sample used in the equation is called a filter coefficient. in this example, the two 0.5's are called coefficients. a more generalized first-order filter would have the equation:

where a and b are variable coefficients. if you want, they can even be negative numbers (though they rarely exceed the range -1 to 1).

in all the equations thus far all the samples used in the filter equation have been INPUT samples (denoted by the letter x). these types of filters are called feedforward, non-recursive, or FIR (finite impulse response) filters.

some filter equations, though, can look like this:

^--- note the 'y'

this means that the current output sample is calculated not by averaging two past input samples, but by averaging the current input sample with the last OUTPUT sample (denoted by the letter y). this types of filters are called feedback, recursive, or IIR (infinite impulse response) filters. IIR filters have a larger potential gain (i.e. are stronger) than FIR filters but also introduce more artifacts into the signal.

a very popular filter is called a biquadratic filter (or biquad, for short). it uses two samples of delay (n-1 and n-2) on both the input and output and lets you average all of them independently with the current input sample in the following equation (where a, b, c, d, and e are the averaging coefficients):

^--- input samples. ^--- output samples fed back in.

but before you drag out your calculators to start computing these things, it's important to learn how most people and most software talk about filters.

generally speaking, there are four kinds of filters:

low pass filters: filters that cut off everything above a certain frequency.

high pass filters: filters that cut off everything below a certain frequency.

band pass filters: filters that cut off everything on either side of a certain frequency band.

band reject filters: filters that cut out everything within a certain frequency band.

filters have up to three parameters: an amount of gain (or cut), a center or cutoff frequency, and a bandwidth or Q.

the center frequency of band filters is the center point of maximum boost or cut in the filter (i.e. the center of the filter). the cutoff frequency of a lowpass or highpass filter is the point at which the frequency is attenuated at 0.707 of it's full value. the bandwidth is determined by finding how wide (in Hz) a band filter is from the .707 point below the center frequency and the .707 point above the center frequency. if you divide the bandwidth by the center frequency, you will get a number called the Q of the filter, which you can use to preserve logarithmic pitch relationships in filters (i.e. the bandwidth will shrink as the center frequency gets lower, so that the perceived width of the filter doesn't change).

finally, comb filters are short feedbacking delay lines that cause a signal to resonate at a frequency and its integer multiples. the delay time of a comb filter is determined by the computing the sampling rate divided by the desired frequency.