Audio FIR Filtering – Part 1
A Guide to Fundamental FIR Filter Concepts & Applications in Loudspeakers
Although not a new technology, manufacturers are increasingly including FIR (finite impulse response) filtering in loudspeaker processors and DSP based amplifiers due to the significant increase in performance-versus-cost of microprocessors and DSP hardware.
The advantages of FIR filtering include more arbitrary and fine control of a filter’s magnitude and phase characteristics, independent control of magnitude and phase, and the opportunity for maximum-phase characteristics (at the expense of some bulk time delay). The primary disadvantage is efficiency; FIR filters are generally more CPU intensive than IIR (infinite impulse response) filters. For very long FIR filters, segmented frequency-domain and multi-rate methods help to reduce the computational load, but these methods come with increased algorithmic complexity.
In pro audio, the terms FIR Filter and FIR Filtering are often used when referring to specific implementations, such as:
- linear-phase crossover and linear-phase brick-wall crossover filters
- very long minimum-phase FIR based system EQ
- horn correction filtering
Whilst these implementations each have their uses, the capabilities of FIR filtering go beyond these implementations; particularly with regard to independent control of magnitude and phase, and mixed & maximum-phase characteristics.
So, what is FIR filtering and how does it compare to ubiquitous IIR filtering? This article aims to answer these questions, but doing so first requires covering a number of basic concepts in digital audio. If you’ve studied digital signal processing, much of this will be second nature. Forgive me for skipping some of the details and simplifying some of the more complex concepts.
1. Key Concepts in Digital Audio
In digital audio, sound waveforms are represented by samples. An analog-to-digital converter (ADC) measures, or samples, an analog signal and assigns a digital value to each sample. Humans can typically hear frequencies between 20 Hz and 20 kHz. (A Hz is a cycle per second.) To adequately represent this frequency range digitally, the ADC needs to sample the audio waveform at least twice the highest audible frequency; hence we have the common sample rates of 44.1 kHz and 48 kHz. (Multiples of these frequencies, such as 88.2 kHz, 96 kHz, 192 kHz and 384 kHz are also used in pro audio; for reasons we won’t go into here.) Half the sampling rate is called the Nyquist frequency. For example, a sampling rate of 48 kHz has a Nyquist frequency of 24 kHz.
Digital filtering is a mathematical process for altering a digital audio signal. At each time interval – for a sampling rate of 48 kHz, the interval is 1/48000 seconds or 20.83 microseconds – a time-domain digital filter takes the current input sample and some previous input samples, scales (or multiplies) the samples by defined numbers, called filter coefficients, and sums the scaled samples to create an output sample. Let’s look at some examples.
Example : “Averaging” Filter
One of the simplest digital filters involves taking the average of the current and previous samples. Conceptually this is:
OutputSample = (InputSample + PreviousInputSample) / 2
As a diagram, we can express the filter as:
As an equation, we can express this as:
y[n] = 0.5 * x[n] + 0.5 * x[n-1]
- x[n] is the input sample at the current time interval, or sample number, n,
- x[n-1] is the input sample at the previous time interval, or sample number n-1,
- y[n] is the output sample for the current time interval, or sample number n, and
- the “0.5” values are the filter coefficients.
Before continuing it’s worth pausing to consider the impulse response and frequency response and how they relate to the filter structure above.
Impulse Response and Frequency Response
The impulse response of a device – an analog filter, a digital filter, a loudspeaker or even a room – is the reaction or response of the device over time in response to an input pulse.
Theoretically we can put a voltage, digital or acoustic pulse into a loudspeaker, amplifier, processor or room and record the output voltage, digital signal or microphone waveform over time to obtain the impulse response. However, a pulse doesn’t have enough energy at all frequencies to excite a device with enough level to give a reasonably clean signal above ambient noise (or a signal-to-noise ratio; SNR) at all frequencies.
Today many measurement systems use either a sinusoidal sweep or cyclic pink noise. (Dual FFT methods use any audio signal – like the output of a live mixing console – but that’s another story.) Sweeps and cyclic pink noise signals have enough energy at all frequencies to give reasonable SNR and therefore give a usable or stable impulse response.
The frequency response is the frequency-domain behaviour of the device. It’s also the frequency-domain equivalent of the impulse response. (The term transfer function is sometimes used in place of the frequency response.) The frequency response is usually plotted as the magnitude (in dB) and phase (in degrees) across frequency. The frequency response can also be converted from magnitude and phase to a complex number representation; real and imaginary values for each frequency point.
Impulse Response ⇔ Frequency Response
The time-domain impulse response and frequency-domain frequency response are inherently linked and are mathematically-equivalent characterisations of the device. We can convert the impulse response to the frequency domain using the Discrete Fourier Transform (DFT) and convert the frequency response to the time domain using the Inverse Discrete Fourier Transform (IDFT); subject to some constraints that we won’t go into here. The fast implementations of these operations are called the Fast Fourier Transform (FFT) and the Inverse Fast Fourier Transform (IFFT).
[I removed the box describing cyclic pink noise, just to reduce the article length.]
… back to the “Averaging” Filter Example
The impulse response of a digital filter is the output of the filter when we pass an impulse – a sample value of 1.0 – through the filter followed by zeros. Let’s calculate the impulse response.
For this filter, the impulse response is [0.5 0.5] for the 1st two time-intervals, and zero everywhere else. Its length is two samples, and since this length is finite, the filter is a finite impulse response or FIR filter.
Since this filter “averages” pairs of samples, we would expect large sample differences to be smoothed out, and very low sample changes to mostly be unaffected. Let’s look at the frequency response magnitude.
Sure enough, the averaging filter is a low-pass filter. Low frequencies, where the audio signal varies more slowly over time, are unaffected, but high frequencies are attenuated.
Example : “Difference” Filter
Let’s look at what happens if we change the sign of one of the coefficients in the averaging filter. As a diagram, we can express the filter as:
As an equation, we can express this as:
y[n] = 0.5 * x[n] + -0.5 * x[n-1]
This filter cancels out adjacent samples that are the same, or similar, and emphasises pairs of samples that are very different. The difference filter’s frequency response is quite different to that of the averaging filter.
The difference filter is a high-pass filter. High frequencies are mostly unaffected, but low frequencies are attenuated.
Example : Digital Filter with Feedback
The filters in the two previous examples calculated the sum of a scaled history of samples. What if we take a previous or delayed sample, scale it, and feed it back into the sum?
The following diagram shows a Butterworth 1st order low-pass filter with a cut-off frequency of 1 kHz (fs = 48 kHz). The important thing to note is that a portion of the previous sample is fed back, or re-circulated, into the filter.
For a digital filter, the filter order is the maximum amount of sample delay used in the digital filter.
For IIR low-pass and high-pass filters, the frequency response roll-off is 6 dB per octave multiplied by the order. (For example a 3rd order high-pass filter has an 18 dB/oct roll-off.)
Let’s calculate the impulse response.
For this filter, the impulse response starts with a value of 0.0615 and, even though subsequent input samples are 0, the output of the filter decays but continues with non-zero values essentially forever. Since the output of the filter goes on for infinite time, the filter is called an infinite impulse response or IIR filter.
The thicker blue line in the following diagram shows the frequency response of the low-pass filter.
The thinner blue line above shows the response of a 1st order high-pass Butterworth filter with a cut-off frequency of 1 kHz (fs = 48 kHz). The following diagram shows the signal flow and coefficients for the high-pass filter.
In the following sections low-pass and high-pass filters will often be referred to as LP or HP filters.
2. The FIR filter
The following diagram shows the signal flow for a general FIR filter. The coefficients (C0 to CN-1) are the “taps” and so for a N length FIR filter there are N taps and N-1 sample delay elements. The filter order is N-1.
While a short FIR filter can’t do very much, longer FIR filters become quite powerful by essentially blending a long history of audio samples to cause level and phase changes at different frequencies in controlled ways.
3. The IIR Biquad
The second order IIR filter is typically called the biquad filter. (The following diagram shows the Direct Form 2 version.)
Biquads form the basis of most IIR filtering in DSP’s. Shelf, parametric and all-pass filters can be implemented in this form, and high-pass and low-pass filters of any order are usually implemented as a cascade of connected biquad filters. A 1st order filter can be implemented in the biquad by setting coefficients a2 and b2 to 0.0. Setting coefficients a1 and a2 to 0.0 turns the biquad into a 3-tap FIR filter.
4. FIR versus IIR Filters
So how do IIR and FIR filters compare? Let’s take a look at some common filter types.
Comparison : FIR filters vs 1st order IIR LP and HP filters
The following two plots show the frequency responses of 1st order Butterworth IIR LP and HP filters along with FIR filters of various lengths that are designed to approximate the IIR filters. (The FIR design method used involves sampling the IIR filter impulse response and applying DC correction.) Here the FIR filters needs to be ~40 taps or longer to begin to accurately approximate the IIR filters. The 10, 20 and 30 tap FIR filters have significant ripple and deviate from the IIR, in magnitude, by up to ~6 dB.
Comparison : FIR filters vs 2nd order IIR parametric filter
The following two plots show the frequency response of a 1 kHz Parametric IIR filter along with FIR filters of various lengths that are designed to approximate the IIR filter. Each plot shows a different FIR design method. The first method has more error toward DC but a slightly better match near 1 kHz. The second method matches the IIR better above and below 1 kHz but has a slightly worse match around 1 kHz. Using either method, the FIR filter needs to be ~40 taps or longer to begin to accurately approximate the IIR parametric filter.
5. FIR Filter Length
Since FIR filters don’t have feedback, their ability to affect low frequencies is directly proportional to their length. The longer the filter, the lower the frequencies that can be adjusted; either in magnitude, phase or both. Higher Q adjustments – sharper magnitude and phase transitions – also require longer FIR filters.
Following are examples of 384 and 3072 tap FIR filters; the filter responses are the dark-blue and dark-red lines. Both FIR filters are attempting to match the desired EQ for a loudspeaker – the light-blue and light red-lines. The difference plots show the difference in magnitude and phase between the desired ideal filter frequency response and the frequency responses of the FIR filters. Note:
- The longer the filter, the more effective FIR filtering is at achieving EQ, particularly toward low frequencies.
- Even the 3072 tap FIR filter can’t achieve the high-Q magnitude change desired at ~65 Hz. (It actually takes over 10000 taps at 48 kHz for the FIR filter to match the desired EQ.)
384 Tap FIR Filter
3072 Tap FIR Filter
In part 2 we will look at computational complexity, relative to IIR filtering, and key FIR filter benefits, including independent control of magnitude and phase.
* All the FIR filter examples and plots in this document were generated with FIR Designer.