Analog and digital filters
In signal processing, the function of a filter is to remove unwanted parts of the signal, such as random noise, or to extract useful parts of the signal, such as the components lying within a certain frequency range.
The following block diagram illustrates the basic idea.
There are two main kinds of filter, analog and digital. They are quite different in their physical makeup and in how they work.
An analog filter uses analog electronic circuits made up from components such as resistors, capacitors and op amps to produce the required filtering effect. Such filter circuits are widely used in such applications as noise reduction, video signal enhancement, graphic equalisers in hi-fi systems, and many other areas.
There are well-established standard techniques for designing an analog filter circuit for a given requirement. At all stages, the signal being filtered is an electrical voltage or current which is the direct analogue of the physical quantity (e.g. a sound or video signal or transducer output) involved.
A digital filter uses a digital processor to perform numerical calculations on sampled values of the signal. The processor may be a general-purpose computer such as a PC, or a specialised DSP (Digital Signal Processor) chip.
The analog input signal must first be sampled and digitised using an ADC (analog to digital converter). The resulting binary numbers, representing successive sampled values of the input signal, are transferred to the processor, which carries out numerical calculations on them. These calculations typically involve multiplying the input values by constants and adding the products together. If necessary, the results of these calculations, which now represent sampled values of the filtered signal, are output through a DAC (digital to analog converter) to convert the signal back to analog form.
Note that in a digital filter, the signal is represented by a sequence of numbers, rather than a voltage or current.
The following diagram shows the basic setup of such a system.
Advantages of digital filters
The following list gives some of the main advantages of digital over analog filters.
A digital filter is programmable, i.e. its operation is determined by a program stored in the processor's memory. This means the digital filter can easily be changed without affecting the circuitry (hardware). An analog filter can only be changed by redesigning the filter circuit.
Digital filters are easily designed, tested and implemented on a general-purpose computer or workstation.
The characteristics of analog filter circuits (particularly those containing active components) are subject to drift and are dependent on temperature. Digital filters do not suffer from these problems, and so are extremely stable with respect both to time and temperature.
Unlike their analog counterparts, digital filters can handle low frequency signals accurately. As the speed of DSP technology continues to increase, digital filters are being applied to high frequency signals in the RF (radio frequency) domain, which in the past was the exclusive preserve of analog technology.
Digital filters are very much more versatile in their ability to process signals in a variety of ways; this includes the ability of some types of digital filter to adapt to changes in the characteristics of the signal.
Operation of digital filters
In the next few sections, we will develop the basic theory of the operation of digital filters. This is essential to an understanding of how digital filters are designed and used. First of all, we need to introduce a basic notation.
Suppose the "raw" signal which is to be digitally filtered is in the form of a voltage waveform described by the function
V = x (t)
where t is time.
This signal is sampled at time intervals h (the sampling interval). The sampled value at time t = ih is
xi = x (ih)
Thus the digital values transferred from the ADC to the processor can be represented by the sequence
x0, x1, x2, x3, ...
corresponding to the values of the signal waveform at times t = 0, h, 2h, 3h, ... (where t = 0 is the instant at which sampling begins).
At time t = nh (where n is some positive integer), the values available to the processor, stored in memory, are
x0, x1, x2, x3, ... , xn
Note that the sampled values xn+1, xn+2 etc. are not available as they haven't happened yet!
The digital output from the processor to the DAC consists of the sequence of values
y0, y1, y2, y3, ... , yn
In general, the value of yn is calculated from the values x0, x1, x2, x3, ... , xn. The way in which the y's are calculated from the x's determines the filtering action of the digital filter.
In the next section, we will look at some examples of simple digital filters.
Examples of simple digital filters
The following examples illustrate the essential features of digital filters.
UNITY GAIN FILTER: yn = xn
Each output value yn is exactly the same as the corresponding input value xn:
y0 = x0
y1 = x1
y2 = x2
... etc
This is a trivial case in which the filter has no effect on the signal.
SIMPLE GAIN FILTER: yn = Kxn (K = constant)
This simply applies a gain factor K to each input value:
y0 = Kx0
y1 = Kx1
y2 = Kx2
... etc
K > 1 makes the filter an amplifier, while 0 < K < 1 makes it an attenuator. K < 0 corresponds to an inverting amplifier. Example (1) above is the special case where K = 1.
PURE DELAY FILTER: yn = xn-1
The output value at time t = nh is simply the input at time t = (n-1)h, i.e. the signal is delayed by time h:
y0 = x-1
y1 = x0
y2 = x1
y3 = x2
... etc
Note that as sampling is assumed to commence at t = 0, the input value x-1 at t = -h is undefined. It is usual to take this (and any other values of x prior to t = 0) as zero.
TWO-TERM DIFFERENCE FILTER: yn = xn - xn-1
The output value at t = nh is equal to the difference between the current input xn and the previous input xn-1:
y0 = x0 - x-1
y1 = x1 - x0
y2 = x2 - x1
y3 = x3 - x2
... etc
i.e. the output is the change in the input over the most recent sampling interval h. The effect of this filter is similar to that of an analog differentiator circuit.
TWO-TERM AVERAGE FILTER: yn = (xn + xn-1) / 2
The output is the average (arithmetic mean) of the current and previous input:
y0 = (x0 + x-1) / 2
y1 = (x1 + x0) / 2
y2 = (x2 + x1) / 2
y3 = (x3 + x2) / 2
... etc
This is a simple type of low pass filter as it tends to smooth out high-frequency variations in a signal. (We will look at more effective low pass filter designs later).
THREE-TERM AVERAGE FILTER: yn = (xn + xn-1 + xn-2) / 3
This is similar to the previous example, with the average being taken of the current and two previous inputs:
y0 = (x0 + x-1 + x-2) / 3
y1 = (x1 + x0 + x-1) / 3
y2 = (x2 + x1 + x0) / 3
y3 = (x3 + x2 + x1) / 3
... etc
As before, x-1 and x-2 are taken to be zero.
CENTRAL DIFFERENCE FILTER: yn = (xn - xn-2) / 2
This is similar in its effect to example (4). The output is equal to half the change in the input signal over the previous two sampling intervals:
y0 = (x0 - x-2) / 2
y1 = (x1 - x-1) / 2
y2 = (x2 - x0) / 2
y3 = (x3 - x1) / 2