Friday, 18 July 2014

Impulse Response

If you choose to embark upon an entrepreneurial career, you will often find yourself putting together financial spreadsheets to model your business. Investors in particular love to pore over scenarios of how your business might develop, and having a good financial model is an invaluable tool to have at your disposal. Of course, if you’re smart, you’ll want to thoroughly test your spreadsheet to make sure that your financial logic contains no embarrassing errors. One of the techniques for doing that is to enter an arbitrary billion dollars into one of the input cells, and see where else in your spreadsheet unexpected extra billions show up. It is very easy to spot billions of dollars when they start to appear in places they don’t belong. You might say that what you are doing is measuring the “impulse response” of your spreadsheet.

Digital filters are no different. Data goes in one place, and results come out someplace else. In this case, both the inputs and outputs are streams of numbers. Conceptually, digital filters are quite simple things. You take the input value, and add to it bits of the previous input values together with bits of the previous output values. That’s really all there is to it. The filter design tells you how many of the previous input and output values go into the mix, and precisely what fraction of each to use. Some filters only rely on the previous input values, and don’t use the previous output values. Filters that do use the previous output values have an interesting property - each output value contains a little bit of each and every previous input value.

What are the implications when a bit of one input value ends up in each and every one of the subsequent output values? A very easy analysis would be to take a signal comprising digital silence - in effect nothing but zeros - and modify it so that one data point (and only one data point) is at a maximum value. We call this waveform an “Impulse”. We put this data stream through our digital filter and see what comes out the other end. What happens is that the output comprises a stream of zeros up until the time the impulse reaches the input of the filter. After that, the output will comprise a sequence of non-zero values - in effect a series of echoes of the original impulse. This artificial construct - how the residue of one single impulse value in a sea of zeros appears in the output data stream - is called the “impulse response” of the filter. If the filter uses only previous input values and no previous output values, then the echoes will fall to zero as soon as we reach the point where the impulse is no longer one of the previous values that goes into the mix. Such filters are called “Finite Impulse Response” (FIR) filters. If, however, the filter uses previous output values, then the echoes of the impulse will remain within the output signal forever, or at least until such time as its magnitude becomes too small to register. These filters are called “Infinite Impulse Response” (IIR) filters.

An impulse response looks like a waveform. You can easily plot it out. It looks like a waveform precisely because it is a waveform, and you can do anything with it that you can do with any other waveform. Impulse responses have many interesting properties, most of which are beyond the scope of this post. But, as an example, if we take its Fourier transform, the result is the transfer function of the filter, which is to say its frequency and phase responses. This is why the key aspects of a filter’s performance are intimately inter-related. Once you define a filter’s frequency response (for example by defining the characteristics of a low-pass filter) and phase response (for example by specifying linear phase or minimum phase), you will have set in stone its impulse response. In other words, the impulse response (IR) is the direct consequence of the choices you have made in terms of frequency response (FR) and phase response (PR). What it boils down to, is that when it comes to filter design, you only get to specify any two of its IR, PR and FR, and the third will be determined for you.