Example Digital Filters

Donald Daniel

Jan 2008, revised Jan 2012

up one level

introduction

This document shows example filter curves produced using the technique described in the article "Complex Digital Filters Using Isolated Poles and Zeroes". That article includes an introduction to the concept of digital filters of the simple type that simulate the behavior of analog filters. This kind of digital filter is the most appropriate for computer programs that simulate the behavior of lumped physical systems, whether electrical, mechanical, or acoustical. It is also the most appropriate for some kinds of audio signal processing. If you are new to the subject that article and this one should be read together, they complement each other. To see that article click here. See also the derivation of a pole here and the derivation of the zero from the pole here.

To use the filter technique presented here, you start with a stream of real numbers, add zero imaginary part to convert it to a stream of complex numbers, feed it through the filter. Provided the pole-zero pattern is symmetrical about the real axis as it always is in the analog world, the output stream will have an imaginary part that is zero and can be discarded to produce a stream of real numbers for the output. You do not need a programming language with complex numbers built in. The language Oberon-2 used to program the examples shown here does not have complex numbers. The simple amount of complex arithmetic needed here is easy to program in any programming language.

In every example in this article, the gain of the filter is normalized to unity gain, zero dB, at some particular frequency. The other article explains how to do this. The pole and zero are given respectively by the following two equations, which are described more fully in the other article. "j" is the square root of minus one. The time interval between samples is "t", a constant.

pz.png

The illustrations presented here were computed using oo2c and filter formulas primarily from the book "Synthesis of Passive Networks" by Ernst A. Guillemin, 1957. The details are available as a zip file, if you do not have too much "clickophobia" to unpack a zip file.

simple filters

A pole on the negative real axis of the complex plane is shown in this example where the pole is shown as an "x" at the first tic mark to the left of the origin:

p1pln.png

Frequency response plots start at the origin and move up the vertical axis for positive frequencies, or down for negative frequencies. The frequencies shown in all plots are regular frequencies, they are radian frequencies divided by two pi. Linear plots show both positive and negative frequencies. Log plots show only positive frequencies. In the log plots "1.0E1" is 10 Hz, and "1.0E5" is 100000 Hz. A decade is a factor of 10 change in frequency. The log plots cover 4 decades. Each decade is marked with vertical lines in a 1, 2, 5 sequence. In most of the plots the upper limit of frequency is 1E5, which is half the sample frequency, and is the highest frequency where the digital filter can possibly operate. The log plots are all calculated from products of the pole-zero gain formulas, not measured by FFT's. This is very accurate. Later linear plots will be shown that are FFT measurements of filter performance.

It should be mentioned that because we call our sample rate twice 1E5 that does not mean that calculations are actually done at that rate. In our software the size of the time step variable is just a number, not a time. Our calculations show what would happen if we had a hardware digital filter that actually operated at the chosen rate. But our computer program can compute what would happen at a rate so fast that it would be impossible to build a hardware digital filter that would operate at the chosen rate.

The vertical axis represents the ratio of the output of the filter to its input. The solid curve represents the output of the digital filter. The dashed curve represents the response of a real hardware filter that the digital filter simulates. If the simulation is perfect the two curves will overlap and the dashed curve will not be visible. The vertical axis in all plots is in decibels (dB). A decibel is ten times the logarithm to the base ten of a power ratio. Since power is proportional to the square of voltage, pressure or force, a decibel is twenty times the logarithm to the base ten of a ratio of voltage, pressure, or force. When the response is at zero dB, that means the output is the same magnitude as the input.

The next figure is a log plot of the previous example, where the negative pole is scaled to the value -1E3. Even though the pole is on the horizontal axis, it affects response as the frequency moves up the vertical axis. The response is 3dB down at 1E3 on the vertical axis. An octave is a factor of 2 change in frequency. The response is flat at low frequencies and rolls off to a slope of 6dB per octave or 20dB per decade. At the upper limit of frequency, 1E5, the simulation has deviated from the correct answer, the dashed line. Because this filter is flat at low frequencies and down at high frequencies, it is called a lowpass filter.

p1log.png

Next we put two poles in the same location where there was only one pole before. The result is similar, but now it is 6dB down at 1E3 and the slope is 12dB per octave or 40dB per decade:

p2log.png

In audio applications it is sometimes useful to have a filter with a slope of 3dB/octave, or 10dB/decade. Such a filter will convert white noise to pink noise with equal noise power in each octave. Here we give sigma numbers on the real axis that are not divided by two pi. A filter normalized to unity gain at zero frequency, with a pole sigma of -1E2, a zero sigma of -3.16E2, pole -1E3, zero -3.16E3, pole -1E4, zero -3.16E4, pole -1E5 will have the desired slope as shown here:

db3.png

We now put one pole on the negative real axis as before, and add a zero at the origin. Any filter with a zero at the origin models an analog filter that passes only alternating current (AC), blocking direct current (DC). Such behavior is called either "a DC block" or "AC coupled".

p1hppln.png

Since the pole and zero are both on the real axis this filter can be computed with real arithmetic, as shown in the audio programming example at this link. The result is now a highpass filter with a positive 6dB per octave slope at low frequencies and a 3dB point of 1E3:

p1hplog.png

We now present examples to explore the uses of a complex conjugate pair of poles 1E3 from the origin at 45 degrees from the imaginary axis:

p2lppln.png

The log plot is a lowpass filter which rolls off at 1E3 and goes down at 12dB per octave:

p2lplog.png

Next we add a zero at the origin:

p2bppln.png

The result is a bandpass filter centered at 1E3 with a 6dB per octave slope on either side:

p2bplog.png

Finally, we add a second zero at the origin, indicated by the number "2" nearby:

p2bplog.png

The log plot shows a highpass filter at 1E3 with a 12dB per octave slope at low frequencies:

p2bplog.png

Now we show a bandpass filter with the real component of the pole locations only 0.03 of the imaginary part:

p2nbpln.png

This simple combination of a complex pole pair and a zero at the origin is a simulation of any simple resonant system in nature. The log plot shows a very narrow spike, but lower down 6dB per octave slopes on each side. Note that a voltage ratio of 0.03 is about -30dB, and that is where the 6dB per octave slopes start:

p2nblog.png

If you wanted to make a filter with several such narrow peaks at widely separated frequencies, a single filter would not be the best way to go. It would be better to feed the input simultaneously into separate filters and add the outputs.

complex lowpass filter

We show an elliptical filter. The normalized pole-zero plot shows 5 poles and 4 zeroes:

eliptpln.png

We plot the elliptic filter where the filter bandwidth is one tenth the simulation bandwidth. The solid line is the simulated filter using isolated poles and zeroes in series, and the dotted line is the ideal transfer function:

elipt.png

step response

Thus far we have only discussed the frequency domain behavior of filters. Time domain behavior is also important. Suppose a lowpass filter has no input signal, then suddenly a step function signal is applied that rises instantly to a constant value. The time required for the output to rise to the constant value is called the rise time. The rise time is approximately equal to the reciprocal of the bandwidth measured from negative to positive frequencies, or half the reciprocal of the bandwith measured from zero to positive frequencies. Similarly, if a bandpass filter has a steady sinewave suddenly applied in the frequency range of the passband, the risetime of the envelope of the output sinewave will be approximately the reciprocal of the bandwidth.

The next two examples show two pole lowpass filters normalized to unity gain at zero frequency that both have 40dB/decade slopes that pass through -40dB at a frequency of 1E4. Each tic on the complex plane is 1E3. Each pole is a distance of 1E3 from the origin. The input step function has zero imaginary part. The real part of the output is a solid line, the imaginary part is a dashed line. Because the pole/zero plots are symmetrical about the real axis, the output has zero imaginary part. The imaginary part could be discarded to make a stream of real numbers. First, poles at 63 degrees from the imaginary axis:

pln63.png

The corresponding time domain step response:

stp63.png

Next, poles at 12 degrees from the imaginary axis:

pln12.png

The corresponding time domain step response:

stp12.png

how to prevent numerical problems

The order that data is fed through the poles and zeroes would not matter with infinite precision arithmetic, but it does with finite precision. Two poles in series does not cause numerical problems, but two zeroes in series does. There are never more zeroes than poles in a realizable filter. It is possible to arrange that there are never two zeroes in series. There will always be a pole after each zero. This is necessary to avoid noise from roundoff error with finite precision arithmetic. This can be illustrated by the step response for the elliptic filter shown above, but with center frequency zero and bandwidth of 2E3. The computations are done with 32 bit floating point variables. First, an example with data fed through all the poles, then all the zeroes:

stpbd.png

Next, with a pole after each zero:

stpgd.png

The code used in my Oberon-2 program to feed the data through the poles and zeroes in series in such a way as to insert a pole after every zero is shown here. fr.n is the number of poles; fr.nz is the number of zeroes. pzxk is the input and pzyk is the output.

PROCEDURE pzfltr*(t:REAL;pzxk:cx.complex;
VAR pzyk:cx.complex; VAR fr:fltrrec);
(*feed data through poles and zeroes in series*)
VAR k:LONGINT;tempxk:cx.complex;
BEGIN
tempxk:=pzxk;
FOR k:=1 TO fr.n DO
IF k < fr.nz+1 THEN
fr.z[k].xk:=tempxk;zero(t,fr.f1,fr.z[k]); 
tempxk:=fr.z[k].yk;END(*IF*);
fr.p[k].xk:=tempxk;pole(t,fr.f1,fr.p[k]);
tempxk:=fr.p[k].yk;
END(*FOR*);
pzyk:=tempxk;END pzfltr;

effects of simulation bandwidth

One kind of multipole filter is the bessel filter, with maximally flat group delay in the passband, for minimal distortion of the shape of a pulse. Most kinds of filters have pole/zero patterns that must be calculated with complex mathematical formulas. But the most common multipole filter is the butterworth filter which has a pattern defined by a simple geometrical arrangement. The Butterworth lowpass filter has maximally flat amplitude response in the passband. However many poles there are, they are evenly spaced on a semicircle in the left half plane. The point where the semicircle intersects the vertical axis is where the filter is 3dB down. Here is a normalized pole-zero plot of a butterworth filter with 4 poles.

btwpln.png

Next we look at the effect of simulation bandwidth. The simulation bandwidth extends to plus and minus half the sample frequency. Half the sample frequency is also called the Nyquist frequency. We start with a four pole butterworth filter centered at zero Hz with a bandwidth of 2E4, one tenth of the total simulation bandwidth:

btw4.png

We look at the same four pole butterworth filter with half the original simulation bandwidth:

btw4h.png

We end our bandwidth investigation by showing the same filter at one fourth the original simulation bandwidth:

btw4q.png

Some people have suggested ways to make digital filters that do not suffer so much distortion with limited simulation bandwidth. This may miss the point. If your simulation bandwidth is no wider than the bandwidth of the filter, why do you need a filter in the simulation?

transformation to highpass, bandpass, bandstop

Next we show how to transform from a lowpass prototype to highpass, bandpass and stopband filters. The transformations work the same way for lowpass prototypes that are all pole, and for those with both poles and zeroes. We start with a three pole butterworth lowpass filter.

LOW PASS PROTOTYPE

Pole pattern:

lppln.png

Linear frequency response:

lplin.png

Log frequency response:

lplog.png

HIGH PASS FILTER

Next, we apply the lowpass to highpass transformation to the preceding example to produce the corresponding highpass filter. Since our lowpass prototype is butterworth, the pole pattern is unchanged. The butterworth pattern is a special case in this regard because all the poles are equally distant from the origin. Any other type of filter would have pole positions altered by the transformation.

Pole-zero plot:

hppln.png

Linear frequency response:

hplin.png

Log frequency response:

hplog.png

The lowpass to highpass transformation requires a prototype that is symmetrical about the real axis. An additional restriction is that there are no zeroes at the origin. There will automatically be no poles at the origin since poles must have a negative real part. Choose a reflection frequency, a real number, typically the 3dB point of a lowpass prototype filter. The square of the reflection frequency divided by the complex location of each pole or zero in the lowpass prototype is the new location after the transformation. The number of new zeroes to be created at the origin is the number of poles less the number of zeroes in the original lowpass prototype.

BAND PASS FILTER

Next we transform our lowpass prototype to a bandpass filter. The lowpass version centered at zero frequency is symmetrical in a linear plot. The bandpass version would not be symmetrical in a linear plot, but is in a log frequency plot, except for errors near the Nyquist frequency, the upper limit of the simulation. If the bandwidth is very small compared with the center frequency, there is very little difference between the shape of a linear plot and a log plot, but if not, the difference can be large. Notice that the original lowpass pole pattern is not merely shifted, but also distorted.

Pole/zero plot:

bppln.png

Linear frequency response:

bplin.png

Log frequency response:

bplog.png

The lowpass to bandpass transformation is simple. The version of the transformation given here preserves the bandwidth from the negative frequency limit to the positive frequency limit, not from zero to the positive frequency limit. Start with the "lowpass prototype", which does not need to be a lowpass filter, it only needs to be symmetrical about the real axis on the complex plane. The number of poles should be equal to or greater than the number of zeroes. The difference between the number of poles and the number of zeroes will be the number of zeroes at the origin after the transformation. If the location of a pole or zero in the prototype is "a", the corresponding pair of locations after the transformation is "b". The geometrical mean frequency of the bandpass filter is "c", a real number.

lp2bp.png

There is only one right answer for the square root of a positive real number, but there is more than one right answer for the square root of a complex number. Unfortunately, only one of them will work in this application. The form of complex square root needed is the form having the principal root from zero to pi, not the form having the principal root from zero to plus or minus half pi. Thus the square root of 0-j1 on the negative imaginary axis should be -0.707+j0.707, in the upper left hand quadrant. Having created a pair of poles or a pair of zeroes for each original pole or zero, add the appropriate number of zeroes at the origin as previously noted. When making bandpass filters that will appear narrow in a log frequency plot, "c" will be greater than the bandwidth of the prototype. When making filters that will appear broad in a log frequency plot, the bandwidth of the prototype is greater than "c". The transformation works equally well for all relative sizes of center frequency and bandwidth.

BAND STOP FILTER

The two transformations given above can be combined to make the lowpass to bandstop transformation. One must be careful to move the unity gain normalization frequency away from the stop band. Zero frequency is a good choice. Applying the lowpass to bandpass transformation to the highpass pole-zero pattern shown previously results in the following stop band example. Notice that the width of the 3dB points on the stopband is the same as the width of the 3dB points on the passband of the original lowpass prototype.

First, the pole pattern. There are three overlapping zeroes in both places where one zero is shown. The program used to plot these figures could only indicate the number of overlapping zeroes in the case of zeroes at the origin.

sbpln.png

Linear frequency response:

sblin.png

Log frequency response:

sblog.png

properties of poles and zeroes

Before looking at other complex examples, we should look at the properties of the poles and zeroes themselves. Remember that these simulations are of necessity circular functions and must match at the right and left edges of the simulation. First we show a pole at real -5E3 and imaginary 4E4:

p44r.png

The solid curve is the FFT measurement of the simulated pole, and the dashed curve is the transfer function of the actual pole, both normalized to unity gain at the frequency of the pole. The pole is at 4E4. The opposite side of the frequency circle is -6E4, where the simulated pole has flared out, but the actual pole is still monotonically decreasing. Near the frequency of the pole the simulation is quite accurate. On the opposite side of the frequency circle the simulation is not very accurate. The simulation is a good approximation for only about half the frequency circle. If we keep the poles and zeroes and our region of interest near the center of the simulation errors will be negligible. High sample rates widen the outer edges of the simulation and push the opposite side of the frequency circle far from the poles and zeroes.

The transfer function of a pole at a point on the complex plane is the reciprocal of the transfer function of a zero at the same point on the complex plane. Similarly, the gain function of a simulated pole at a point on the complex plane is the reciprocal of the gain function of a simulated zero at the same point on the complex plane, except for a constant vertical shift in dB. Therefore the errors of the simulated zero will be identical to the errors of the simulated pole shown above.

The gain functions of poles and zeroes are used to produce the solid curves in the log frequency plots in this article. Therefore it is of interest to see how accurately the gain functions match the FFT measurements of the simulated poles and zeroes. The simulated poles and zeroes shown are shown here with a solid line and the theoretical gain functions are shown in dashed lines. The dashed lines cannot be seen because the theoretical gain functions exactly overlap the FFT plots of the pole and zero functions. The theoretical gain functions are not to be confused with the ideal transfer functions, which are shown in the other plots in this article. The theoretical gain functions only predict the behavior of the simulated poles and zeros, whereas the transfer functions give the behavior of the actual poles and zeroes in a real filter, not a simulated filter. To start with we show a single pole with a real frequency component of -5E3 and a positive imaginary frequency component of 4E4 :

p44.png

Next, a single pole at -5E1, 4E4, :

p42.png

Now a zero at -5E1 and 4E4:

z42.png

In order for a filter to be physically realizable in hardware any complex poles and zeroes must appear in conjugate pairs at equal positive and negative imaginary frequencies. Only that way will a real signal in result in a real signal out, with zero imaginary parts. In the computer, however, we can simulate unrealizable filters with only positive or only negative imaginary frequency components. Now we make an unrealizable notch filter with only positive frequency poles and zeroes by combining the first pole example with the zero example. The notch filter is normalized to unity gain on the opposite side of the frequency circle from the notch. Both the simulated notch and the transfer function are plotted, but the transfer function overlaps the simulation and is invisible:

notch.png

Presumably the close match between the simulation and the actual transfer function is because the errors of the pole and zero are nearly equal and opposite in sign, and nearly cancel out.

The notch example previously shown was unrealizable because it did not have conjugate poles and zeroes. To create a realizable version, we move the same notch to zero frequency, then use a lowpass to bandpass transformation to move it to 1E4. First the normalized pole-zero pattern:

bpnchpln.png

Notice that each pole and the corresponding zero are no longer at the same imaginary frequency in this version, whereas they were in the previous version. Next a log frequency plot:

bpnchlog.png

Since the simulated pole and the simulated zero are both approximations and not exact, it is of interest to see how well they match. To see this the pole at -5E1, 4E4 is plotted with the zero at -5E1, 4E4 as a notch filter normalized as before. They match so well that the plot is a straight line as it should be:

strt.png

use of complex phasors

Now to examine the use of this technique for baseband simulation of narrowband filters centered at high frequencies. Filters such as this are used in radio receivers at the intermediate frequency (I.F.) of the receiver. The technique presented here is used to reduce the simulation bandwidth that would otherwise be required. Complex phasors are used in the data stream. Negative frequencies in the simulation represent positive frequencies in the real world that are below the center frequency of the narrowband filter. The real filter has poles at both positive and negative frequencies but the simulated filter represents only the positive poles in the real filter by means of the lowpass prototype centered at zero. This produces a distortion in the simulated response that we will now investigate. We show a four pole butterworth filter with bandwidth of 2E4 centered at zero in the simulation. We also plot the transfer function of a real filter with various I.F. frequencies. The I.F. frequency will be at zero frequency in the plot, and zero frequency in the real world will be offset to negative frequencies in the plot. The match between overlapping plots would be worse with fewer poles and better with more poles. First, an I.F. frequency of 3E4:

if3.png

Next we make the I.F. frequency 2E5, ten times the filter bandwidth:

if10.png

Finally, we make the I.F. frequency 2E6, 100 times the filter bandwidth:

if100.png

up one level