- JuanS

# IIR vs FIR: Understanding their differences

Updated: Jul 8

Very often when I hear discussions about IIR and FIR filters I end up surprised about how many erroneous conceptions there are around them. Actually most of the things that people state as differences between one and the other come from their most common usages; however, clearly understanding what these acronyms mean (which is very different from knowing the acronym itself) it should be easy to see why most of these conceptions end up being erroneous.

## ¿What are they?

First lest start with their definitions. IIR (infinite impulse response) filters, as their name states have impulse responses that are infinite in length; on the other hand FIR (Finite Impulse Response) filters have impulse response with a finite length. The key for this distinction, and the reason behind being able to generate an output of infinite length when exciting the system with just an impulse, is mainly on a feedback structure. The only way to generate an impulse response that extends indefinitely is to feed the output in some way back into the system to generate a recursion where, at each moment, the output is defined by previous outputs.

In general, digital filters are build with two elemental blocks: delays and gains. These two elements are combined in clever structures to generate desirable effects in the frequency domain. This process can be done in thousands of different ways. There are very interesting and varied ways of designing these filters; however, in this article, we are only interested in understanding the difference between these two categories FIR vs IIR.

## FIR

Let start with FIR filters, although they seem less common, I think their structures are more intuitive. The idea of FIR filters is to connect the input of the filter to a series of delays (often called a delay line). The first one with only one sample of delay, the second one with two, the third one with there and so on. After that, it gets amplified or attenuated with a gain factor specific for that delay and finally the delayed outputs are summed together. Additionally, because this structure is analogous to a tapped delay line, we tend to talk about taps that in reality are just these gain factors, coefficients of the filter or amplitudes of the impulse response. An FIR is that simple. The following animation shows this process and, in particular, how these gain factors are equivalent to the coefficients of the impulse response.

## IIR

An IIR filter, in addition to using delays for the input values of the filter, also takes values at the output, applies a new delay chain and feeds back this signal to the input of the filter. This additional element allows the design of “interesting" transfer functions without requiring a huge amount of elements. Understanding how these transfer functions are achieved, both in the case of FIR and IIR, is not a simple process achieved through the solution of difference equations (sums and subtractions of delayed inputs and outputs) through the Z-transform (a “discrete” version of the Laplace transform). Maybe in a future article we could explore these details. The following animation shows this process. Check that the impulse response lasts many more samples than the amount of delays that exist in the system.

## Some Simple Examples

Let's analyze a simple FIR filter. Its impulse response (and accordingly the gains of the associated delays) will be 0.5, 0.5. This filter is clearly a low pass filter (Of Course! :) ). To show this, let's notice that if the input is a DC, the output isn’t affected. The output at each sample is half the value of the input plus half the previous input. Because both the current input and the previous one have the same value because the amplitude of the signal is constant, the output would be equivalent to the input. In other words, the transfer function would have a unitary gain at 0Hz. In contrast, if the signal is a sinusoid at the Nyquist frequency (lets remember that at the Nyquist frequency, the waveform has two samples per period) the signal would oscillate between two values so lets assume it moves between +1 and -1. Clearly if we filter this signal with an FIR filter whose impulse response is [-0.5, 0.5], each sample would be half of its current value plus half of the previous value. In this case the sum is always 0. In other words, the transfer function of this filter has a gain of minus infinite decibels at the Nyquist frequency!. It is indeed a low pass filter.

IIR filters are a bit harder to analyze. Nonetheless, let's see a simple example. Suppose that an IIR filter is defined in such way that the output is calculated as the sum of the current input plus 90% of its previous output. If we feed an impulse through this the first output value would be 1 as the input was an impulse. However, after this sample the input wouldn’t have any other input values as the input signal is an impulse. The only thing that is left is to use the previous output (1) to compute the new output as the 90% of its value. The output of the second output would be 0.9. We repeat this process and calculate 90% of the previous output which was 0.9 obtaining an output of 0.81. We keep doing this process until the output has an output of 0. When does this happen? Never! The impulse response will be [1, 0.9, 0.81, 0.729, 0.6561, 0.59049, ...] and it will follow the formula 0.9^n where n is the number of the sample that we want to compute (starting with 0). This geometric series will never get to 0 and is almost equivalente to one of Zeno’s paradox. In this paradox, Achilles is chasing a tortoise halving its distance to the animal every now and then. However, because each time he halves the distance that’s left he is never able to catch the tortoise. Of course, both in Achilles case as in ours, the innate quality of the situation depends on having an infinite resolution. In our case, at some point the impulse response will fall below the representable values of the digital system and will finally reach its end.

This last point is actually crucial for the correct development of DSP. Given that we use floating point architectures, we have very surprising capabilities to represent very very small numbers. BUT! There’s a small problem hidden behind all this. ¿Do you remember subnormal numbers from the article about bit depth? ¿Those where the numerical representation has reached the smaller available exponent in floating point and the arithmetic operations become super expensive? If an IIR filter is not properly designed, its impulse response could reach that subnormal range, and then, our computer starts to do an incredible effort to precisely represent very small values near -300dBfs. I always wonder if all the available freeware is always considering this type of things.

## Erroneous conceptions and counter-examples

Finally, and having understood what FIR and IIR filters are, I would like to share some counterexamples about common misconceptions. For example, it is common to hear people talk about minimum phase and linear phase as oposite concepts; however, they are simply two separate characteristics of a filter’s impulse response. A minimum phase filter is a filter whose impulse response has its energy maximally concentrated near its starting point. This in comparison to all the other impulse responses that have exactly the same amplitude response. IIR filter tend to be minimum phase filters as they are optimized to be extremely simple and efficient in their structure; however, there are cases where this doesn’t happen. The simplest one is an all-pass filter as the minimum phase all-pass filter is actually a unitary gain. A perfect impulse is the impulse response associated to a flat amplitude response with the most concentration of energy at the beginning of the impulse response. Due to this, every IIR all pass filter whose phase is flat is NOT a minimum phase filter.

Analogously, we tend to think that FIR filters are linear phase filters; however, it is incredibly easy to build an FIR filter whose phase isn’t linear, it is even easier to do a minimum phase FIR. We only have to measure a minimum phase IIR, obtain its impulse response and use its values as the coefficients of our FIR filter. Actually, this process is a digital filter design method based on analog filters closely related to the impulse invariance method.

An IIR filter can’t have linear phase?. This is one that I don’t tend to discuss very much as it is true that it isn’t possible in realtime schemes. To understand what linear phase is, let's see what is required so that a filter can be called linear phase. A filter is linear phase if and only if its impulse response is symmetrical. The intuition behind this is that the first part of the filter will alter the phase en one direction and the second part will alter it in the opposite direction. We could even take a full length song, reverse it and paste it at the end and we would obtain a linear phase FIR (Note that being linear phase doesn’t say anything about how. Concentrated is the energy around the center of our impulse response!). Clearly, this isn’t possible with an IIR filter as its impulse response is infinite. But if we are not required to process in real time, there’s nothing preventing us from processing a signal with an IIR filter, reversing the signal in time and processing it again. Voila! A linear phase IIR filter (and if it was a minimum phase filter, it wouldn’t only be a linear phase filter but it would be the linear phase filter that concentrates the most the energy around the center of our impulse response).

Given that we don’t usually see analog FIR filters, we tend to think that these only exist in the digital domain. Certainly, given that they are based on precise delays of the signal, it would be very complicated to use, for example, 128 tape based analog delays to achieve an FIR filter that in the digital domain takes only a few bytes. But that doesn’t mean that it is impossible to obtain an analog domain based FIR filter. In fact, we have a very intuitive one around us all the time. When an acoustical wave impacts a hard surface and reaches our ears a few milliseconds later, a comb filter is generated. This filter is simply the sum of a signal with a delayed version of itself… hummm.. that sound a lot like what an FIR filter is!

FIR vs IIR? Which is better. As always I try to explain a few things but also generate some questions around it. In reality, the fact that there are methods to generate FIR filters through the impulse responses of IIR filters showing that they aren’t that different. On top of that there are opposite methods as Prony’s method. This allows the generation of IIR filters using FIR filters as a starting point. Definitively they are different types of beasts and each has its pros and cons; however, very often we jump to conclusion and believe that the benefits of certain processor in comparison to another one might be on this characteristic when there could be 1000 variables influencing the final result. When I talk to people who understand very well these topics we always reach the same two conclusions. One: everything is a filter and two: In DSP everything is equal to everything if it is analyzed with the correct perspective. What do you think about all this?