12
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 signals 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 signal 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

Documentl5

Embed Size (px)

DESCRIPTION

l5

Citation preview

Page 1: Documentl5

Lecture5 - Digital Filters

5.1 Digital filtering

Digital filtering canbe implementedeither in hardwareor software; in the firstcase,thenumericalprocessoriseitheraspecial-purposechipor it is assembledoutof asetof digital integratedcircuitswhichprovidetheessentialbuilding blocksofa digital filtering operation– storage,delay, addition/subtractionandmultiplica-tion by constants.On theotherhand,a general-purposemini-or micro-computercanalsobeprogrammedasa digital filter, in which casethenumericalprocessoris thecomputer’sCPUandmemory.

Filtering may be appliedto signalswhich are then transformedback to theanaloguedomainusingadigital to analogueconvertoror workedwith entirelyinthedigital domain(e.g. biomedicalsignalsaredigitised,filteredandanalysedtodetectsomeabnormalactivity).

5.1.1 Reasonsfor usinga digital rather than an analoguefilter� The numericalprocessorcan easily be (re-)programmedto implementanumberof differentfilters.� Theaccuracy of a digital filter is dependentonly on the round-off error inthearithmetic.Thishastwo advantages:

– the accuracy is predictableandhencethe performanceof the digitalsignalprocessingalgorithmis known a priori .

– The round-off error canbe minimizedwith appropriatedesigntech-niquesandhencedigital filters canmeetvery tight specificationsonmagnitudeandphasecharacteristics(whichwouldbealmostimpossi-ble to achieve with analoguefilters becauseof componenttolerancesandcircuit noise).

59

Page 2: Documentl5

� Thewidespreaduseof mini- andmicro-computersin engineeringhasgreatlyincreasedthenumberof digital signalsrecordedandprocessed.Powersup-ply andtemperaturevariationshave no effect on a programmestoredin acomputer.� Digital circuitshaveamuchhighernoiseimmunity thananaloguecircuits.

5.1.2 The samplingprocess

This is performedby ananalogueto digital converter(ADC) in whichthecontin-uousfunction

�������is replacedby a“discretefunction”

��� �, whichis definedonly

at���� �

, with������������

. We thenceonly needconsiderthedigitisedsampleset

���� �andthesampleinterval

�.

Aliasing

Consider�����������! #"���$ %'&( � (onecycle every 4 samples)andalso

���������)�! #"*�,+-$%.&( �(3 cyclesevery 4 samples)asshown in Fig. 5.1. Note that theresultantsamplesare the same. This result is referredto asaliasing. The mostpopularsolutionto this problemis to precedethe digital filter by an analogue low-passfilter toensurethat any frequency above

�0/#�0�Hz is adequatelysuppressed.(This LPF

is known asan“anti-aliasing”filter andis shown to theleft of theA/D converteron theblockdiagramof page46). Without ananti-aliasingfilter,

��1�23/4�Hz at the

outputcould have beenproducedeitherby��152#/4�

Hz or��156#/4�

Hz at the input.With the anti-aliasingfilter, any signalat

�7186#/0�Hz will be suppressedprior to

A/D conversion,i.e.��1�23/4�

comingout mustrepresent��1�23/4�

goingin. Sincewecannotbuild perfectanti-aliasingfilters,however, digital filterswill normallyhavetheirpassbandwell below

�0/��4�Hz.

5.1.3 Reconstructionof output waveform

The dataat the outputof the D/A convertermustbe interpolatedin orderto re-constructthefilteredsignal.Usuallythis takestheform of stepor one-pointinter-polation(in which thevalueat thesampletime is assumedto bethevalueof thefunctionuntil the next sampletime), followedby analoguelow-passfiltering asshown in Fig. 5.2. Theoutputlow-passfilter is sometimesknown asa recoveryfilter.

60

Page 3: Documentl5

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−1

−0.5

0

0.5

1

Figure5.1: Aliasing.

5.2 Intr oduction to the principles of digital filtering

We canseethat the numericalprocessingis at the heartof the digital filteringprocess.How canthearithmeticmanipulationof a sequenceof numbersproducea “filtered” versionof that sequence?Considerthe noisy signal of figure 5.3,togetherwith its sampledversion:

Onewayto reducethenoisemightbeto try andsmooththedata.For example,wecouldtry a polynomialfit usinga least-squarescriterion. If wechoose,say, tofit aparabolato everygroupof 5 pointsin thesequence,then,for everypoint,wewill makeaparabolicapproximationto thatpointusingthevalueof thesampleatthatpoint togetherwith thevaluesof the4 nearestsamples(thisformsaparabolicfilter), asin Fig. 5.4

9 �� �:�);�<>=?@;BAC=? % ; %where9 �� � = valueof parabolaateachof the5possiblevaluesof

D�FEHGI� ��GJ���K�����#�K� Land

;�<*��;BA��K; %are the variablesusedto fit eachof the parabolaeto 5 input data

points.

61

Page 4: Documentl5

samples

DAC

LPF

Figure5.2: Reconstructionusinga DAC andLPF.

-2 -1 0 1 2

Figure5.3: Noisydata.

We obtaina fit by finding a parabola(coefficients;�<

,;BA

and; %

) which bestapproximatesthe5 datapointsasmeasuredby theleast-squareserrorE:

M �N;�<��K;�A,�K; % �O� %PQKR:S % ��T>�� �UGV��;�<>=?@;BAC=?% ; % �W� %

Minimizing theleast-squareserrorgives:X MX ;�< �Y�7� X MX ;BA �Z�7�and

X MX ; % �Y�andthus:

[ ;�<=\�*�3; % � QKR %PQKR:S % T>�� �

�*�3;BA�� Q]R %PQKR:S % T>�� �62

Page 5: Documentl5

-2 -1 0 1 2

parabolic fit

centre point, k=0

Figure5.4: Parabolicfit.

�*�3;�<>=^2B_H; % � QKR %PQ]R:S % % T>��H�

which thereforegives:

;�<�� �2 [ �`Ga24T>�bGa�4��=V�0�0T>�bGc�!� =\�064T>�d�B� =V�*�4T>�b�e�fGg2BT>���4���;BAh� ��*� �`GI�4T>�iGa�4�UGjT>�bGc�!�7=kT>�b�!�H=?�4T>���4�W�

; % � ���_ �N�4T>�iGI�0�UGjT>�bGc�!�UGg�4T>�d�B�UGlT>�i�!�7=^�4T>���0���Thecentrepointof theparabolais givenby:

9 �� �Om QKR <K�Y;*<>=^@;BAn=^ % ; % m QKR <��Z;*<Thus,theparabolacoefficient

;�<givenabove is theoutputsequencenumber

calculatedfrom a setof 5 input sequencespoints. The outputsequenceso ob-tainedis similar to theinput sequence,but with lessnoise(i.e. low-passfiltered)becausetheparabolicfiltering providesa smoothedapproximationto eachsetoffive datapointsin thesequence.Fig. 5.5 shows this filtering effect. Themagni-tuderesponse(which we will re-considerlater) for the5-pointparabolicfilter isshown below in Fig. 5.6.

Thefilter whichhasjustbeendescribedis anexampleof anon-recursivedig-ital filter, which aredefinedby thefollowing relationship(known asa difference

63

Page 6: Documentl5

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

0

0.5

1

1.5

Figure5.5: Noisydata(thin line) and5-pointparabolicfiltered(thick line).

0 100 200 300 400 500 600 7000

0.2

0.4

0.6

0.8

1

f

|H(z

)| fsamp

/ 2

Figure5.6: Frequencyresponseof 5-pointparabolicfilter.

equation):

o �� �p� qP r R <tsr T>��uGkvw�

wherethe srcoefficientsdeterminethefilter characteristics.Thedifferenceequa-

tion for the5-pointsmoothingfilter, therefore,is:

o �� �p� �2 [ �xGy2BT>��J=^�4� =\�0�4T>��c=\�!� =\�064T>�� �7=V�0�0T>��uGz�!�fGj2BT>��{G|�4�W�This is a non-causalfilter sincea given outputvalue o �� � dependsnot only onpreviousinputs,but alsoonthecurrentinput

T>�� �, theinput

T>��}=k�!�andtheinputT>��~={�4�

. Theproblemis solvedby delayingthecalculationof theoutputvalueo �� �(thecentrepoint of the parabola)until all the 5 input valueshave beensampled(i.e. adelayof

�4�where

�= samplingperiod),ie:

64

Page 7: Documentl5

o �� �:� �2 [ �`Ga2BT>�� �7=\�0�4T>��{Gz�e� =V�060T>��uGg�4�H=V�0�4T>��{Gk2B�fGg2BT>��{Gj_��W�It is of importanceto notethat the equationo ��H����� s

r T>���G�vw�represents

a discreteconvolution of the input datawith the filter coefficients; hencethesecoefficientsconstitutethe impulseresponseof thefilter.

Proof:

LetT>�� �����

, exceptatl���

, whereT>���3�c���

. Then o ��H�t��� rsr T>���G?vw���

s Q T>���3� (all termszeroexceptwhenva��

). This is equalto s Q sinceT>���3�J���

.Thereforeo ���3�I� s < ; o �`�0�a� s A ; etc

1�1!1. As thereis a finite numberof s ’s, the

impulseresponseis finite. For this reason,non-recursive filters arealsocalledFinite-Impulse Response(FIR) filters.

As we will see,we mayalsoformulatea digital filter asa recursive filter; inwhich,theoutput o �� � is alsoa functionof previousoutputs:

o �� �p� qP r R <�sr T>��{Gkvw�H= �P r R A��

r o ��uGjv��Beforewecandescribemethodsfor thedesignof bothtypesof filter, weneed

to review theconceptof the � -transform.

5.3 The � -transform

The � -transformis importantin digital filtering becauseit describesthesamplingprocessandplaysa role in thedigital domainsimilar to thatof theLaplacetrans-form in analoguefiltering.

TheLaplacetransformof a unit impulseoccurringat time�J�� �

is � S Q (�� .Considerthe discretefunction

����H�to be a successionof impulses,for example

of area�����3�

occurringat�c���

,���`�0�

occurringat�c���

, etc1�1�1

. TheLaplacetransformof thewholesequencewouldbe:�>� �w;0�t�Z���w�#�C=?���`�0� � S (�� =^���N��� � S % (�� =V1!1�1*=^����H� � S Q (��Thesuffix � denotesthetransformof thediscretesequence,notof thecontinuous�������

.

65

Page 8: Documentl5

Let usreplace� (�� by anew variable� , andrename��� �N;0�

as� � � � :� � � �h�Z���w�3�C=^���x�*� � S A =?���w�#� � S % =\1�1�1]����H� � S Q

For many functions,theinfinite seriescanberepresentedin “closedform”, ingeneralastheratioof two polynomialsin � S A .5.3.1 Examplesof the z-transform� stepfunction

��� �= 0 for

��?�,���� �

= 1 for����

� � � �h�F��= � S A = � S % =\1�1�1*= � S Q =V1�1!1� � � �h� ��'G � S A

by summationof ageometricprogression6.� Decayingexponential�������t� � S � & G:� ����H�:� � S �*Q (� � � �t�F��= � S � ( � S A = � S � % ( � S % =V1�1�1*= � S �*Q ( � S Q =V1�1�1

� � � �h� ��'G � S � ( � S A� Sinewaves

�������h�V�! �"f�h��G:� ��� �:�\�! #"p3�h�\� �K� Q�� ( G � S � Q�� (�� � � �h� �� � ��'G � � � ( � S A =

��'G � S � � ( � S A �� � � �h� �'Gk�e #"��h� � S A�'G|���! �"7�h� � S A = � S %

6strictly valid only if �K�4�3���� ¢¡66

Page 9: Documentl5

5.3.2 The PulseTransfer Function

This is thenamefor ( � -transformof output)/(� -transformof input).Let the impulseresponse,for exampleof anFIR filter, be s < at

�c���, s A at�O�\�

,1�1�1 s

rat�O�Vv��

withv>�Y�

to £ .Let ¤ � � � bethe � -transformof thissequence:

¤ � � �t� s <�= s A � S A = s % � S% =\1�1�1�= s

r� Sr=V1!1�1 s q � S q

Let ¥ � � � beaninput:

¥ � � �h�\T>�d�B�7=kT>�b�!� � S A =gT>���4� � S % =\1�1�10=kT>�� � � S Q =V1!1�1Theproduct¤ � � � ¥ � � � is:

¤ � � � ¥ � � �t�¦� s <�= s A � S A =\1�1�1 sr� Sr=V1�1!1 s q � S q �!��T>���4�7=gT>�i�!� � S

A =V1!1�1�T>�� � � S Q �in which thecoefficientof � S Q is:

s <]T>�� �7= s A`T>��uGz�!� =\1�1�1 sr T>��uGkvw�H=V1�1�1 s q T>��§G £ �

This is nothing else than the value of the output sampleat�^� �

. Hencethe whole sequenceis the � -transformof the output,say ¨ � � � , where ¨ � � ���¤ � � � ¥ � � � . Hencethe pulsetransferfunction, ¤ � � � , is the � -transformof theimpulseresponse.

For non-recursivefilters:

¤ � � �t� qP r R < sr� Sr

For recursivefilters:

¨ � � �t� qP r R < sr� Sr¥ � � �C= �P r R A �

r� Sr¨ � � �

¤ � � �h� ¨ � � �¥ � � � �� s

r� Sr

�'G|� �r� Sr

67

Page 10: Documentl5

5.3.3 © -planepole-zero plot

Let � � � �ª( , where�

= samplingperiod.Since;I�V«¬=®­��

, we have:

� � ��¯ ( � � � (If«°�Z�

, thenm � md�±�

and � � � � � ( �V�e #"��h�²=¢­�"�³µ´��h� , i.e. theequationofacircleof unit radius(theunit circle) in the � -plane.

Thus,the imaginaryaxis in the;-plane(

«?���) mapsonto theunit circle in

the � -planeandthe left half of the;-plane(

«Y���) onto the interior of the unit

circle.We know that all the polesof ¤ �N;0� must be in the left half of the

;-plane

for a continuousfilter to bestable.We canthereforestatetheequivalentrule forstability in the � -plane:

For stability all polesin the � -planemust be inside the unit circle.

5.4 Frequencyresponseof a digital filter

This canbeobtainedby evaluatingthe(pulse)transferfunctionon theunit circle( i.e. � � �K� � ( ).

ProofConsiderthegeneralfilter

o �� �p� ¶P r R <tsr T>��uGkvw�

NB: A recursive typecanalwaysbeexpressedasaninfinite sumby dividing out:

eg., for ¤ � � ��� s <�}G � A � S A�

wehave o �� �:� ¶P r R < s <�1 �rA T>��{Gkvw�

Let inputbeforesamplingbe�e #"0���h��=�·#�

, sampledat�h�V���¸�'��1!1�1C�� �

. ThereforeT>�� �:�Z�e #"*�W�� �g=|·#�O� A%#E �K�K¹ �BQ (�º@»`¼ = � S ��¹ �BQ (�º@»`¼ Lie.o �� �U� �� ¶P r R <�s

r� �]½ � ¾ QeS

r5¿ (�º@»xÀ = �� ¶P r R <tsr� S �]½ � ¾ QeS

r5¿ (�º@»xÀ

68

Page 11: Documentl5

� �� � �K¹ �BQ (�º@»`¼ ¶P r R < sr� S � �

r ( = �� � S �K¹ �BQ (�º@»`¼ ¶P r R < sr� � �r (

Now¶P r R <ts

r� S � �

r ( � ¶P r R <tsr � � � � ( � S

r

But¤ � � � for thisfilter is¶P r R <�s

r� Sr

andso¶P r S <�s

r� S � �

r ( � ¤ � � �`Á�� � � � (Let ¤ � � �xÁ�� � � � ( �\ � �xà .Then

¶P r R <�sr� � �r ( �Z � S ��à (complex conjugate)

Henceo ��H�:� A% �K��¹ �BQ (�º@»`¼  �K��à = A% � S ��¹ �BQ (�º@»`¼  � S �xÃor o �� �p�VÂÄ�! #"����� �j=^·'=^ÅÆ� when

T>�� �Æ�V�e #"0�W�� �k=|·#�Thus

Âand

Årepresentthegainandphaseof thefrequency response.i.e. the

frequency response(asacomplex quantity)is

¤ � � �*m Á R@ÇWȪÉeÊExample

Considerthe5-pointparabolicfilter.

o �� �:� �2 [ �`Ga2BT>�� �7=\�0�4T>��{Gz�e� =V�060T>��uGg�4�H=V�0�4T>��{Gk2B�fGg2BT>��{Gj_��W�hence

¨ � � �t� �2 [ �xGy2}=V�0� � S A =\�06 � S % =V�0� � S + Gg2 � SHË � ¥ � � �69

Page 12: Documentl5

thus

¤ � � � Á R@ǵÈ�É,Ê � �2 [ �`Ga2}=\�0� � S � � ( =V�*6 � S % � � ( =V�0� � S + � � ( Gk2 � SHË � � ( �

¤ � � � � ( �O� �2 [ � S % � � ( �`�06'=?�B_h�e #"7�h��GjÌh�e #"p�0�h�a�

Thereforem ¤ � � � � ( �*mB� �2 [ m5�06�=?�4_t�e #"��h�^GkÌO�! #"p�0�h�§m

When�h�z�Y�7��m ¤ � �K� � ( �0mB�Í�

andm ¤ � �K� � ( �*mB�Y��156��36

when�h��Î)��1�_3ÏBÐ

, i.e. ÑÑNÒ �Y��15�B_Ó ¤ � �K� � ( �t�FGI�0�h�i.e. linear phase(true for any FIR filter with palindromiccoefficients); all fre-quenciesdelayedby

�4�(asexpected!)

70