This preview shows page 1. Sign up to view the full content.
Unformatted text preview: E LE CTRIC AL E NGINEERING 113L
Digital Signal Processing Laboratory
@ 1998, Dr. Y1. Wer ter Lecture 4: Digital Wav e form G en e rat ors Intr od uct ion Digita l signal pro cessors can be pro gr ammed to generate ar bitr ary waveforms with great pr ecision and flexibility. In this experimen t , we will pr ogr am the TM S320G54x chip to gene ra te sine waves usin g a sim ple modificat ion of t he trad itio nal t abl e lookup met hod . Thi s is useful in communicati ons (e.g., fr equ en cy hopp ed modems, ph aseshift keyed mo dems , spre ad spect rum ), testing (e.g., precision signal generat ors) and contr ol a pplica tions. A waveform (or func t ion ) genera to r is an integr at ed par t of man y app lica tions impl em en t ed on digita l signal processors . In to day 's exp eriment we will st udy t he implem entat ion of sine wave, t riangul ar wave and sq uare wave genera to rs on the TMS320C54x chip. Sinewave generator by difference equation Ther e are many ways to gene rat e sinusoidal signals using digital signal processors. On e method is based on t he second order difference equat ion
y (n ) = BI .x (n  1) + AI.y (n  1) + A 2.y(n  2) If we set B I = 1, A l = 2cos(O), and A 2 = 1 , then wit h the de lta funct ion (x( n ) = 8(n » as in put (x( n = 0) = 1 an d x (n ) 0 for n :f. 0), we will have a sinu soidal sol ution . If we, the refore, calc ulate y en) from t his eq uat ion recursively, we will get a sinusoidal response as out put . The sinusoidal oscilla t ion results from a pair of poles on the u nit circle of th e Zpl an e whe n t he coefficient A 2 =  L T he angle 0 of t he p oles on the unit circle is deter mined by coefficient AI : th e poles ar e at an angle 0 if Al = 2 cos(O) . T he oscillat ion frequen cy is related to t his angle 0 as F = (Of 2rr )Fs, where Fs is th e s am pling frequency, and 0 is expressed in radia ns . Thu s, t he frequen cy is given by t he formula = F = Fs 2rr arccos (AI/2) From t his it is cle ar that for any freq uency F bel ow the folding frequency Fs / 2, we must take the co rrect coe ffici ent value Al between 2 and 2. The amplit ude of t he oscilla tion is 1/ sin(O) times t he st art ing im pulse, x(n). Sinewav e ge nera tor by table lookup method A second way to cr e ate a sinusoidal signal is by table lookup. A table can be cr eated which can then be used to instruct the D f A to output values listed in the table at the sample tim es. Any ar bitr ary waveform can thus be approxim ate d , wit h the constrain t h at sharp tr ans itions will be smoothed by the AGOl 's out p ut filters. Below is sh own a table for sinusoidalwave, tr iangular wave, and squ are wave signals of 32 s am p les wit h a 15bit 16,384 ext reme valu e. = Sinewave generat or by lowpass filt ering For the DSKplus, one technique is to use the AGOI A/D and D/ A chip 's embedded filters. If we enforce t he ouput of t he D/ A to oscillate between two extreme values every sample period (or , in essence, try to follow a squar e pulse) th en t he output filter will pass only the frequency compo nents of this sign al below the lowpass corner frequency. W it h ot her words, if the fundamental frequency is just below the passband corner fr equ ency and all its harmonics (integer mult iples of the fundamental frequency) are above t he passband corner freq uency then only the fundamen tal frequency will ap pear at t he outp ut of the DAG channel. T he out put will t hus be a sinusoidal signal (provided t hat the filter parameters, sampling freque~ etc . are set up appropriately). In th is experiment we create a table wit h only 4 values: 0,16 384, 0  16384. We initialize the AGOl us ing the standard initialization (used in Experiment B). We load the accumulator with the values mentioned above in an alternately, circular fashion (usin g circular addressing). So your out put will be 0, 16384 , 0, 16384 , ... and so on, a t each clock instant. Th e out put filter will suppress all the higher harmonics involved in t he shar p t r ans it ion from 0 to 16384 and back down , so that t he output will be a sinu soidal signal. By changing the sampling frequency and filter parameters you can suit t he sinusoid al signal to your needs. 1  85 As a reminder t he impo rtant fr equencies are t he sam pling freq uen cy F« , given by th e formula : Fs
and t he lowp ass filt er corne r frequ ency
F LP , =: A1C LK 2..1.B given by t he formula: F
wh ere th e master clock frequ ency M'C LK Ta ble of signal generator valu es sinewa ve 0 3196 6270 9102 11585 13623 15137 16069 16384 16069 15137 13623 11585 9102 6270 3196 0  319 6  6270  9102 11585 13623 15137 16069 16384 16069 15137 13623 115 85  9102  6270  3196 t riang ular 0 2048 4096 6144 8192 10240 12288 14336 16384 14336 12288 10240 8192 6144 4096 2048 0  2048  4096  6144  8192 10240 12288 14336 16384 14336 12288 10240  8192  6144  4096  2048 square wave 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384 16384  16384
=: LP  _ lv/C LK 80.A 10 MHz for t he DS Ppius b oard . 0 1 2 3 4
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 2 86 I f'I ' y, J c. ): .
~ ~I ~ (~~ ~ AI jl"\) +A
{1 ) 0( 0 /0    • _. ]. 2. J (,,  ,) , xl' ):: J ('1\ 0
J{( I)::: \
n? 1 I j ("" ~) = 0 0t: t\ ~ / ,
(. _=I.,..J A_,
I 'j (I ) DJ Ij(") = 'jl,,I)  j C!' _1..) . ~ (I)  'j \.0)
~ (3):::' ~ [z.)  = g1
B I Il , ::. 0
0 L ~, ' . 3 ... ,
, , , J ( I):: J ('! ) = 1 (3) I
'j (S)
'j (b) JC L):: BI = IS, .
( ~ = J (4) JCS)::  J~J 0:: 6, ., = 'jCf)  ;Ll): 6 I  [  ,;].) ::. 0 .,  5
 ...,: ;;j .~. . ')(7)::' ~ (.)  ,C') =
~ (7)  J (,)
~ i)  J (1) :: 7 ....
,
I D  (6.)
0
 z:
I 13 1 'j (I) ~ = aJ i) I
z, ~ \9) = =g ~ =0
t e
:
,f ,I
", ;4 9
10 J (I"] J (~ )  j (i)
~ 0 ~ 6, :::  BI
0 (
I J (~)  0 u) 'j ( q ) ~  I~ I ~  is
z: /I
" I j ell )  'jCt ~)  'j~o) ~ ~ ~ l
87  (  ~1 b~_ ". " ~~ . I Z. r .::. is . (, S'"+ / f~· . 88 University of Hertfordshire STUDENT'S GUIDE FILTERING  LECTURE 3 FILTERING OBJECTIVES
This lecture should achieve the following: • • • • • • Intr oduce signal filtering conce pts Introduce filter performance criteria . Introduce Finite Impulse Response (FIR) filters Consider advantages of digital filters Cons ider advantages of using DSP in digital filter implementation Consider sources of noise in digital filters LECTURE 3 31 ; 89 ,
University of Hertfordshire
STUD ENT'S GUIDE t FILTERING S IGNA LS A ND FILT E RI NG
THE Fi l TER T I M E D O M A IN AMPLITUDE ~M'I\\,.+ )
AMP LITU DE TIME Q t'. , .
Fil TERED OU T: A MPL ITUDE F R E Q U E N C Y DOMA I N r, "
t. SURVIVED : '. '. ' , ', r, t. t. FR E QU ENCY "" '. '. t. F REQU ENCY • Intro duction This lecture discu sses filters. We will first look at simple analog filters in order to give the necessary background information needed to examine digital filters in the second half of the lecture. Let us now look at what a filter does by considering the signals that go in and out of filters. • Signals The signal shown on the above diagram has five components. marked in increasing frequency order. f l to fs. Depending on the application, some of these frequencies may be undesirable. If. for instance, we wanted to remove the frequencies f l and f2, a filter could be used. The circuit shown at the top right acts as a filter that will remove most of the frequencies (fl and f2) so that only the higher frequencies (f3• [4' fs) remain. This is shown in the frequency domain graph in the bottom right of the diagram. An audio system is a good example of an application for a filter. It may be desirable to filter out all of the very low frequencies that contain "main's hum", which presents an unpleasant background noise.
• Filterin g It is particularly easy to observe the effect of filtering in the frequency domain. For example, a highpass filter as shown on the diagram, attenuates (resists) the lowfrequency components of the signal, while the highfrequency co mponents of the signal are passed through without noticeable modification. This is the essence of filtering . LECTURE 3 32 INSIRUMENIS ~1ExAs . 90 u~ "L' University of Hertfordshire STUDENT'S GUIDE FILTERING  The main filter types are as follows : LowPass Filters (LPF)  These filters pass low frequencies and stop high frequencies. HighPass Filters (HPF)  These filters pass high frequencies and stop low frequencies . Band P ass Filters (BPF)  These filters pass only a set range of frequencies. BandStop Filt ers (BSF)  These filters pass all frequencies except the ones within a defined range. We shall be examining analog high and lowpass filters in some detail. Understand, however, that using DSPs, both analog filters and digita l filters can be made. LECTURE 3 33 ; 91 u4D University of Hertfordshire STUDENT'S GUIDE FILTERING PHA S E
A M P L IT U D E .rrv : IAI ~ ~~ ~~ h ~ : :~ 1:\:~ :~ ~~ t A : : 6 : ::/."'\. : .. . . ..\i:T\J . :V;: ... : :::::::::
~ 0~:V /'~ TI ME • W E CA N SE E PHASE RESPONS E • CA N WE H EAR PH AS E RE SPONSE? C). ,~ I • t 'A ~ ' : ::: :: :: .. . . . . . . . . :: t o' PHA SE SHIFT V::V==Q : :A : : A:: /'\ ~~~ i~ ~~~ i N ON· LI N EA R P H AS E RE SPON SE IS UNDESIR A B L E IN • MUSIC • VIDEO • DATA COMMUN ICAT IO NS 180' PHASE SHI FT "~ I • Phase Before we look at filters, let's exam ine another property of signals  phase  to which we shall frequently refer. The phase of a signal refers to its timing. Two signals of the same frequency can be in phase or out of phase, and when they are out of phase, one of the frequencies has been delayed. As the above diagram shows, a 90degree phaseshifted sine wave has its peaks where the original waveform has zero value; A 180degree phase shift represen ts a signa l which is completely out ofphase with the original signal. If these two signals were added, the grand total would amount to no signal at all, because while one signal is positive, the other signal is negative with equal amplitude. If the phase shift were 360 degrees, the signal would be delayed by one period, and would once again be back in phase. Electrical components are one of the sources of phase shift in signals. For example, capacitors and inductors cause shifts in phase. The phase shift that they introduce can depend on the frequency of the input signal, as well as the other components around them. Phase is an important property of the signal. Humans locate sound by working out the phase difference between signals arriving at each ear. The phase of two different signals is used to deceive the ear into knowing where the sound is coming from . This property is also used in stereo hifi reproduction. In data communications, the correct phase of a signal may be the decisive factor in successful transmission. LECTURE 3 34 ' 92 University of Hertford shire STUDENT'S GUIDE FILTERING.. ANALOG FILTERS
HIGH PASS
V out H(oo) _ V in
H(oo) ~  R R+ _ 1 _ jmC ~
e .. IAI • Im !H(", )) R." REAL PART 1 .. IMAGINARY PART m Gain  IAI V Re [H(.. ))z + Im[H(.. )) z v_  I*R Phase . ~ tan t 1m [H( .. )) Re [H(.. )) • Analog Filters The simple capacitorresistor circuit on the above diagram is a highpass filter. It will pass higher frequencies without much modification and stop (attenuate) lower frequencies. This can be predicted because a capacitor will not pass low frequencies, but will allow high frequencies to pass through.
The reactance X, of a capacitor is frequencydependent. .and its mathematical represen tation contains the operator 0> , which is used to represent the square root of I. Let us take the reactance equation for a capacitor as granted and work with it By calculating the input and output voltages in terms of the components in the circuit, we can arrive at an equation that represents the response of the circuit to input excitations, (VoulVin) This is commonly called the transfer function. The first step is to work out an equation for the input voltage (Vin). ... where Zm is the input impedance. In this case, the input impedance is the resistance of R added to the. reactance of C. since they are in series. So: Next, the output voltage (Vou') is simply the voltage across R, so: 2) VOUI = I*R
Given this . the transfer fun ction V oulVin is obtained by dividing equation 2 by equation 1. This equation can also be expre ssed as H( co ). LECTURE 3 35 .
:.. 93 u~ "LJ' University of Hertfordshire STUDENT'S GUIDE FILTERING • Gain and Ph ase Response _ H( ro ) is a frequencydependent complex function. It is frequencydependent because it includes to, and complex because it includes j. This means that the gain and phase will vary with frequency. Using trigonometry, separate equations can be worked out for the gain and phase of the circuit. The vector diagram shows geometrical representation of the transfer function, making it is easier to see how the gain and phase equations are calculated. The magnitude of the signal is the hypotenuse of the triangle, and can be worke d out using Pythagorous Theorem. The phase of the circuit is shown as the angle (0) on the phasor diagram, and is the inverse tangent of the opposite side length div ided by the adjacent side length. Since both gain and phase equations contain frequencydependent components, it is natural to expect both to be frequencydependent. We use this behavior to our advantage in filtering. LECTURE 3 36 94 u4D University of Hertford shire STUDENrs GUIDE FILTERING H IGH PA SS RESPONS E
HIG H PASS IAI Lc=
fe
Ph .. a (Oa llre .. 1 IAI  V R 1 R I + ":"' (CDCII .. f r, I. when IAI(1IV21 IAI ~ 1 '. hRC + z la n ·,(_l_, CDR C • Gai n IAI= ;== == Let us just consider the gain equation at two extremes . When co = H( co )0,
R (Remember that 110 = co, and I I co = 0) 1 R2 + (o*ci This means that if the input is direct current (DC), the gain tends towards zero due to the highvalue denominator, so the signal will be stopped. At the other extreme, when co tends towards infmity, LECTURE 3 37 .
~ 95 u~ 'LJ' University of Hertfordshire STUDENT'S GUIDE FILTERING The gain equation approaches unity, so the signal will be passed. This gives us an indication about the behavior of gain with frequency. If the signal is stopped at low frequencies and passes at high frequencies, it is a highpass filter. Another important point on the gain vs. frequency plot is the cutoff frequency. This is defined as the point where the gain falls to (lI n ) of its original value, commonly called the "3dB point" (the reason for this naming is explained later in this lecture). This can be calculated from the gain equation: so Squaring both sides gives R2 + I2 ( Cl) * C) = 2R 2 .
 Taking R2 to the other side gives 1 2 = 2R2 ( cv * C) R2 = R2 Now take the square root of both sides 1 " . (cv* C) =R and rearrange _ 1_ CR = ro = 21tf. This gives the cutoff frequency fc = l li1tRC. The cutoff frequency identifies a turning point in the behavior of the filter, and marks the start of the pass band . In the case of a highpass filter, any frequency above this point will be passed with little attenuation, and frequencies below this point will be attenuated. • Phase Phase response can be calculated from the phase equation. Phase response starts with a 90degree lead at low frequencies, and falls to 45 degrees at the cutoff frequency. Beyond the cutoff and towards higher frequencies, phase shift continues to drop. In any realistic scenario, we are concerned with the phase response in the pass band. When the amplitude is small, the phase has little effect on the signal. In this particular case, the phase response may be just adequate for some applications. LECTURE 3 38 " 96 Universityof Hertfordshire STUDENT'S GUIDE FILTERING. L O W PASS RESPONSE 'jQl C
H(OI' ' R j<o'.C  IAI   ;::= = = =fc Ph . . . (O .lI r• • • ' o
· 30
· 10 fc '2 .RC . t o '   ..............;;;:~ • LowPass Filter A simple lowpass filter consists of a resistor and a capacitor, as did the highpass filter, but notice that the two components have been swapped. Now the capacitor will be shorting the higher frequencies down to ground, leaving the lower frequencies. The lowpass filter response is very similar to the highpass filter response which we have just examined. The only d ifference is that it is reversed in frequency. The equations are worked out the same way, but as the two components are swapped, R must be swapped with IljcoC. Gain response falls below unity beyond the cutofffrequency. The phase of the output signal lags behind the input by 45 degrees at cutoff, and this lag increases to 90 degrees at higher frequencies. We have looked at two very simple filters. We know that the signal is attenuated at certain frequencies and the phase of the output signal changes with the frequency. How then, do we decide that the performance of the filter is adequate for our purposes? What are the criteria for comparing filter responses? LECTURE 3 39 ; 97 University of Hertfordshire STUDENT'S GUIDE FILTERING PERFORMANCE CRITERIA
AMPLITUDE RESPONS E
IA I pa .. ba nd JI'. ripple 20 IOill. IAI " Gain In dB
 J d B p o lnl atop band rippl e ' ." Cut... " Frequency Gai n at 3dB p oint (at f. ) = f 1\ V2 IAI .... I" ~ I ,...c    . ..
atop band • RIPPLE IN PASS BAND CAUSES NONLINEARITY • POSSIBL E TO DESIGN WITH NO RIPPLE • RIPPLE IN STOP BAND IS LESS IMPORTANT • FALL OFF dB I Decade (Gain In dB I Decade • STOP BAND ATTE NUA TES (SAY <tOdB) p a.. band 0 ') ' Let US now formally defme filter term inology and establish some pe rformance criteria for filters. • Gain and Freq uency We can express a greater range of numbers with less zeros using a logarithm. It is traditional and useful to use decibels (dB) for expressing the gain of filters. One reason for using decibels is that it follows more closely the way the human ear detects different volumes in sound. To convert a gain to decibels, take the log to the base 10 of the gain and multiply by 20. .
So, if a system at a particular frequency has
Y in = 5V, and V out = I V then: To convert this to decibels, first take loglo(0.2) = 0.69897 and multiply this by 20. 20*0 .69897 = 13.97dB Note that loglo(l) = 0, which is why graphs of dB usually have 0 at the top of the scale. LECTURE 3 3 10 . 98 u~ 'L1 University of Hertfordshire STUDENT'S GUIDE FILTERING For frequency, the decade is the unit of measurement used. A decade is the distance between a frequency and 10 times that frequency (e.g., 304kHz to 34kHz). Decades are used to cover a greater range of frequencies in a meaningful way. Th ere fore, a 20dB/decade rolloff means that the filter increases its attenuation by 20dB for every decade of frequency. In digita l filters, linear frequency ranges are also used, since the frequency range is usually not as great. • Cuto rr Frequency Cutoff frequency is defined as the frequency where the gain of the filter falls to (I1 ..fi = 0.70 7) of its value in the pass band. It is also referred to as the "3dB point" (since 2010g,o (0.707) = 3). • Pass Band, Stop Band and Transition Region The pass band is the range of frequencies over which signals pass through the filter with virtually no attenuation. The stop band is chosen by the designer to be at or below a certain level of attenuati on. The amount of attenuation varies from application to application, but realistically, there will always be a small amount of the stopband frequencies left in a filter. The frequencies between the 3dB point and stop band are referred to as the transition region. The transition region is characterized by its falloff rate which is usually expressed in dB/decade.
• Ripples Ripple is when the ga in is not even or level throughout the pass band or stop band, fluctuating as shown in the diagram. While ripple is very common in digital filters, it is not found in simple RC analog filt ers. A filter can produce ripple in both the pass band and the stop band, but we are more concerned with passband ripple, since it caus es some degree of nonlinearity to the signal in which we are interested. It is possible to design ripplefree filters, but there is usually a tradeo ff between the amount of ripple in the pass band, the fa lloff rate in the transition region, and the stopband attenuation. Some ripple may be tolerable in the pass band depending on the application. • Summary of Filter Performance Criteria • Passband ripple • Falloff rate in transition region • Stopband attenuation • Phase response LECTURE 3 3 11 99 University of Hertfordshire STUDENT'S GUID E FILTERING PH A S E RESPONSE
•
Ph l . e R•• pons. of a Llnaa, Ph ... Fllte,
• • PH A S E RESPONSE REPRESENTS TIM E DELAY Of DIFFERENT FREQUENC IES LINEAR PHASE RESPONSE DELAY S AL L FREQUENCIES BY SAME AMOUNT TIME DELAYS A T' , & ' 2 ARE EQ UAL NO N ·L IN EA R PHAS E R ESPONSE • DELAYS A LL FREQUENCIES BY D IFFER EN T AMOUNTS • CA U SE S DISTOR TION TO OR IG IN AL SIG N AL • IS AUDIB L E IN A MUS IC A PPLI CATI ON • IS VISIBLE IN A VID EO APPLICA TION LINEAR PHASE IS ONLY I MPOR TA N T IN PAS S B A ND SOME NO NLINEAR ITY M AY BE TOLE RA TED • "
Tim. De l.y '2
0 ' • Un ifo rm Tim . Delay a Lln aa, Ph •• e Flit., • • • Phase Response The phase response of a filter is one of the important performance criteria in determining a filter' s suitability for a particular application. Phase response represents the time delay introduced to all or part of the signal. • Linea r and NonLinear Phase Response A filter with a linear phase response delays all frequencies by the same amount. To demonstrate this concept, lets take two frequencies (f l and f2) , which are both delay ed by the same amount of time (0.2ms) .
If f l = 100Hz, then the period of the signal is 1/100 0.2msl l O = 0.02, or 2%. ms If f2 = 1kHz, then the period of the signal is 1/1000 0.2msllms = 0.2, or 20%. = 10ms. If the signal is delayed by 0.2ms, then = Ims. In this case, the signal would be delayed by So, with these two signals, they are delayed by the same amount, but they will have different phase shifts. This is shown on the above diagram . The output signal is not distorted, but delayed by a certain amount. Because a real signal contains a large number of frequencies, if each frequency is delayed by a different amount, the output signal will be distorted. .Some applications, such as music and video, cannot tolerate nonlinear phase response.
Linear phase response is really only important in the pass bands, since the passed signals are the ones in which we are interested. There is usually a tradeoff between linear phase response in the pass band and other filter performance criteria, such as steepness of rolloff and stopband attenuation. LECTURE 3 312 100 University of Hertfordshire STUDENT'S GUIDE FILTERING BUTTERWORTH FI L T E R
IA I IA I ;:::= = = = • 'MAX IMA L L Y FLAT' FILTE R De la y
• POO R PHAS E RESP ONSE, NON L INEA R ARO U ND C UT· OF F FREQ UE NC Y "   ...   .+, If. o
1.0 2.0 • EXCESSIVEL Y HIGH ORDER FI LTER NE EDED TO ACHIEVE ADEQUA TE RO L L o F F • Practical Analog Filters There are a number of practical analog filter designs with different performances for gain and phase. We shall closely examine the «Butterworth" filter . • Butterworth Filter This filter type is commonly referred to as a «maximally flat" filter, due to its amplitude response in the pass band . The pass band in a Butterworth filter is virtually ripple free . However, there are two problems : I. The nonlinear phase response in the pass band rules out its use in applications which require linear phase response. On the above diagram, the delay plot versus frequency shows the nonlinearity of the phase response on a normalized frequency scale. The delay is worst at fife = I, wh ich is the 3dB point. 2. It has a slow rolloff in the transition region. In order to achieve adequate rolloff, a number of stages need to be cascaded. Our amplitude response plots show various responses that are achievable for different orders of Butterworth filters. The greater the number of stages, the worse the phase response. LECTURE 3 3 13 , 101 University of Hertfordshire STUD ENT'S GUIDE FILTE RING FI LT E R TYPES
CHEBYS HEV
• • • ST EEPER RO LLoFF THAN BUTTE R WO RTH MOR E RIPPLE IN PASS BAND PO O R PHASE RESPONS E BESSE L
• • MA XIMAL LY FLAT P HA SE RESP O NS E L ESS STEEP R OLLoFF FI LT E R D ESIGN S O FT W A RE P AC KAGES ALLOW US TO :
• • EXPERIMEN T WITH MANY DES IG N S EVALUATE SUITABILITY OF GAIN AND PH ASE RESP O N SES • C hebyshev Filter There are a number of other commonly used filter types. The Chebyshev design has a steeper rolloff than the Butterworth. . However, it has more ripple in the pass band and poor phase response. Since the steepness of the rolloff is considerably better than Butterworth, the ripple in the pass band may be tolerated in some applications. • Bessel Filters Bessel filters are designed using Bessel functions as a base. They have a better phase response than either Butterworth or Chebychev. However, their rolloff is much less steep (flatter). It is clear from the introduction and comparison of these filters that there is a tradeoff between steeper rolloff and flat phase response. In most practical cases, the Butterworth seems to be a good compromise.
• Filter Design Packages Filter design is a formulabased, calculationintensive task that is perfectly suited for computerization. Filter design software packages offer this functionality and increase efficiency and effectiveness of designers. Using one of these packages, a filter may be easily designed by specifying a number of its features, such as type of filter, cutofffrequency, passband ripple, and required rolloffrate. The software package usually computes all of the component values and the amplitude and phase response of the filter. The designer can then assess the suitability of the design and make any necessary changes to the spec ifications without actually building the filter. This is one of the major advantages of using such a software package. LECTURE 3 314 '1ExAs INSIRUMENI'S .
102 University of Hertfordshire STUDE NT'S GUIDE FILTERING. DIGITAL FILT ERS
In pUI x( n) <>..+1 ~ Su mming Junctio n y(n) Ou tp ul x(n) u m p/ ed analog waveform. x(O)al I " O. x(1 ) a l I " t.. x(2 )al I " 2 t. _ . t. " .ampling perio d f. " Q a n " welghla (coemel enla •• eallng factor)
Z1 unit time de'ay " one .amp llng pe riod y(n ) • • o x(n) + a 1 x(n 1) + a2 x(n  2) Digita l Filters We shall now examine digital filters, starting with a simple example  a moving average filter (see above flow diagram). Let us first identify the major components of a digital filter.
e e The In put x(n) The input of a digital filter is a series of discrete samples obtained by sampling the input waveform. The sampling rate must meet the Nyquist Criteria (Shannon's Sampling Theorem) that we covered in our sampling lecture (highest frequency of input signal :5: 2 x sampling frequency). The term x(n) means the input at a time (n).
e Z 1 ZI represents a time delay that is equal to the sampling period. This is also called a unit delay. Therefore, each z box delays the samples for one sampling period. In the diagram, this is shown by the input going into the delay box as x(n) and coming out as x(nl). Since x(n) means the input at a time (n), x(n~l) means the input at time (nI), What actually hap pens is that x(nI) is the previous input that has been saved in the memory of the DSP.
e Filter Taps and Weights The output of each delay box is called a tap. Taps are usually fed into sealers which scale the value of the delayed sample to the required value. This is done by multiplying the input (or delayed input) by a coefficient. In the diagram, these are marked as au, a, and a 2• The scaling factor is called the weight. In mathematical terms, the weight is multiplied by the delayed input, so the output of the first tap is llo*x(n). The next tap output will be at *x(nI), and the output of the last tap is a2*x(n2). LECTURE 3 315 103 University of Hertfordshire STUDENT'S GUIDE FILTERING • Sum ming Juncti ons Outputs of the weights are fed into summing j unctions, whic h add the weighted, de layed, fed forward outputs from the taps. So in this example, the outpu t of the first summ ing junction is 8o*x(n) + a)*x(nI). At the next summing junction, this is added to the output of the final tap , giving llo *x(n) + al*x(n I) + a2*x(n2), which is the output. . • T he Output yen) The output of a digital filter is a combi nation of a number of samples which have been delayed and we igh ted, and is usually called yen). • T he Operation of Digital Filters In summary, the output is yen) and the present sample is x(n ). The previous samples would then be : x(n I) = one unit time delay x(n2 ) = two unit time delay When x(n) arrives at the input, the taps are feeding the delayed samples to weights a l and a2. Therefore, sampling at any sampling instant, the value of the output can be calculated using the weighted sum of the current and two previous sam ples as follows: yen) = 8o*x(n) + al*x(nI ) + a2*x(n2) LECTURE 3 316 104 University of Hertfordshire STUDENr s GUIDE FILTERING MOVI NG AVERA GE FILTER
x(n) • A SSUME NO PREVIOUS INPUTS X(O) 20 ; X( .1) 0 ; X(2 ) 0 = = = 0 _25 0 .5 .... ~ 0 .2 5 _ • A ND LET
.0 = 0 .25 . , " 0 .5 $ '. ® I:
in p ut .z " 0 .25 yen )
YCO )
& 0 .25·x (0 ). 0.S· " (· 1) . 0 .25· " (·2 ) & 5 40 y( 1) " 0.25· 20 . 0. S·20 • 0. 25'0 " 15 mon tve wed thu 40 30 1
$ o u tpu t . y(5) .. 0.25·20. 0.S·4O + 0.2 5·12" 28 7· . :
:
fri : ~
, : y(6 ) .. 0 .25·20 • 0.S· 20 + 0.25 ·40 .. 25 20 } 7 10 ~6.tJ i j.j • Um. • MOVING AVERAGE CALCULA TION • The Practical Operat ion of the Filter Let us now observe the operation of the filter on our sample data. If we enter some numbers, we can see the result. Let 's start with the coefficients.
30 = 0.25 a. = 0.5 a2 = 0.25 These weights were selected to give a good averaging performance on our share prices. Late r in th is lecture, we shall consider how filter weights are calculated from performance requirements and specifications by using a software package. Now let's define some inputs. The samples chosen represent the value of a stock during the course of a week, the sample rate being one per day . For our purpose, time starts on Monday , so the sample on.Monday is the value for x(O), Tuesday is x(l), and so on.
Day Mon day Tuesday Wednesday Thursday Friday Saturday T ime Period x(n) 0 I 2 3 4 5 x(O) x(l) x(2) x(3) x(4) x(5) PriceS 20 20 20 12 40 20 These va lues are shown on the graph in the middle of the above diagram. Note that major variations took place on Thursday and Friday. LECTURE 3 3 17 INSIRUMENTS ~ TEXAS  105 u~ 'L' University of Hertfordshire STUDENT'S GUIDE FILTERING Now, assuming no previous inputs (meaning that x( I) = 0, x(2 ) = 0, etc.), let' s calculatethe output of the . filter. We know that: y(n) = ao ·x(n) + a l·x(nI) + a2·x(n2) Entering the values of the coefficients gives: y(n) = 0.2S· x(n) + O.5·x (n l) + 0.25· x(n2) On Monday, the time period is 0, so we can work out y(O) as follows : y(O) = 0.2S· x(0) + O.S·x( I) + 0.2S· x(2) y(O = 0.2S·20 + O.S·O + 0.2· S.0 = S ) Therefore, the output of the filter on Monday is $S . For Monday, the only input that has an affect on the output is Mond ay's input. For Tuesday, there is now one more input to consider. This is the delayed input sample from Monday, now unitdelayed and weighted by O.S. On Tuesday, the time period is 1, so: y(l) = 0.2S·x(l) + O.5·x(O) + 0 .2S·x(I) = 0.2S ·20 + 0.5·20 + 0.2S·0 = $ IS For Wednesday, all three inputs need to be considered . On Wednesday, the time period is 2, so : y(l) = 0.2S·x(2) + O.5·x (I) + 0.2S·x(0) == 0 .2S·20 + 0.S·2,0 + 0 .2S·20 = $20 Now, work out the values for Thursday and Friday and fill in the blanks on the transparency. Then complete the missing section of the bottom graph in the diagram. You may be asking what this has to do with filters. Well, if you look at the completed graph, you will see that the system has filtered out some of the fast movement on Thursday and Friday to give a smoother graph. The filter is actually performing a "moving average calculation. While it may not be much of a filter, it demonstrates the basic principles involved in digital filters by doing a number of calculations with past and present inputs to generate an output. In complex filters, other information can also be included in the calculation, but the basic principals remain the same. These calculations also demonstrate the importance of MAC instruction in DSPs. Filter outputs consist of a series of multiplications and successive additions (ca lled accumulate) operations, and the MAC instruction is designed to perform these as quickly as possible. LECTURE 3 3 18 ; 106 University of Hertfordshire STUDENT'S GUIDE FILTERING WE IG H TE D IM P UL S E FUNC T ION
IAI
77 Are . under pu l •• IAI
3 •• WldlhO Ampl"Ud·O ., JoC t) del ) = I LL _l _i ~ ,) .J S Are. und. r puis . puls c( l) del)  .3 .5 J 3 del) = 6 ., WEIG HTED IMPUL SE FU N C TION JA o( l ) del) =A Anta • A Amplitud e . CI) SA M PLING WA VEFORM A S WEI GHT ED IMPUL SE TRAIN i1
t. ... ... ... ...
....
:
to oC )  6 (t ..) + ..•.•_+ 6 (t t t.) + 6 (I) + 6 (I + t ,) + .•.. + 6 (t + ..) n=co
o(t) t :
2t. 3 t. 4to L 6(t nt, ) • n = co • Tools Before we consider more complex digital filters, let us first learn about some mathematical tools used in dig ital filterin g. This will solidify our understanding of digital filters and provide a foundation for future learning of more complex subjects. • Impulse An impulse is defined as an idealized rectan gular pulse with a pulse width of zero and infinite amplitude. It is typically expressed by an integral as shown on the above diagram. Th is is a general formula that allows us to calculate the area under any pulse. . • Weighted Impulse Function Consider th e pulse with an amplitude of 3 and a width of 2, as shown on the transparency. Using the sam e integral to calculate the area under it, we find that it equals 6. A weighted impu lse function is similar to this. It has an area of "A" and amplitude of infinity. It is represented by the integral as shown on the d iagram. Obviously this is impossible in the real world, but the weighted impulse function is extensively used in digital signal processing to he lp explain DSP techniques. For example, an ana log wa veform can be represented as a multiplication of the analog signal with a period ic we ighted impulse function whose frequency is equal to the sampling frequen cy. LECTURE 3 319 ; 107 University of Hertfordsh ire STUDENrs GUIDE FILTERING F ILTER FUNC T IONS
F ILTE R INPUT AS W EIGH TED IMPULS ES MONDAY'S IN PUT VAL UE
40 30 20 ..,
~t+'I'+++ ti me , 2 4 J20 0(1) d(l ) = 20 '0 o , IM PULSE RES PON SE O F FI L TER • OU TPUT WAVE FO RM OB TA IN ED F OR It. SINGL E UN ITY WEIGH TED IM PULS E A PPLI ED A T t· 0 yet)
0 .5 0 .25 • IMPULSERESPONSECONS~TSO F FINITE NUMBER O F PULSES; HENC E FINITE IM P UL SE RE SPONSE (F IR) FI LTER o t 2 • IMP U L SE RESPONSE MAY BE USED TO OBTAIN R E SP O NSE TO ANY INP U T • Filter Input as Weighted Im pulses Let us now use weighted impulses to represent our input signal (the stock values) . Monday is represented by "0 " on the time axis (x). The stock value on Monday was $20. Th e weighted impulse function sh ould th ere fore evaluate to this value. The diagram shows the integral for the weighted impulse function. In this same way, we can evaluate the weighted impulses to represent each input sample as shown on the first graph. Impulse Response of the Filter • Us in g the moving average filter again, if an input is applied at time t = 0, with a value of 1, followed by all other inputs being 0, the output at time t = 0 will be 0.25 as the 1 goes down the first tap. Then , at time t = I, the 1 will go down the second tap , g iving 0.5, and fmally at time t:= 2, it will give an output of 0.25, as the 1 goes down the third tap. This is shown on the bottom graph. Some useful results can be gained by this. First, we now have a list of coefficients for the filter, so if filter coefficients of a digital filter are unknown, then sending an impulse into the filter may give the coefficients for an FIR filter. Also, from this we can see that the I eventually drops out of the right side of the filter, at which point all future outp uts are zero. This means that the length of the response to an impulse is fmite. There are two main types of digita l filters  those that produce a fmite impulse response (FIR), and those that produce an output that would, in theory, go on forever, known as the Infinite Impulse Response (lIR) fil ters.
We can use the weighted impulse response theory to help us with impulse response of our digital filter. Impulse response of a filter is defmed as the waveform obtained for a single unity weighted impulse applied at time zero. Using this defmition and the filter output equation, we can compute the impulse response. y(n) = 0.2S*x(n) + O.5*x(n l ) + 0.2S*x(n2) LECTURE 3 320 INS11UJMENl'S ~TEXAS ; 108 u~ University of ~ Hertfordshire STUDENrs GUIDE FILTERING The impu lse response of a filter is very usefu l for a numb er of calculations, for example, plotting the filter freq uency respo nse. It can also be used to comp ute the output for a given input by a process ca lled convolution. However, convolution is beyond the scope of this discussion . • Finite Impulse Response (FIR) filter We calculated the impulse response of our filter. There were only three weighted impulses as the impulse response. This is characteristic of the type of digital filters we have discussed. If the number of taps we re to be increased, the number of samples at the output would increase accordingly, but would still be a fini te number. LECTURE 3 32 1 109 University of Hertfordshire STUDENT'S GUID E FILTERING FIR FI L TERS
• AN FIR FILTER WITH A STEEPER ROLL·O FF X(l c' r.. ~ ·.
80 ., . 1 60 ....c . •161 1. p •
• • ••• • • • • • • • • • • •••• •• •• • • _ y(l) A MORE REALISTIC FIL TER DESIGNED USIN G A SOFTWARE FI L TE R D ES IG N PAC K A GE SPECIFICATIONS: • • • CUToFF FREQUENCY . 260Hz STOP BAND ATT E NUA TION> 60db ROLLoFF 55dB pe r 10 0Hz (VE RY SHA RP l • FILTER WITH 16 1 T A PS • 161 DIFFERENT GAIN VA LUE S • THIS FILTER IS USED IN OUR DEMONS T RA TION • Complex FIR Filters Let us now cons ider a more complex FIR filter  one that uses an identical structure to the moving average. Instead of three taps and three coefficients. it will have 161 of both. That means 161 coefficients are needed (the current input and 160 previous inputs). It is a lowpass filter with a 260Hz cutoff frequency and a very steep rolloff in its transition region. In the stop band, it attenuates on average down to about 6OdB. As a general rule, the greater the number of taps. the faster the cutoff. and the more attenuation in the stop band. We will introduce its structu re and specifications in our demonstration. Our tone generator can genera te a number of tones. Weare using this filter to eliminate some high pitch tones. When you listen to the tone generator with and without the filter, you will notice the difference. Are you thinking about how to calculate 161 different tap weights? For this many tap weights, we use a software design package which automatically calculates the weig hts and more. We shall further discuss digital filter design later on in this lecture. LECTURE 3 322 .
0 110 University of Hertfordshire STUDENT'S GUIDE FILTERI NG FIR RESPONSE
Gain (dB) a STEEP ROLLO FF
'e • cut oft' frequency 4 a >60dB SUPPR ESS ION IN STO P B A N D ' •• aampllnll ' ... quane y 2"60 1000 2000 3 000 4000 Ie
P h aa. (D. gr. . . ) o
· 30 a L IN EA R PHASE R ESPONSE · . 0 '....,..~ • Amplitude Response The top graph shows the amplitude response of the filter. As you can see, it is a lowpass filter, because it passes the frequencies from 0 to the cutoff frequency, then attenuates the high frequencies. It has a small amount of ripple in the pass band, which can be seen by the filter response going up before it goes down. This is not ideal, but it is unlikely to be audible for this application. The ripple in the stop band is more obvious, as there is a defmite rise and fall in the response. This means that some frequencies will be attenuated much more than others. Again, this does not matter, as you would not hear the signalbelow 60dB under normal conditions anyway. The steep rollo ff between the pass band and stop band is the most important aspect of the filter in this application.
• Phase Response The bottom graph on the diagram shows the phase response of the filter. Phase response is extremely linear. This is typical of FIR filters, and is their major advantage. It makes them ideal for music, video, data communications, and many other applications. LECTURE 3 323 .
111 University of Hertfordshire STUD ENT'S GUIDE FILTERING DSP AND DIG ITA L FIL TERS
INFINITE IMPULSE RE S P ONSE (UR) FI LT E R
• DELA YS A N D WEIGHT S ARE IN FEEDBACK L OOP • NO Nl..INE A R PHASE RESPONSE • LE SS TA PS, SHARPER FALL OFF • MA Y BE UNSTABLE ADVANTAGES OF DIGITA L FIL TERS
• • PROGRAMMAB LE CHANGE COEFFICIENTS. NEW F IL TE R POSSIBL E TO I MPL EMENT ' A DA P TIVE' FILTERS CHANGE COEFFIC IENTS UNDE R CERTAIN COND ITIONS ON THE FL Y W HY USE DSP FOR DIGITAL FI LTER I MPL EMENTA TIO N?
RE MEMB ER : A  S'C + D
y(n) .0 x( n ) + 8\ x(n l ) + 82 _(n2 1 • Infinite Impu lse Response (lIR) Filters Infinite Impulse Response (lIR) filters not only calculate the output in terms of current and past inputs, but also use the previous outputs (i.e., they have feedback). Because of the feedback loop, these filters may become unstable. Their impulse response has an infinite number of samples for a single unity impulse input. These filters o ffer sharper rolloff for fewer taps , However, their nonlinear phase response is a major disadvantage. They are very useful when there are limitations on the number of taps that can be implemented. • Advantages of Digital Filters One of the major advantages of digital filters is that they are programmable. To change the cutoff frequency, rolloff rate, or phase response, all one must do is change a few coefficients. We can quite easily make major changes, such as converting a lowpass filter into a highpass filter. The idea of changing filter characteristics by changing a few coefficients opens up even wider possibilities. It is possible to design adaptive filters that adapt themselves to changing conditions. For adaptive filters, a mechanism must be designed to change the coefficients of the filter in accordance with changing conditions. Such filters are very useful in modems. Since the properties of telephone lines change continuously, adaptive filters offer the ideal solution for these environments.
Why Use DSP for Digital Filter Implementation? DSPs are very efficient in performing successive multiply and add (MAC) operations. Most DSPs can perform a singlecycle multiply and add operation. Digital filters require delays and fast multiply and add operations. DSPs can provide both, making them the ideal medium for implementation of digital filters. The increasing processing power of DSPs has made possible the implementation of complex _ digital filter stru ctures, such as adaptive filters. LECTURE 3 324 11 2 uID University of Hertfordshire STUDENT'S GUIDE FILTERING PERFORMANCE ISSUES
NOISE IN DIGITAL FILTERS
• SIGNAL QUANTIZATION
NOISE INTRODUCED IS PROPORTIONAL TO NUMBER OF BITS CONVERSION USES • COEFFICIENT QUANTIZA TION
COEFFICIENTS DETERMI NE THE BEHAVIOR OF FILTERS MORE SIGNIFICANT IN IR • TRUNCATION
0.14 x D.n  0 ."72 TRUNCATE TO 0.46 DOUBLEWIOTH PRODUCT REGISTERS AND ACCUMULA TORS HELP REDUCE TRUNC A TIO N ERRORS. • INTERNA L OVERFLOW 00,0.,,11,000, ~ OVERFLOW
~
~ ~ SATURATE 1111 • DYNAMIC RA NGE CONSTRA INTS
11 bit 32 bit 2D Iolh .( 2"'_ KdB
20 Iolh. ( %,2, 112dB • Noise in Digital Filters There are five major sources of error in digital filters. With IIR filters, these errors are exaggerated due to the feedback. Since FIR filters are feedforward circuits, errors appear once only. • Signal Quantization ADCs introduce quantization errors to the original signal, and DACs do not eliminate this error in their reverse conversion process. If the resolution of a DAC is smaller than the DSP, there will be a small error. For example, a 16bit DSP using a 1Obit DAC cannot produce an output signal greater than 10 bits, but this type of system can reduce the truncation error compared with a 10bit DSP and a 10bit DAC. • Coefficient Quantization Coefficients of filters are calculated as analog values. Within DSPs, 16or 32bit representations are used. Such conversions inevitably introduce errors. Although 32bit representations are clearly more accurate than 16bit, errors are quite small even with 16bit representation. However, coefficient quantization errors must be taken into account, particularly in design and implementation of IIR filters, because the effect of feedbac k increases the effect of such errors, and may even cause instability. Normally, this is only a problem in fixedpo int DSPs, since floatingpoint DSPs with 32bit accuracy even apply the 32 bits to small numbers. On a fixedpo int DSP, a small number will be preceded by a large number of zeros, which will reduce the accuracy of the coefficient LECTURE 3 325 INSIRUMENTS ~TEXAS 11 3 University of Hertfordshire STUDENT'S GUIDE FILTERING • Trun cation When two 16bit numbers are multiplied, the result is 32 bits wide. This can be demonstrated with decima l multiplication (064 x 0.73 = 0.4672). Here, two numbers of two decimal places each, produce a result with four decimal places. For this reason, most fixedpoint DSPs use a product register and accumulator, which is double the width of all other registers. This allows 32bit precision to be maintained during multiplication and addition. The problem comes when this result must be stored in memory. It is possible to store all 32 bits, but this increases costs and computation time. Usually the mostsignificant 16 bits are used, and the leastsignificant 16 bits are truncated. The error due to this truncation is only in the 16th bit, and is less than 0.001%. By having 32bit accuracy, this truncation is only done once for each output. If 16 bits were used, the truncation would be necessary for each tap, so in the previous examp le, it would happen 161 times, giving a much bigger error. • Internal Overflow When you add two 4bit binary numbers as shown on the diagram, the result can be 5 bits. In a 16bit DSP, it could overflow to 17 bits. A 4bit processor would have to discard the 5th bit. This is called overflow. In the same way, underflow is also possible as a result of adding two negative numbers. Both can cause errors in digital filters. DSPs allow designers to switch to saturation mode. If the result of operation is greater than the largest possible positive value, the DSP's accumulator will saturate to the greatest positive number it can store. Similarly, if the result is greater than the largest representable negative value, the output saturates to the largest negative number it can store. Neither situation corrects the errors, but they do stop wrong results from going through the filter. Such situations should be avoided in digital filter design. This is one of the reasons why fixedpoint DSPs are more difficult to program. an • Dynamic Range Constraints The dynamic range of a device is directly proportional to the word width of DSPs. On a 16bit device, the number of different values is 2 16• From this; the dynamic range for a 16bit device can be calculated by converting 2 16 to decibels, which is 20l0gI 0(2 16) = 96dB. During arithmetical calculations, this is extended to 192dB since the product registers and accumulator have 32 bits. Such dynamic range is sufficient for most digital filter applications. LECTURE 3 326 114 University of Hertfordshire STUDENT'S GUIDE FILTERING _ DIG ITA L FILTER D ES IGN
• AUTOMAT ES DESIGN TASK BY SOF T W ARE • D E S IG N S OFTWARE REQUIRES INFORMAT ION SUC H A S: • PASS BA ND. STOP BAND , TRA N SITI O N REG ION • RIPPL E IN PASS BAND • REQU IRED RO LL ·OF F • DE S IG N SO FTW A R E G E N E R A T E S : • NUMBER O F TAPS • COEFFICIENTS R EQUIRE D • DSP SPECIFIC ASSEMBLY CO D E • RESPONSE PLOTS : • GAIN • PHASE • IMPUL SE ENAB L ES EVA L UA TION OF DE S IG N
~IMPLEM ENT A T I O N • • Automation of Design Digital filters are now designed almos t exclusively by approp ria te design software. Th ere are a number of commercia lly available digital filter design pack ages of varying comp lexity and funct io na lity. Most packages are qu ite intu itive, De. ign Process s • Design software requi res the specification of the fi Iter from the designer. TIle designer should provide information such as the pass band. slop band. transition region. and the required rolloff rate in the transition region. The software will then do all of Ihe computations necessary to calculate the number of taps and coe ffi cients required. II will even produce nS Pspecific assembly code for the implementation of the filter. Quite commonly. most packages ,15k Ihe user whether the number of taps required to implement the filter is acceptable, As the number of taps increases. the requirements on the processor resources increase as wel l. The designer may wish 10 trade some of the performance lor a less complex filter before the design is done. On completion of the design, all necessary gain, phase. and impulse response plOIS are produ ced. This is one of the primary advantages of using a soil ware des ig n pac kage. It allows the designers to evaluate the performance of the filter before the actual implementation. LECTURE 3 327 I./} 1ExAs INSTRUMENTS ' 115 University of Hertfordshire STUDENT'S GUIDE FILTERING SUMMAR Y
• • • • • FILT ER S ARE USED FOR FREQUENCY SELECTION LOW AND HI GH P A S S ANALOG FILTERS P E R FO R M A N CE
• PASS BAND RIPP LE . RO L LOFF AN D PH A SE RESPONSE DI GITAL F IN ITE IM PUL SE RES P O NSE FILTERS (FI R) A D V A N TA G ES OF DIG ITA L F IL TERS
• PROGRAMMABLE • ADAPTIVE FILTERS • DSP MAKES DIG IT A L FILTER I MPL E M ENTATI ON EASIER • Filters Filters are used to iso late certain frequencies in waveforms. A waveform usually contains a group o f desirable frequencies and a group which we would like to eliminate.
• Low and HighPass Analog Filters Analog filters use res istors , capacitors and inductors. We have only discussed filters with resis tors and capacitors (more comm on). Filters are usually classified according to the group of frequencies they pass'o r attenuate. Hence, the names highpass, lowpass, bandpass, and bandstop. • Perfo rm ance Filter performance is commonly defined in terms of passband ripple, rolloff rate in transition region, and phase response . Nonlinear phase responses and high ripples are undesirable. • FIR Filters Digital filters operate on a basis of samples rather than continuous signals. The fundamental concepts of digital filter operation are wellrepresented in FIR filters. Such filters are feedforward circuits with a number of unitdelay elements. The filter impulse response consists of a fmite number of weighted impulses. • Advantages of Digital Filters The primary advantage of digital filters is that they are programmable (by changing their coefficients). This makes them easy to configure, so with DSP implementation, a new filter can be produced simply by changing a program. This is in contrast with analog filters, where even a minor change may require a soldering iron. Adaptive filters "adapt" to external conditions. Through a suitable mechanism, external conditions chang e the filter coefficients, and therefore create a more desirable filter for the new conditions. Such filters are used extensively in data communications, where conditions in a transmission medium change constantly. • DSPs for Digital Filters DSPs are designed specifically for applications such as digital filters. Since DSPs are highly optimized f or performing singlecycle MAC operations, they are a very suitable engine for digital filter implementation. LECTURE 3 328 116 University of Hertfordshire STUDENT'S GUIDE FILTERING. REFERENC ES
Ahmed, H. and Sprea dbury , P. J. [1978]. Electronics f or Engineers, Cambridge University Press, Cam bridge, UK Bateman, A. and Yates, W. [1988]. Digital Signal Processing Design, Pitman Publishing, London, UK Chu, S. and Burrus, C. S. (Nov 1984]. "M ultirate Filter Design Using Comb Filters," IEEE Transactions .on Circuits and Systems, Vol CAS3 1, No 11, pp. 913 924 Cowan, C. F. N. and Grant, P. M. [1985]. Adaptive Filters, PrenticeHall, Englewood Cliffs, NJ Hamming, R. W. [1989]. Digital Filters, PrenticeHall, Englewoo d Cliffs, NJ Haykin, Simon. [1991]. Adaptive Filter Theory, PrenticeHall, Englewood Cliffs, NJ Jackson, L. B. [1989]. Digital Filters and Signal Processing, Second Edition, Kluwer Academ ic Publishers, Norwell, MA Jury, E. 1. [1964]. Theory and Application ofthe ZTransform Method, John Wiley, New York Oppenheim, A. V. and Schafer, R. W. [1975 and 1988]. Digital Signal Processing, PrenticeHall, Englewood Cliffs, NJ Papam ichalis, Panos (ed.) (1991). Digital Signal Processing with the TMS320 Family, Volume 3, PrenticeHall, Englewood Cli ffs, NJ Parks , T. W. and Burrus, C. S. [1987] . Digital Filter Design, Wiley and Sons, New York Tre ichler, J. R.; Johnson, C. R. and Larimore, M. G. [1987]. Theory and Design of Adaptive Filters, Wiley and Sons, New York Zaks, R. [1981]. From Chips to Systems, Sybex, California LECTU RE 3 329 117 University of Hertfordshire STUDENrs GUIDE FILTERING LECTURE 3 330 118 University of Hertfordshire STUDENT'S GUIDE .  DEMONSTRATIONS T O N E GENERA TOR W IT H F IL TER T u ne~ Ba ss ~ + LO W PASS FIL TE R DSP Pro gram • To To To Pu rpose demonstrate a digital filter and show how a filter can change a signal. show how the length of a digital filter changes the frequency response. demonstrate a number of digital filters with different frequency responses. • Introduction In this demonstration, we will show how a lowpass filter can be used to remove unwanted signals. The tun e generator that was used in the first lecture is used as a basis. The filter is added to the program in the DSP to try and to remove the tune, leaving just the bass notes. The block diagram shows the new configuration. The tune generator generates the samples exactly as before, but before they are sent to the DAC, they are passed through an FIR filter, which is incorporated as part of the program. DEMONSTRATION 3 D3 1 11 9 120 E LECTRICAL ENGINEERING 113 L Digital Signal Processing Laboratory
@ 1998, Dr. M. We rter Le c t u r e 5: FIR Digital Filtering In trodu ction Digital filters ar e a common ingredi ent of many digital signal processing systems. Th ere are two types of digital filters, nam ely Finit e Im pulse Response (F IR) and Infinit e Impulse Resp onse (IIR) filters. In today' s experiment we will implement FIR filters on t he TMS320C542 chip. FIR Filt ers An FIR filter has several design advantages over an IIR filter. First of all, it is always stable and realizable, and it can be designed to have exact linear phase. Moreover, it will never create limi t cycles due t o quantization or overflow oscillations. The design process for FIR filters is also less complicated than that of IIR filters, but the FIR filter does require many more taps t han the IIR filter to meet a given set of filter magnit ude specifications . A N tap FIR filter is described by the difference equation (or convolu t ion formula) y(n) = h(O)x(n) + h(l )x (n  1) + .. .+ h(N  l )x (n  (N  1)) =L N l h(k)x (n  k) = h(n) * x(n) (1) k=O wher e h(n ) for n = 0, .. . , N  1 is the impulse response of the FIR filt er . T he structure of the F IR filter in its direct form (also called t apped delay line) realization is shown in t he figure b elow. ~ ·1 Z .1 Z h/OJ h(l )
_ ...... _ _4'_ h[_. :::&
z ., Yin) Figure . 1: Direct form implementation of an FIR Filter At any given tim e n, the output y(n) is a coJivolution sum of the impulse response, h(n ), and the filt er input , x(n) . The calculation involves multiplying each of the delayed input samples x(n  k) by a "tap weight" h(k) and adding all of th e products. After one sum is obtained, the time in dex is incr em en ted , and the delay line must be updated by shifting all samples in time, an d a new input is made available as x(n) . F IR filter design techniques are used to determine the actual tap weights or impu lse res ponse h(n) th at will adequately approximate a desired frequency response or other desired specificat io ns . There are many met hods for FIR filter design . T hree wellknown approaches are the window design method , the discreteleast square design method , an d the Par ksMcClellan algorit hm (see Section 8.2 in "Digit al Signal P rocessing" by P roakis and Manolakis, or the EE 212A lect ure notes by Wer ter ). Useful design progr ams are available in the Signal Toolbox of Matlab . We will not discuss these met hods here. Fro m an implementation point of view, the difference between different design methods is just a different set of filter coefficients. FIR Filter Implementation Some feat ures of the T MS320C542 that facilitate the im plement at ion of F IR filters are its parallel multiply / ad d instruction, and its circu lar addr essing mode. T he mu ltiply /addit ion instructions permit the execution of a multiplication and an addition in a single machine cycle; thus permitting the calculation of one filter tap per machine cycle. The circular addressing mo de is an efficient way of implementing the data shifts via a circular buffer . As can be seen from equ ation (1), the arit hmetic of an FIR filter involves filter coefficient multip lications and produc t accumulations (ad ditions). T he parallel mu ltiply/add instruction is optimized for t hese operations. Each coefficient multiplication can be performed in parallel with the running accumulation of the product produced in the previous st ep. Thus , only N instruction cycles are needed t o implement N multiplications and N additions needed to comp ute a length N FIR filter . 1 121 Shift in memory (delay) instr uction Another important par t of an FIR filter is th e time shift of th e input samp les x(n) . At any given tim e, n , th e current input x(n) , and th e previous (N  1) input samp les x (n  1), . .. ,x (n  (N  1» ar e needed to comp ute th e out put y en ), and must be stor ed. Th us, a memory buffer with at least N elements is requ ired to contain th e inp ut samples, x( n), . .. , x (n (N 1 » . When a new samp le arrives, it becomes the curre nt x(n). Before it can be placed in th e first physical locat ion of th e buffer, the other (N 1) old samples must all be shifted downward one location. Th e previous x( n) now becomes x(n  1), the previous x (n  1) becomes x (n  2), etc . and the oldest sample x (n  (N  1» is pushed out of the buffer since it is no longer needed. Implementi ng the sh ift operations in this way (called shifting in memory), we have t o move N samples from one memory location to the n ext . T he TMS320C542 has a sp ecial ins t ruc t ion to do th e shift ing in memory (delay) simu ltan eously with the multiplyaccumulat e operation . This instruction is called MACD(Smem, pmad , src) . First it m ultiplies the value Smem from data memory with th e value pointed to in program memory location pmad . It next adds the product to the source accumulat or (src) value and stores the r esult back into that accum ulator . Finally, t he data memory value (Smem ) is copied in th e T register, and from ther e into th e next higher data memory address. For more information abo ut MACD see page 489 of Reference Set vol.3: Algebraic Instruction Set . Circular ad dressing As an alternative to the funct ion MAC D we can use the original MAC instrucion with circular ad dressing mo de. The circul ar addressing m ode of the TMS3 20C 542 provides a very efficient way to implement the shift operation. Instead of act u ally moving t he dat a aro un d in t he mem ory, an a ddress point er is used that circularly moves within the x(n) buffer . Wh en a new sample x(n) is received, it is not always put in the first location of the bu ffer . Inst e ad , it is stored in the same location as the previous oldest samp le x( n  (N  1», which is no longer needed , so it can be overwritten . From t his locat ion , which now contains x(n), the pointer su ccesively po ints to the next locati on where the current x(n  1) is, an d next to x( n  2), etc. When it reaches the physical end of the buffer , it aut omatical ly r et urns to the beginning to po int on th e first sample (wh ich is not x(n) in general) . The figure below shows t he circular buffer .
response
low address
h( N 1) Impulse initial Input sa~ ronal Input....,..,....
xln) Xln(NI)J
~ _ Input h(N2) Xln(NI)] ldn< 11 N·2 • • •
h(l)
high address
hID) • • •
""west input
x/nI) . x/n) • • •
x(n2) x(nI) U Figure l 2: FIR filter imple mentation with cyclic buffer T he circular addr essin g is a s pecial form of th e indi rect addr essing mode . Since the T MS320C542 has two ARAU (Auxiliary Register Arit hm et ic U n its ) t hat can calculate data addresses independ ently of th e multiplier an d ALU, the shift operat ions can be perform ed at t he same time the coefficients are being multiplied and t he produ cts are being ad ded and , hence, no extr a cycles are required. While the circular addressing mode can use variable step sizes; in th is applica tion, the step is fixed at one (1) . Th e blocksize regis ter BK controls the length of the circular buffer an d should be initialized to N_ For the circular addressing to work p roper ly, th e starting address of the x(n) buffer must be a multiple of the sm allest power of 2 that is gr eater than or equal to N. For example , N = 20 requ ires the first address for x(n) to be a multiple of 25 (the lower 5 bits of the beginning addr ess should be zero). This is needed by the circu lar addressing logic that is based on th e value in the BK register and t h e content of th e auxi liary register ARn that is used as t he po int er. Repeat instruction Another instru cti on that is useful for the implementat ion of FIR filters is the singlerepeat, RPTS, instruct ion. If t he RC register is set to (N I) , the RPTS instruct ion will repeat one single instruction N times without any overhead. T hus, by using the p ar allel multiply /add ins tru ction (in combinat ion with the circular addressing mode), the N coefficient multip lications and product addit ions can be execut ed in N machine cycles. Lowpass filter Ex am ple As an example we will imp lement a 20tap lowpass filter with a stopband edge frequency of approx imately 0.25 Fs (normalized ) and a stopband attenuatio n of approximately 40 dB . The passband edge is ap prox imat ely 0.175 F s . Th e corres pon din g filte r coefficie nt s are shown be low. 2 122 F ilter coefficients for 20tap FIR lowpass filter h(i) h(O) = h(l) = h(2) = h(3) = h(4) = h(5) = h(6 ) = h(7) = h(8) = h(9) = h (Ni) h(19) = h(18) = h(17) = h(16) = h(15) = h(14) = h(13) = h(1 2) = h(l1) = h(10) = val ue 0 .01541467  0.02169395 0.00066375 0.03957745 0.03988632  0.02293868  0.07546433  0.00340502 0.20065564 0.38603673 2 r o•• vaIue  505  711 22 1297 1307  752  2473  112 6575 12650 Sam ple program lin es for FI R di git al filt er impl emen ta tion ARO
A = #XNLAST = #0 repeat (#19) macd( *ARO. hO,A)
~OUTP UT = hi (A) Load ARO with addres s of x(n( N 1» Zero accumul ator A Repeat the next instruct io n 20 times Compute FIR output hO is progr am memory add re ss of h(O) Store t he higher word of ac cumula to r , w hich i s the FIR output y (n) , i nt o OUTPUT 3 123 124 ...
View
Full
Document
This note was uploaded on 11/06/2010 for the course EE 113 taught by Professor Walker during the Spring '08 term at UCLA.
 Spring '08
 Walker
 Digital Signal Processing, Signal Processing, 1984

Click to edit the document details