Monday, February 18, 2013

Digital Filter University - Course IV: Filter Theory

You may have been wondering when we'd get around to filter theory. Or maybe you paid attention in the first lecture and knew it would be now.







I couldn't have said it better if I'd ... oh yeah, I did say it myself. But once is enough.












Think back to the seven sample averging filter we discussed previously.














This filter can be drawn in standard filter notation as follows. Recall that the z^-1 element is a unit delay. This filter takes a seven-sample average of the most recent seven samples.











The averaging filter is an FIR or finite impulse response filter. The genera filter of this variety is shown below. Note that, generally speaking, this can have any number of delays and coefficients, and that the coefficients need not all be the same value.










Due to its utility in filter analysis, we define the impulse signal, which is valued 1 at one time (usually n=0), and 0 at all other times.











We use this impulse signal to get the impulse response of a filter. For an FIR filter, such as the average, the impulse response is just the list of coefficients, as you see here.









We are going to use the z-transform a an analysis tool for digital filters. In the sample domain, we have to 'convolve' the impulse response by the input to get the output. This is simple to do in HW but more difficult to do by hand. And, it doesn't teach us as much about the system as the 'frequency response,' which is the z-transform of the impulse response.

But don't worry. You might have run into z-transforms before and hated them. So did I. But I promise this time it will be simple and painless.







Recall that we can take our difference equation description, and change it to a z-transform description by applying a simple relationship as below.

Did you follow all that?











The transfer function is Y(z)/X(z). It tells us what we multiply the input by to get the output (in the z-domain, at least). The general (IIR) transfer function is shown. For FIR filters the denominator coefficients are all 0. (The funny upside down Vs, capital lambdas I guess, should have been ellipses (...). One day I might get around to updating the graphic.)







A step function is one that is zero up until a point, usually time 0, and then one forever after.







Like its very good friend the impulse function, the step function gives us insight into filter behavior.









Notice that it took the filter a while to "charge" up to the steady output of one. We learned something here about the "charge" time of the filter, and about how it will behave initially when hit with a new signal, or a large, long-lasting burst of energy even within a signal that it was already filtering.

We often plot filter responses on a dB scale. Decibels are defined below. This gives us a way to plot data with ranges that are otherwise too large to visualize.









We can get from the z-domain transfer function to the frequency response of a filter by substituting exp(i omega) for z, as shown below. This is a complex function. If we plot the magnitude (in dB, typically) as a function of frequency we have the magnitude response. We can also plot the phase, as shown below.










The phase above is actually linear, but "wrapped." If we were to "unwrap" it - remove the discontinuities at 180 degree intervals and attach the segments end to end - this one would be a nice linear function. Note how linear each segment appears. And there are ways to know, theoretically that it's perfectly linear.

When the phase is perfectly linear, it has a constant group delay. We see below that the group delay is the negative frequency derivative of the phase.










The Matlab code below shows how to create the filter response plots without using any fancy tools such as from the Signal Processing Toolbox. Similar commands could be used in other math tools. In my book I even show how to do it in Excel.










The arithmetic below shows how to use Euler's equations to get the frequency response of the averaging filter in terms of sines and cosines. You won't need to do all that by hand if you have access to a good math tool. And there are free ones out there.











Now let's think about this filter that showed up previously.










The frequency response for this filter, with the coefficients shown, is shown below. Note also how it smoothes the erratic noise signal (blue) to create the red output signal.







The phase response and group delay for this filter are shown. 









Recall the various types of filters. There are types not shown here, but this is most of the common ones.














If you use my book to design your digital filters, you will not need these, though their effects are embedded within my equations.

Many digital filters begin life as analog filters, and typically as a prototype analog lowpass filter. This prototype is then transformed, using one of the equations below, to have the desired critical frequency(ies) and to be of the desired type. After that it is transformed to digital.













Below are some of the standard forms for digital filters. Any of these can implement any filter type, depending upon the coefficients.








No comments:

Post a Comment