Digital Signal Processing Tutorials
Digital Signal Processing Tutorials
What is DSP?
DSP, or Digital Signal Processing, as the term suggests, is the processing of signals by digital
means. A signal in this context can mean a number of different things. Historically the
origins of signal processing are in electrical engineering, and a signal here means an electrical
signal carried by a wire or telephone line, or perhaps by a radio wave. More generally,
however, a signal is a stream of information representing anything from stock prices to data
from a remote-sensing satellite. The term "digital" comes from "digit", meaning a number
(you count with your fingers - your digits), so "digital" literally means numerical; the French
word for digital is numerique. A digital signal consists of a stream of numbers, usually (but
not necessarily) in binary form. The processing of a digital signal is done by performing
numerical calculations.
In many cases, the signal of interest is initially in the form of an analog electrical voltage or
current, produced for example by a microphone or some other type of transducer. In some
situations, such as the output from the readout system of a CD (compact disc) player, the data
is already in digital form. An analog signal must be converted into digital form before DSP
techniques can be applied. An analog electrical voltage signal, for example, can be digitised
using an electronic circuit called an analog-to-digital converter or ADC. This generates a
digital output as a stream of binary numbers whose values represent the electrical voltage
input to the device at each sampling instant.
Signal processing
Signals commonly need to be processed in a variety of ways. For example, the output signal
from a transducer may well be contaminated with unwanted electrical "noise". The electrodes
attached to a patient's chest when an ECG is taken measure tiny electrical voltage changes
due to the activity of the heart and other muscles. The signal is often strongly affected by
"mains pickup" due to electrical interference from the mains supply. Processing the signal
using a filter circuit can remove or at least reduce the unwanted part of the signal.
Increasingly nowadays, the filtering of signals to improve signal quality or to extract
important information is done by DSP techniques rather than by analog electronics.
Development of DSP
The development of digital signal processing dates from the 1960's with the use of mainframe
digital computers for number-crunching applications such as the Fast Fourier Transform
(FFT), which allows the frequency spectrum of a signal to be computed rapidly. These
techniques were not widely used at that time, because suitable computing equipment was
generally available only in universities and other scientific research institutions.
Digital Signal Processors (DSPs)
The introduction of the microprocessor in the late 1970's and early 1980's made it possible for
DSP techniques to be used in a much wider range of applications. However, general-purpose
microprocessors such as the Intel x86 family are not ideally suited to the numerically-
intensive requirements of DSP, and during the 1980's the increasing importance of DSP led
several major electronics manufacturers (such as Texas Instruments, Analog Devices and
Motorola) to develop Digital Signal Processor chips - specialised microprocessors with
architectures designed specifically for the types of operations required in digital signal
processing. (Note that the acronym DSP can variously mean Digital Signal Processing, the
term used for a wide range of techniques for processing signals digitally, or Digital Signal
Processor, a specialised type of microprocessor chip). Like a general-purpose
microprocessor, a DSP is a programmable device, with its own native instruction code. DSP
chips are capable of carrying out millions of floating point operations per second, and like
their better-known general-purpose cousins, faster and more powerful versions are
continually being introduced. DSPs can also be embedded within complex "system-on-chip"
devices, often containing both analog and digital circuitry.
Applications of DSP
Although some of the mathematical theory underlying DSP techniques, such as Fourier and
Hilbert Transforms, digital filter design and signal compression, can be fairly complex, the
numerical operations required actually to implement these techniques are very simple,
consisting mainly of operations that could be done on a cheap four-function calculator. The
architecture of a DSP chip is designed to carry out such operations incredibly fast, processing
hundreds of millions of samples every second, to provide real-time performance: that is, the
ability to process a signal "live" as it is sampled and then output the processed signal, for
example to a loudspeaker or video display. All of the practical examples of DSP applications
mentioned earlier, such as hard disc drives and mobile phones, demand real-time operation.
The major electronics manufacturers have invested heavily in DSP technology. Because they
now find application in mass-market products, DSP chips account for a substantial proportion
of the world market for electronic devices. Sales amount to billions of dollars annually, and
seem likely to continue to increase rapidly.
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.
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.
The following list gives some of the main advantages of digital over analog filters.
Fast DSP processors can handle complex combinations of filters in parallel or cascade
(series), making the hardware requirements relatively simple and compact in comparison with
the equivalent analog circuitry.
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
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
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
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.
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.
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.
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
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.
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).
6. 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:
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
... etc
The order of a digital filter can be defined as the number of previous inputs (stored in the
processor's memory) used to calculate the current output.
Example (1): yn = xn
This is a zero order filter, since the current output yn depends only on the current input
xn and not on any previous inputs.
Example (2): yn = Kxn
The order of this filter is again zero, since no previous outputs are required to give the
current output value.
Example (3): yn = xn-1
This is a first order filter, as one previous input (xn-1) is required to calculate yn. (Note
that this filter is classed as first-order because it uses one previous input, even though
the current input is not used).
Example (4): yn = xn - xn-1
This is again a first order filter, since one previous input value is required to give the
current output.
Example (5): yn = (xn + xn-1) / 2
The order of this filter is again equal to 1 since it uses just one previous input value.
Example (6): yn = (xn + xn-1 + xn-2) / 3
To compute the current output yn, two previous inputs (xn-1 and xn-2) are needed; this is
therefore a second-order filter.
Example (7): yn = (xn - xn-2) / 2
The filter order is again 2, since the processor must store two previous inputs in order
to compute the current output. This is unaffected by the absence of an explicit xn-1
term in the filter expression.
The order of a digital filter may be any positive integer. A zero-order filter (such as those in
examples (1) and (2) above) is possible, but somewhat trivial, since it does not really filter the
input signal in the accepted sense.
All of the digital filter examples given in the previous section can be written in the following
general forms:
The constants a0, a1, a2, ... appearing in these Example Order a0 a1 a2
expressions are called the filter coefficients. The
values of these coefficients determine the 1 0 1 - -
characteristics of a particular filter.
2 0 K - -
The table opposite gives the values of the 3 1 0 1 -
coefficients of each of the filters given as
examples in the previous section. 4 1 1 -1 -
1 1
5 1 /2 /2 -
1 1 1
6 2 /3 /3 /3
1
7 2 /2 0 -1/2
Self-assessment question
SAQ 1
For each of the following filters, state the order of the filter and identify the values of
its coefficients:
(b) yn = xn-2
(c) yn = xn - 2xn-1 + 2xn-2 + xn-3
Answers to SAQ 1
1. Order = 1: a0 = 2, a1 = -1
2. Order = 2: a0 = 0, a1 = 0, a2 = 1
3. Order = 3: a0 = 1, a1 = -2, a2 = 2, a3 = 1
The impulse response of a digital filter is the output sequence from the
filter when a unit impulse is applied at its input. (A unit impulse is a
very simple input sequence consisting of a single value of 1 at time t =
0, followed by zeros at all subsequent sampling instants). An FIR filter
is one whose impulse response is of finite duration. An IIR filter is one
whose impulse response (theoretically) continues for ever, because the
recursive (previous output) terms feed back energy into the filter input
and keep it going. The term IIR is not very accurate, because the actual
impulse responses of nearly all IIR filters reduce virtually to zero in a
finite time. Nevertheless, these two terms are widely used.
yn = xn + yn-1
In other words, this filter determines the current output (yn) by adding the current input (xn) to
the previous output (yn-1).
Thus:
y0 = x0 + y-1
y1 = x1 + y0
y2 = x2 + y1
y3 = x3 + y2
... etc
Note that y-1 (like x-1) is undefined, and is usually taken to be zero.
Let us consider the effect of this filter in more detail. If in each of the above expressions we
substitute for yn-1 the value given by the previous expression, we get the following:
y0 = x0 + y-1 = x0
y1 = x1 + y0 = x1 + x0
y2 = x2 + y1 = x2 + x1 + x0
y3 = x3 + y2 = x3 + x2 + x1 + x0
... etc
Thus we can see that yn, the output at t = nh, is equal to the sum of the current input xn and all
the previous inputs. This filter therefore sums or integrates the input values, and so has a
similar effect to an analog integrator circuit.
This example demonstrates an important and useful feature of recursive filters: the economy
with which the output values are calculated, as compared with the equivalent non-recursive
filter. In this example, each output is determined simply by adding two numbers together.
For instance, to calculate the output at time t = 10h, the recursive filter uses the expression
y10 = x10 + y9
To achieve the same effect with a non-recursive filter (i.e. without using previous output
values stored in memory) would entail using the expression
y10 = x10 + x9 + x8 + x7 + x6 + x5 + x4 + x3 + x2 + x1 + x0
This would necessitate many more addition operations, as well as the storage of many more
values in memory.
The order of a digital filter was defined earlier as the number of previous inputs which have
to be stored in order to generate a given output. This definition is appropriate for non-
recursive (FIR) filters, which use only the current and previous inputs to compute the current
output. In the case of recursive filters, the definition can be extended as follows:
The order of a recursive filter is the largest number of previous input or output
values required to compute the current output.
This definition can be regarded as being quite general: it applies both to FIR and IIR filters.
For example, the recursive filter discussed above, given by the expression
yn = xn + yn-1
is classed as being of first order, because it uses one previous output value (yn-1), even though
no previous inputs are required.
In practice, recursive filters usually require the same number of previous inputs and outputs.
Thus, a first-order recursive filter generally requires one previous input (xn-1) and one
previous output (yn-1), while a second-order recursive filter makes use of two previous inputs
(xn-1 and xn-2) and two previous outputs (yn-1 and yn-2); and so on, for higher orders.
Note that a recursive (IIR) filter must, by definition, be of at least first order; a zero-order
recursive filter is an impossibility. (Why?)
Self-assessment question
SAQ 2
Answers to SAQ 2
a. Order = 1
b. Order = 3
c. Order = 2
From the above discussion, we can see that a recursive filter is basically like a non-recursive
filter, with the addition of extra terms involving previous outputs (yn-1, yn-2 etc.).
Note the convention that the coefficients of the inputs (the x's) are denoted by a's, while the
coefficients of the outputs (the y's) are denoted by b's.
Self-assessment question
SAQ 3
Identify the values of the filter coefficients for the first-order recursive filter
yn = xn + yn-1
discussed earlier.
Answers to SAQ 3
a0 = 1 a1 = 0
b0 = 1 b1= -1
a.
a0 = 2 a1 = -1
b0 = 1 b1 = -1
c.
a0 = 0 a1 = 1 a2 = 0 a3 = -1
b0 = 1 b1 = 2 b2 = 0 b3 = 0
e.
a0 = 1 a1 = 2 a2 = 1
b0 = 1 b1 = 2 b2 = -1
In the last section, we used two different ways of expressing the action of a digital filter: a
form giving the output yn directly, and a "symmetrical" form with all the output terms (y's) on
one side and all the input terms (x's) on the other.
In this section, we introduce what is called the transfer function of a digital filter. This is
obtained from the symmetrical form of the filter expression, and it allows us to describe a
filter by means of a convenient, compact expression. Tthe transfer function of a filter can be
used to determine many of the characteristics of the filter, such as its frequency response.
First of all, we must introduce the unit delay operator, denoted by the symbol
z-1
When applied to a sequence of digital values, this operator gives the previous value in the
sequence. It therefore in effect introduces a delay of one sampling interval.
Applying the operator z-1 to an input value (say xn) gives the previous input (xn-1):
z-1 xn = xn-1
x0 = 5
x1 = -2
x2 = 0
x3 = 7
x4 = 10
Then
z-1 x1 = x0 = 5
z-1 x2 = x1 = -2
z-1 x3 = x2 = 0
and so on. Note that z-1 x0 would be x-1 which is unknown (and usually taken to be zero, as we
have already seen).
Similarly, applying the z-1 operator to an output gives the previous output:
z-1 yn = yn-1
Applying the delay operator z-1 twice produces a delay of two sampling intervals:
z-2 xn = xn-2
This notation can be extended to delays of three or more sampling intervals, the appropriate
power of z-1 being used.
Let us now use this notation in the description of a recursive digital filter. Consider, for
example, a general second-order filter, given in its symmetrical form by the expression
yn-1 = z-1 yn
yn-2 = z-2 yn
xn-1 = z-1 xn
xn-2 = z-2 xn
Rearranging this to give a direct relationship between the output and input for the filter, we
get
This is the general form of the transfer function for a second-order recursive (IIR) filter.
For a first-order filter, the terms in z-2 are omitted. For filters of order higher than 2, further
terms involving higher powers ofz-1 are added to both the numerator and denominator of the
transfer function.
A non-recursive (FIR) filter has a simpler transfer function which does not contain any
denominator terms. The coefficient b0 is regarded as being equal to 1, and all the other b
coefficients are zero. The transfer function of a second-order FIR filter can therefore be
expressed in the general form
yn / xn = a0 + a1z-1 + a2z-2
2. The general form of the transfer function for a first-order recursive filter can be
written
yn = xn + yn-1
which we discussed earlier. To derive the transfer function for this filter, we rewrite
the filter expression using the z-1 operator:
(1 - z-1) yn = xn
yn / xn = 1 / (1 - z-1)
Collecting output terms on the left and input terms on the right to give the
"symmetrical" form of the filter expression, we get
Self-assessment question
SAQ 4
Answers to SAQ 4
a. yn / xn = (2 - z-1) / (1 - z-1)
Tutorial question
x0 = 5
x1 = 16
x2 = 8
x3 = -3
x4 = 0
x5 = 2
Tutorial: Answers