Lecture 5 - Digital Filters

5.1 Digital filtering

Digital filtering can be implemented either in hardware or software; in the first case, the numerical processor is either a special-purpose chip or it is assembled out of a set of digital integrated circuits which provide the essential building blocks of a digital filtering operation – storage, delay, addition/subtraction and multiplica- tion by constants. On the other hand, a general-purpose mini-or micro-computer can also be programmed as a digital filter, in which case the numerical processor is the computer’s CPU and memory. Filtering may be applied to which are then transformed back to the analogue domain using a digital to analogue convertor or worked with entirely in the digital domain (e.g. biomedical signals are digitised, filtered and analysed to detect some abnormal activity).

5.1.1 Reasons for using a digital rather than an analogue filter

The numerical processor can easily be (re-)programmed to implement a number of different filters.

The accuracy of a digital filter is dependent only on the round-off error in the arithmetic. This has two advantages: – the accuracy is predictable and hence the performance of the digital processing algorithm is known a priori. – The round-off error can be minimized with appropriate design tech- niques and hence digital filters can meet very tight specifications on magnitude and phase characteristics (which would be almost impossi- ble to achieve with analogue filters because of component tolerances and circuit noise).

59 The widespread use of mini- and micro-computers in engineering has greatly increased the number of digital signals recorded and processed. Power sup- ply and temperature variations have no effect on a programme stored in a computer.

Digital circuits have a much higher noise immunity than analogue circuits.

5.1.2 The sampling process

This is performed by an analogue to digital converter (ADC) in which the contin- ¡©¨

uous function ¡£¢¥¤§¦ is replaced by a “discrete function” , which is defined only 

at ¤  , with . We thence only need consider the digitised sample  set ¡£¨ and the sample interval .

Aliasing

¡£¢¥¤§¦ ! #"¢$ %'& ¦ ¡£¢¥¤§¦)! #"*¢,+-$%.& ¦ ( Consider ( (one cycle every 4 samples) and also (3 cycles every 4 samples) as shown in Fig. 5.1. Note that the resultant samples are the same. This result is referred to as aliasing. The most popular solution to this problem is to precede the digital filter by an analogue low-pass filter to ensure that any frequency above 0/#0 Hz is adequately suppressed. (This LPF is known as an “anti-aliasing” filter and is shown to the left of the A/D converter

on the block diagram of page 46). Without an anti-aliasing filter, 1 23/4 Hz at the 156#/4 output could have been produced either by 152#/4 Hz or Hz at the input.

With the anti-aliasing filter, any signal at 7186#/0 Hz will be suppressed prior to 1 23/4 A/D conversion, i.e. 1 23/4 coming out must represent going in. Since we cannot build perfect anti-aliasing filters, however, digital filters will normally have their passband well below 0/4 Hz.

5.1.3 Reconstruction of output waveform The data at the output of the D/A converter must be interpolated in order to re- construct the filtered signal. Usually this takes the form of step or one-point inter- polation (in which the value at the sample time is assumed to be the value of the function until the next sample time), followed by analogue low-pass filtering as shown in Fig. 5.2. The output low-pass filter is sometimes known as a recovery filter.

60 1

0.5

0

−0.5

−1 0 10 20 30 40 50 60 70 80 90 100

1

0.5

0

−0.5

−1 0 10 20 30 40 50 60 70 80 90 100

Figure 5.1: Aliasing.

5.2 Introduction to the principles of digital filtering

We can see that the numerical processing is at the heart of the digital filtering process. How can the arithmetic manipulation of a sequence of numbers produce a “filtered” version of that sequence? Consider the noisy signal of figure 5.3, together with its sampled version: One way to reduce the noise might be to try and smooth the data. For example, we could try a polynomial fit using a least-squares criterion. If we choose, say, to fit a parabola to every group of 5 points in the sequence, then, for every point, we will make a parabolic approximation to that point using the value of the sample at that point together with the values of the 4 nearest samples (this forms a parabolic

filter), as in Fig. 5.4

%

%

¨ :);<>=? @;BAC=? ;

9

¨ DFEHGI GJK#K L

where 9 = value of parabola at each of the 5 possible values of % and ;<*;BAK; are the variables used to fit each of the parabolae to 5 input data points.

61 samples DAC

LPF

Figure 5.2: Reconstruction using a DAC and LPF.

-2 -1 0 1 2

Figure 5.3: Noisy data.

%

;BA ; We obtain a fit by finding a parabola (coefficients ;< , and ) which best

approximates the 5 data points as measured by the least-squares error E:

%

% %

P

% %

¢N;<K;A,K; ¦O ¢¥T>¨ UGV¨;<>=? @;BAC=? ; W¦

M

% QKR:S

Minimizing the least-squares error gives:

X X X

M M M

Y7 Z7 Y

%

X X X

;BA ; ;< and

and thus:

%

QKR

P

%

T>¨ ;<©=\*3; 

[

%

QKR:S

%

Q]R

P

*3;BA£ T>¨

% QKR:S

62 parabolic fit

-2 -1 0 1 2 centre point, k=0

Figure 5.4: Parabolic fit.

%

QKR

%

P

%

*3;<>=^2B_H;  T>¨ H

% Q]R:S

which therefore gives:



¢`Ga24T>¨bGa4 =V00T>¨bGc! =\064T>¨dB =V*4T>¨be fGg2BT>¨4 ¥¦ ;<

2

[



;BAh ¢`GI4T>¨iGa4 UGjT>¨bGc! 7=kT>¨b! H=?4T>¨4 W¦

*



%

;  ¢N4T>¨iGI0 UGjT>¨bGc! UGg4T>¨dB UGlT>¨i! 7=^4T>¨ 0 ¥¦ _

The centre point of the parabola is given by:

%

%

¨ Om =^ @;BAn=^ ; m <Z;*<

9

QKR QKR

Thus, the parabola coefficient ;< given above is the output sequence number calculated from a set of 5 input sequences points. The output sequence so ob- tained is similar to the input sequence, but with less noise (i.e. low-pass filtered) because the parabolic filtering provides a smoothed approximation to each set of five data points in the sequence. Fig. 5.5 shows this filtering effect. The magni- tude response (which we will re-consider later) for the 5-point parabolic filter is shown below in Fig. 5.6. The filter which has just been described is an example of a non- recursive dig- ital filter, which are defined by the following relationship (known as a difference

63 1.5

1

0.5

0

−0.5 0 10 20 30 40 50 60 70 80 90 100

Figure 5.5: Noisy data (thin line) and 5-point parabolic filtered (thick line).

1

0.8

0.6 f / 2 samp |H(z)| 0.4

0.2

0 0 100 200 300 400 500 600 700 f

Figure 5.6: of 5-point parabolic filter.

equation):

r

P r

¨ p q T>¨ uGkvw

o

R r

where the coefficients determine the filter characteristics. The difference equa- s

tion for the 5-point filter, therefore, is:



¨ p ¢xGy2BT>¨ J=^4 =\04T>¨ c=\! =\064T>¨ 7=V00T>¨ uGz! fGj2BT>¨ {G|4 W¦

o

2

[ ¨

This is a non-causal filter since a given output value o depends not only on T>¨ }=k!

previous inputs, but also on the current input T>¨ , the input and the input

T>¨ ~={4 ¨ . The problem is solved by delaying the calculation of the output value o

(the centre point of the parabola) until all the 5 input values have been sampled  (i.e. a delay of 4 where = sampling period), ie:

64



¨ : ¢`Ga2BT>¨ 7=\04T>¨ {Gze =V060T>¨ uGg4 H=V04T>¨ {Gk2B fGg2BT>¨ {Gj_ W¦

o

2

[

r

¨ H € T>¨ ‚Gƒvw

It is of importance to note that the equation o represents s a discrete convolution of the input data with the filter coefficients; hence these coefficients constitute the of the filter.

Proof:

r

r

T>¨ „ l T>¢ 3¦c† ¨ H t‡€ T>¨ ‚G?vw 

Let , except at , where . Then o

s

T>¢ 3¦ va‡ T>¢ 3¦Jˆ Q

Q (all terms zero except when ). This is equal to since .

s s

¢ 3¦I < ¢`0¦a A 11!1 o

Therefore o ; ; etc . As there is a finite number of ’s, the

s s s impulse response is finite. For this reason, non-recursive filters are also called Finite-Impulse Response (FIR) filters.

As we will see, we may also formulate a digital filter as a recursive filter; in ¨

which, the output o is also a function of previous outputs:

r r

P r P r

¨ p T>¨ {Gkvw H= Š ¨ uGjv

q

o o

<‰s A£‹

R R

Before we can describe methods for the design of both types of filter, we need

to review the concept of the Π-transform.

5.3 The  -transform

The Π-transform is important in digital filtering because it describes the sampling process and plays a role in the digital domain similar to that of the Laplace trans-

form in analogue filtering.

S Q

( ¤J‡ 

The Laplace transform of a unit impulse occurring at time is Ž .

Consider the discrete function ¡£¨ H to be a succession of impulses, for example

¤c„ ¡£¢`0¦ ¤c 111 of area ¡£¢ 3¦ occurring at , occurring at , etc . The Laplace

transform of the whole sequence would be:

%

S S S Q

( ( (

¢w;0¦tZ¡£¢w#¦C=?¡£¢`0¦ =^¡£¢N¦ =V1!11*=^¡£¨ H

>‘

Ž Ž Ž

The suffix ’ denotes the transform of the discrete sequence, not of the continuous ¡£¢¥¤§¦ .

65

(

¢N;0¦ ¢ ¦

“‘ 

Œ Œ

Let us replace Ž by a new variable , and rename as :

%

A

S S Q S

=?¡£¢w#¦ =\111]¡£¨ H ¢ ¦hZ¡£¢w3¦C=^¡£¢x*¦



Œ Œ Œ Œ

For many functions, the infinite series canA be represented in “closed form”, in S

general as the ratio of two polynomials in Π.

5.3.1 Examples of the z-transform

¡©¨ •”? ¡£¨ ‚– 

step function = 0 for , = 1 for

%

A

S S S Q

¢ ¦hF‰= = =\111*= =V11!1



Œ Œ Œ Œ



¢ ¦h



A

S

'G

Œ Œ

by summation of a geometric progression6.

Decaying exponential

S — S —*Q

(

&

¡£¢¥¤§¦t G:˜ ¡£¨ H :

Ž Ž

% %

A

S — S S — S S —*Q S Q

( ( (

¢ ¦tF= = =V111*= =V111



Œ Ž Œ Ž Œ Ž Œ



¢ ¦h



A

S — S

(

'G

Œ

Ž Œ

Sinewaves

Q§› S Q§›

( (

G

¡£¢¥¤§¦hV! "f™h¤‰G:˜ ¡©¨ :\! #"p 3™h\

ŽKš Ž š



  

¢ ¦h ¢ = ¦



A A

› S S › S

( (

 'G 'G

Œ

Ž Œ Ž Œ

š š

A

S

'Gke #"™h

¢ ¦h

 Œ

%

A

S S

'G|£! "7™h =

Œ

Œ Œ

6

strictly valid only if œK4ž3Ÿ£œ ¢¡

66

5.3.2 The Pulse Œ

This is the name for ( Π-transform of output)/( -transform of input).

r

¤c„ A

Let the impulse response, for example of an FIR filter, be < at , at

s s

¤O\ 111 ¤OVv  v>Y

, at with to £ .

s

¢ ¦

r

Œ Œ

Let ¤ be the -transform of this sequence:

r

%

A

%

S S S S

¢ ¦t <£= A = =\111= =V1!11

¤ Œ Œ Œ Œ Œ

q

s s s s s

q

¢ ¦ Œ

Let ¥ be an input:

%

A

S S S Q

¢ ¦h\T>¨dB 7=kT>¨b! =gT>¨4 =\1110=kT>¨ =V1!11

¥ Œ Œ Œ Œ

¢ ¦ ¢ ¦

r

Œ ¥ Œ

The product ¤ is:

r

A A

S S S S S Q

¢ ¦ ¢ ¦t¦¢ <£= A =\111 =V11!1 ¦!¢¥T>¨4 7=gT>¨i! =V1!11§T>¨ ¦

Œ ¥ Œ Œ Œ Œ Œ ¤ Œ

q

s s s s

q S Q

in which the coefficient of Πis:

r

<]T>¨ 7= A`T>¨ uGz! =\111 T>¨ uGkvw H=V111 T>¨ §G

£

s s s s

q 

This is nothing else than the value of the output sample at ¤^ . Hence

¢ ¦ ¢ ¦•

¨ Œ ¨ Œ

the whole sequence is the Π-transform of the output, say , where

¢ ¦ ¢ ¦ ¢ ¦

¤ Œ Œ Œ ¥ Œ ¤ . Hence the pulse transfer function, , is the -transform of the impulse response.

For non-recursive filters:

r

r

P r

S

¢ ¦t

q

¤ Œ Œ

s

< R

For recursive filters:

r r

r r

P r P r

S S

¢ ¦t ¢ ¦C= ¢ ¦

Š

q

¨ Œ Œ ¥ Œ Œ ¨ Œ

s ‹

< A

R R

r

r

r

S

¢ ¦

€

r

 ¢ ¦h

Œ ¨ Œ

s

S

¢ ¦ 'G|€

¤ Œ

¥ Œ Œ ‹

67

5.3.3 © -plane pole-zero plot

ª(

  ;IV«¬=®­™ Ž

Let Π, where = sampling period. Since , we have:

›

( (



š

Œ Ž¯ Ž

›

(

«°Z m md±  Ve #"™h²=¢­‰"§³µ´™h

š

Œ Ž If , then and Œ , i.e. the equation of

a circle of unit radius (the unit circle) in the Œ -plane. «?

Thus, the imaginary axis in the ; -plane ( ) maps onto the unit circle in

; «Y”

the Π-plane and the left half of the -plane ( ) onto the interior of the unit

circle.

¢N;0¦ ;

We know that all the poles of ¤ must be in the left half of the -plane for a continuous filter to be stable. We can therefore state the equivalent rule for

stability in the Π-plane:

For stability all poles in the Π-plane must be inside the unit circle.

5.4 Frequency response of a digital filter

This can be obtained by evaluating the (pulse) transfer function on the unit circle

›

(

 ŽKš ( i.e. Œ ).

Proof

Consider the general filter

r

P r

¨ p ¶ T>¨ uGkvw

o

NB: A recursive type can always be expressed as an infinite sum by dividing out:

r

<

P r

 ¨ : <1 T>¨ {Gkvw ¢ ¦‰

A

A

o

s

S

}G A Œ

eg., for ¤ we have

s ‹

<

Œ

R

‹

e #"0¢¥™h¤=•·#¦ ¤hV¸'1!11C 

Let input before samplingA be , sampled at . Therefore

›BQ S ›BQ

(º@»`¼ (º@»`¼

T>¨ :Ze #"*¢W™ g=|·#¦O %#E = L

ŽKšK¹ Ž š¹

r5¿ r5¿

r r

 

r r

P P

› ¾ QeS S › ¾ QeS

(º@»xÀ (º@»xÀ

¨ U =

¶ ¶

o

š]½ š]½

  Ž

ie. Ž

<‰s

R R

68

r r

r r

 

P r P r

›BQ S › S ›BQ ›

( ( (º@»`¼ (º@»`¼

= 

¶ ¶

šK¹ š šK¹ š

 

Ž Ž Ž Ž

s s

< <

R R

r r

r r

P r P r

› S S ›

( (

 ¢ ¦

¶ ¶

š š Ž

Now Ž

R R

r

r

P r

S

¢ ¦ ¶

Œ Œ

But ¤ for this filter is

<‰s

R

r

r

P r

› S ›

( (

 ¢ ¦`Á ¶

š š

¤ Œ Ž

and so Ž

<‰s

S

›

(

¢ ¦xÁ \Â

š šxÃ

Œ Ž Ž Let ¤ .

Then r

r

P r

› S

(

¶ ZÂ

š š§Ã Ž

Ž (complex conjugate)

<s

R

A A

›BQ S ›BQ S

(º@»`¼ (º@»`¼

¨ H : Â = Â

% %

o

ŽKš§Ã Ž š¹ Ž šxÃ

Hence ŽKš¹

¨ pVÂÄ! #"¢¥™ j=^·'=^ÅƦ T>¨ ÆVe #"0¢W™ k=|·#¦

or o when ŠThus  and represent the gain and phase of the frequency response. i.e. the

frequency response (as a complex quantity) is

¢ ¦*m

Á

R@ÇWȪÉeÊ

¤ Œ

Example

Consider the 5-point parabolic filter.



¨ : ¢`Ga2BT>¨ 7=\04T>¨ {Gze =V060T>¨ uGg4 H=V04T>¨ {Gk2B fGg2BT>¨ {Gj_ W¦

o

2 [

hence

%



A

S S S SHË

+

¢ ¦t ¢xGy2}=V0 =\06 =V0 Gg2 ¦ ¢ ¦

2

¨ Œ Œ Œ Œ Œ ¥ Œ [

69

thus

%



S › S › S › SHË ›

( ( ( (

+

¢ ¦  ¢`Ga2}=\0 =V*6 =V0 Gk2 ¦

Á

R@ÇµÈ É,Ê

š š š š

2

¤ Œ Ž Ž Ž Ž

[

%



› S ›

( (

¢ ¦O ¢`06'=?B_he #"7™hƒGjÌhe #"p0™ha¦

š š

2

¤ Ž Ž

[



›

(

m506=?4_te #"™h^GkÌO! #"p0™h§m m ¢ ¦*mB

š

2

¤ Ž

Therefore [

›

(

™hzY7m ¢ ¦0mBÍ ŽKš

When ¤

›

(

m ¢ ¦*mBY15636 ™hƒÎ)1_3ÏBÐ Y15B_

ŽKš Ñ

and ¤ when , i.e.

›

(

¢ ¦tFGI0™h

Ó

ÑNÒ

¤ ŽKš i.e. (true for any FIR filter with palindromic coefficients); all fre- quencies delayed by 4 (as expected!)

70