The Digital Solution
The Digital Solution
general, the most recently ar- tant in aJl kinds of digital cir-
rived current has the biggest 10 REM *** FIR DIGITAL FILTER *** cuit. The precision of a digital
20 DIM X(100). A(100)
effect. To produce an eq uiva- 30 CLS:INPUT"Number Qf taps";T value is usually ±1 bit, so the
lent effect, we must weight 40 INPUT"Number Qf ~amples";N precision with which a value
the coefficients so that aO is 50 PRINT"Select waveform" is represented digitally de-
60 PRINT TAB(10) "1 Sque r-e
the largest and a5 is the 70 PRINT TAB (10) "2 Sawtooth
pends on its magnitude. Val-
smal1est. This modi fies the 80 PRINT TAB (10) "3 Tr-Lang Le " uee in the region of 60 000
moving average calculation, 90 PRINT TAB (10) "4 Sine" have aprecision of 0.0015%,
but the effect is still that of a 100 PRINT TAB(10)"5 Pulse" but values in the region of 100
110 INPUT"Key 1 to 5";W
lew-pass filter. It is the nature 120 INPUT"Period"; P
(with 7 bits) have a precision
of the weighting that largely 130 FOR J=O Ta T-l of only 0.01%. For optimum
determines the exact shape of 140 PRINT"Coeffici!'mt "jJ::INPUT"= ";A(J) precision, registers should be
150 NEXT used near their full capacity,
the filter's response curve and
160 FOR SAMPLE=O TO N STEP 1
the type of phase changes it 170 XS=SAMPLE Mon p provided that they do not be-
exhibits. Later we shall look 180 ON W GOTO 190, 220, 230. 250. 260 come over-full. Usually, the
at other patterns ofweighting. 190 XS=SGNCXS-P/2) most significant digit of a reg-
200 X=O: IF XS=)O THEN X=255
210 GOTO 270
ister that is filled beyond its
Filter action 220 X=INT(XS*255/P):GOTO 270 full capacity changes from 1 to
230 X=INT(XS*255/P):IF X)127 THEN X=255-X 0, with a dramatic fall in the
Ta see how the filer operates, 240 GOTO 270 value stored. This would seri-
250 X=INT«SIN(XS*6.283/P»*127+127l:GOTO 270
here is a numerical example. 260 X=O:IF SAMPLE<=P THEN X=255 ously upset the action of the
The filter in Fig. 51 has six 270 FOR J=T-l TO 1 STEP -1 filter. Many DSPs have regis-
taps and its output at any in- 280 X(J)=X(J-1) ters that minimize the error
290 NEXT
stant is represented by th is by making the register fill
300 X(O)=INT(X)
equation 310 Y=O with ls when there is over-
Yn = aQXO + alxn_l + a2oXn-2 320 FOR J=O TO T-1 flow. The error passes along
330 Y=INT (Y+X (J) oJ!'A (J» the chain and is eventual1y
+agXn_3 + a4xn-4 + aSXn-5'
340 NEXT
Suppose that seven consecu- 350 PRINT X; Yj" "-, lost (not so in another filter
tive sarnples, in order of ar- 360 NEXT type yet to be described). Sim-
rival at the input, are 11, 13, 940120--1-52
ilarly, if a register underflows,
15, 17, 14, 12, and 10. Sup- it is made to hold all Os. This
pose also that the coefficients Fig.53 feature could be added to the
are 0.3, 0.25, 0.2, 0.15, 0.1, BASIC program.
and 0.05. When the first six The results of filtering a
sampIes have arrived, the out- sine wave are shown in
put is Fig. 54. The program was set
0.3x12 + 0.25x14 + 0.2x17 to provide three taps with co-
+0.15x15 + 0.lx13 +0.05x11 efficients aO = 0.25, al = 0.5,
= 14.6. and a2 = 0.25. The period of
Note that the [irst sampIe to the sine wave is 40 samples.
arrive is now in register 5; the The magnitude of the coeffi-
sarnples are in the reverse of eients affects the 'gain' of the
50
their order of arrivaL An in- sampies
filter; for a 'gain' of 1, the coef-
940120-7-53
stant later, the seventh sam- ficients should total about 1.
ple (10) arrives, and the The graph shows a transient
others are shifted along the Fig.54. response for the first three
chain. The first sam pie (11) is sam ples as they are shifted
lost. Now the output is through to occupy both taps.
0.3x10 +0.25x12 + 0.2x14 From then on, the filtered
XlV
+0.15x17 +0.lx15 waveform is a sine wave of the
+ 0.05x13 = 13.5. 200 same frequency and almost
Between the 6th and 7th sam- the same amplitude as the
pIes, the input signal falls by 100 input signal. There is a very
2. The output falls by 1.1. The slight phase delay of one sam-
I
filter is smoothing out the sig- o pling period. In a real digital
nal, as required in a lew-pass filter in which the sampling
20
r' filter.
940120-7-54
sampies rate is higher in comparison
We could continue to ana- with the signal frequency, this
lyse tbe filter in this way but, delay is negligible. Note that
obviously, operating a pencil - Fig.55. in this filter we have allocated
aud-paper digital filter is a the middle tap the largest co-
lengthy business. A simple efficient, and that aO and a2
BASIC pro gram gives results of BASIC. The program allows 127, so they are equivalent to are equa l. This symmetrical
more quickJy. the user to decide on the num- having 8-bit registers in the pattern of coefficients has the
ber of taps, the number of fil ter. Actual filters usua11y effect of giving the filter a lin-
BASICsimulation samples, the waveform, the have 16-bit registers, giving a ear phase response, a charac-
period (the number of samples precision of 1 in 65536 or teristic of Bessel filters in the
Figure 53 lists a GWBASIC per cycle of the waveform or 0.0015%, provided that the analogue world. Unfortu-
program that simulates digi- the length of the single pulse), amplitude of the waveform is nately, this advantageous fea-
tal filters of the type ilIus- and the coefficients for each sufficiently great to almost ture of analogue Bessel filters
trated in Fig. 51. It is easily tap. The waveforms a11have saturate the registers. Inci- is counter-bal anced by their
converted into other dialects an amplitude and offset of dentally, this factor is impor- poor roll-off. With digital fil-
100 I x __
y--
"
rt
as an infinite impulse re-
eponse or UR filter. For a
given number of taps, an IrR
filter has a faster roll-off at
the extremes of the passband,
50
is a sine wave of the same fre- sampies
which is an advantage. Hcw-
queney, lagging ODe sampIe 94ü120-7-55 ever, in contrast with an IFR
period behind the input, as filter, which is always stable,
before. But the amplitude of Fig.56. an UR filter may become un-
the output is less than that in stable in certain circum-
the previous example, indicat- stances. This is because the
ing that the filter is behaving IIR filter has an element of
as a low-pass filter. With more feedback in its action and,
taps, the effeet would be 200 where there is feedback, there
greater. is always the possibility of the
The low-pass action is more system going into permanent
apparent in Fig. 56 in which oscil1ation. For this reason,
a single pulse is filtered. In IIR filters need much more
50
this example, the filter has 11 sarnptes
careful design.
taps with coefficients 0.19, The FIR and UR filters are
0.17. 0.15, 0.13, 0.11, 0.09, the two basic configurations of
-200
0.07, 0.05, 0.03, 0.01 and 950120-7-56
digital filters, but it is posible
0.005. The 'exponential' rise to combine both types. The
and fall at the beginning and simplest of these is a filter in
end of the pulse are indicative which the output from each
of a lew-pass filter. By COD- Fig.57. register 1S summed and se nt
trast, Fig. 57 shows behav- to the filter output, as in an
iour associated with a high- FIR filter and, at the same
pass filter. Analogue high- time, the output of each regis-
pass filters are differentiators, ter is also fed back to the
so we might expect to use dir- input side as in an JIR filter. It
ferences between successive is possible to cascade these fil-
samples to represent rate of ters or connect them in paral-
change and thus produce a lel to give filters of higher
high-pass filter. Figure 57 was order. There are very many
produced with a 5-tap filter ways in which filters can be
with coefficients 0.1, 0.25. 0.4, built, leading to a wide range
-0.25, and 0.1. Typical up- of responses that can be engi-
ward and downward spikes neered. The digital filter is a
occur at the beginning and 940120-7-57 flexible device and is capable
end of each pulse of this of realizing filter functions
square wave. that are not possible with
The mathematics of digital Fig.58 analogue filters.
filters 1Shighly involved and We have shown that digital
any discussion of this is not filters may be implemented in
appropriate to this series. The several diferent ways. The
'D[ j[ j[
coefficients for the foregoing BASIC program is one such
examples were arrived at by way which, though quick
intuition rather than by calcu- enough as a demonstration, is
lation. But enough has been not fast enough to filter, say,
said to illustrate the pr-inci- an audio signal. Increased
ples behind digital filtering. o j I j j
speed is obtained by program-
The reader is left to investi- '.
21
5 ming the computer in ma-
gate further, using the BASIC chine code, but this falls short
'Ir j[ j[ J
program. of the speed that can be
achieved with a dedicated
Another digital filter digital signal processor. Multi-
plication is an essential stage
The filter described above is in filter ing and, on a micro-
know as a finite impulse re- o ' , processor acts as a bettle-
'-.'2 -, 21.
sponse or FIR filter. Each sam- IM0120-7-5&o.b neck. It takes a microproces-
ple is considered to be an im- sor several machine cycles to
pulse. Eacb sam pie passes perform a multiphcation. In
along the row of taps and is Fig.59. contrast, DSPs have multi pli-
eventually lost. Thus, each cation circuits built in, and
impulse exerts its effect for a can multiply in a single cycle.
finite nurnber of sample peri- value in each tap, multip1ied side, to be summed with the A DSP, such as one of the
ods. Figure 58 shows a differ- by the corresponding coeffi- products from subsequent Texas TMS320C5x series, op-
ent type of digital filter. The cient, is fed back to the input sampIes. Each sample, multi- erating as a 50-tap filter, can
accept and filter signals at result is that the lew-pass fil- spaee. No matter how precise logue filters need eomplete
frequencies up to 250 kHz. In ter passes all the lower fre- the eomponents in an ana- rewiring to effect such a
contrast, a typical micropro- quencies that can be heard (ta logue filter, they introduce change. The ability to pro-
cessor, working at 33 MHz the left of the dashed line) parasitic capacitance and in- gram the filter by changing
and programmed as a 50-tap and also higher frequencies ductance into the circuit with the eoeffieients opens up the
filter, can filter signals with atha t can not be heard. In consequent distortion. Trim- possibility of altering the re-
maximum frequeney of only Fig. 58b, the pass-bands are mers to adjust the eapaei- sponse of the filter while it is
25 kHz. shifted up the frequeney spec- tances and inductanees are running. This means that the
trum. The band within the often required in preeision filter ean be altered to suit the
range of interest provides a analogue filters, adding more signal that it is eurrently re-
Frequency response eeiving. Filters of this type
high-pass function. Suitably to cost and board space.
It is a consequence of the located combs of bands can Even when an analogue fil- are known as adaptive filters.
mathematics that the fre- provide band-pass and band- ter has been built from high- The incoming signal is moni-
queney response of digital fil- stop filters. precision eomponents and tored and the eoeffieients al-
ters is repeated at multiples earefully trimmed, its behav- tered accordingly. Taking all
of the sampl ing frequency. The digital solution iour is subject to changes in these points intc considera-
Whether a filter is considered eomponent values resulting tion, it is not surprising that
to be low-pass, high-pass, Digital filters operate by cal- from age or temperature. Di- the digital solution has been
band-pass or band-stop de- culating and produee an out- gital filters work precisely ac- so widely adopted.
pends on the relationship be- put to any reasonably re- cording to the response de-
tween the location of the mul- quired level of precision. In signed into them and are en- Reference: Craig, Marvin and
tiple pass-bands in the fre- addition, filters of widely dif- tirely stable. This is a re- Ewers, Gillian: A simple ap-
queney spectrum. In Fig. 59a, fering characteristics can all minder that it is possible to proach to digital signal pro-
the first pass-band extends be realized with a general- program a digital filter with cessing; Texas Instruments,
from zero frequeney (0) to a purpose DSP device. There is frequency and phase re- 1993.
value less than fs/2, where fs no need of high-precision (and sponses that are just not pos-
is the sampling frequency. The expensive) resistors, capaei- sible with analogue tech-
band is repeated at {" 2 {" tors (possibly ganged), induc- niques. Test yourself
The sampling frequency is tors or op amps as there is for Finally, there is the advan- The I1Rfilter in Fig. 58 has co-
chosen so that it 1S at least an analogue filter. There is no tage that the response of a efficients ao == 0.2, a1 == 0.4,
double the frequency of any need for special layouts on the digital filter can be altered, and a2 = 0.2. A single ramp
signal that is of interest. This peB. Discrete components, possibly quite drastically, pulse is fed into it, having
is why, in digital audio, for particularly inductors, are rel- simply by changing the values values 2, 4, 6, 8, 10. Find the
whicb 20 kHz is the highest atively bulky and take circuit- of the eoefficients. A few small output of the filter for 10 con-
frequency that the human ear board space. A digital filter is changes in the coefficients can secutive sample times, round-
can detect, the sampling fre- built from minute deviees on a even change a low-pass filter ing to four decimal places.
quency is at least 40 kHz. The silicon chip and takes up little into a high-pass filter. Ana- [940120-VIl]