Tài liệu Real time digital signal processing P5 docx

59 319 0
Tài liệu Real time digital signal processing P5 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

5 Design and Implementation of FIR Filters A filter is a system that is designed to alter the spectral content of input signals in a specified manner. Common filtering objectives include improving signal quality, extracting information from signals, or separating signal components that have been previously combined. A digital filter is a mathematical algorithm implemented in hard- ware, firmware, and/or software that operates on a digital input signal to produce a digital output signal for achieving filtering objectives. A digital filter can be classified as being linear or nonlinear, time invariant or varying. This chapter is focused on the design and implementation of linear, time-invariant (LTI) finite impulse response (FIR) filters. The time-invariant infinite impulse response (IIR) filters will be discussed in Chapter 6, and the time-varying adaptive filters are introduced in Chapter 8. The process of deriving the digital filter transfer function H(z) that satisfies the given set of specifications is called digital filter design. Although many applications require only simple filters, the design of more complicated filters requires the use of sophisticated techniques. A number of computer-aided design tools (such as MATLAB) are available for designing digital filters. Even though such tools are widely available, we should understand the basic characteristics of digital filters and familiar with techniques used for implementing digital filters. Many DSP books devote substantial efforts to the theory of designing digital filters, especially approximation methods, reflecting the considerable work that has been done for calculating and optimizing filter coefficients. 5.1 Introduction to Digital Filters As discussed in previous chapters, filters can be divided into two categories: analog filters and digital filters. Similar specifications are used for both analog and digital filters. In this chapter, we will discuss digital filters exclusively. The digital filters are assumed to have a single input x(n), and a single output y(n). Analog filters are used as design prototypes for digital IIR filters, and will be briefly introduced in Chapter 6. Real-Time Digital Signal Processing. Sen M Kuo, Bob H Lee Copyright # 2001 John Wiley & Sons Ltd ISBNs: 0-470-84137-0 (Hardback); 0-470-84534-1 (Electronic) 5.1.1 Filter Characteristics A digital filter is said to be linear if the output due to the application of input, xna 1 x 1 na 2 x 2 n, 5:1:1 is equal to yna 1 y 1 na 2 y 2 n, 5:1:2 where a 1 and a 2 are arbitrary constants, and y 1 n and y 2 n are the filter outputs due to the application of the inputs x 1 n and x 2 n, respectively. The important property of linearity is that in the computation of y(n) due to x(n), we may decompose x(n) into a summation of simpler components x i n. We then compute the response y i n due to input x i n. The summation of y i n will be equal to the output y(n). This property is also called the superposition. A time-invariant system is a system that remains unchanged over time. A digital filter is time-invariant if the output due to the application of delayed input xn À m is equal to the delayed output yn À m, where m is a positive integer. It means that if the input signal is the same, the output signal will always be the same no matter what instant the input signal is applied. It also implies that the characteristics of a time-invariant filter will not change over time. A digital filter is causal if the output of the filter at time n 0 does not depend on the input applied after n 0 . It depends only on the input applied at and before n 0 . On the contrary, the output of a non-causal filter depends not only on the past input, but also on the future input. This implies that a non-causal filter is able to predict the input that will be applied in the future. This is impossible for any real physical filter. Linear, time-invariant filters are characterized by magnitude response, phase response, stability, rise time, settling time, and overshoot. Magnitude response specifies the gains (amplify, pass, or attenuate) of the filter at certain frequencies, while phase response indicates the amount of phase changed by the filter at different frequencies. Magnitude and phase responses determine the steady-state response of the filter. For an instantaneous change in input, the rise time specifies an output-changing rate. The settling time describes an amount of time for the output to settle down to a stable value, and the overshoot shows if the output exceeds the desired output value. The rise time, the settling time, and the overshoot specify the transient response of the filter in the time domain. A digital filter is stable if, for every bounded input signal, the filter output is bounded. A signal x(n) is bounded if its magnitude jxnj does not go to infinity. A digital filter with the impulse response h(n) is stable if and only if  I n0 jhnj < I: 5:1:3 Since an FIR filter has only a finite number of non-zero h(n), the FIR filter is always stable. Stability is critical in DSP implementations because it guarantees that the filter 182 DESIGN AND IMPLEMENTATION OF FIR FILTERS output will never grow beyond bounds, thus avoiding numerical overflow in computing the convolution sums. As mentioned earlier, filtering is a process that passes certain frequency components in a signal through the system and attenuates other frequency components. The range of frequencies that is allowed to pass through the filter is called the passband, and the range of frequencies that is attenuated by the filter is called the stopband. If a filter is defined in terms of its magnitude response, there are four different types of filters: lowpass, highpass, bandpass, and bandstop filters. Each ideal filter is characterized by a passband over which frequencies are passed unchanged (except with a delay) and a stopband over which frequencies are rejected completely. The two-level shape of the magnitude response gives these filters the name brickwall. Ideal filters help in analyzing and visualizing the processing of actual filters employed in signal processing. Achieving an ideal brickwall characteristic is not feasible, but ideal filters are useful for concep- tualizing the impact of filters on signals. As discussed in Chapter 3, there are two basic types of digital filters: FIR filters and IIR filters. An FIR filter of length L can be represented with its impulse response h(n) that has only L non-zero samples. That is, hn0 for all n ! L. An FIR filter is also called a transversal filter. Some advantages and disadvantages of FIR filters are sum- marized as follows: 1. Because there is no feedback of past outputs as defined in (3.1.16), the FIR filters are always stable. That is, a bounded input results in a bounded output. This inherent stability is also manifested in the absence of poles in the transfer function as defined in (4.3.8), except possibly at the origin. 2. The filter has finite memory because it `forgets' all inputs before the L À 1th previous one. 3. The design of linear phase filters can be guaranteed. In applications such as audio signal processing and data transmission, linear phase filters are preferred since they avoid phase distortion. 4. The finite-precision errors (discussed in Chapter 3) are less severe in FIR filters than in IIR filters. 5. FIR filters can be easily implemented on most DSP processors such as the TMS320C55x introduced in Chapter 2. 6. A relatively higher order FIR filter is required to obtain the same characteristics as compared with an IIR filter. Thus more computations are required, and/or longer time delay may be involved in the case of FIR filters. 5.1.2 Filter Types An ideal frequency-selective filter passes certain frequency components without any change and completely stops the other frequencies. The range of frequencies that are INTRODUCTION TO DIGITAL FILTERS 183 passed without attenuation is the passband of the filter, and the range of frequencies that is attenuated is the stopband. Thus the magnitude response of an ideal filter is given by jH!j  1 in the passband and jH!j  0 in the stopband. Note that the frequency response H! of a digital filter is a periodic function of !, and the magnitude response jH!j of a digital filter with real coefficients is an even function of !. Therefore the digital filter specifications are given only for the range 0 ! p. The magnitude response of an ideal lowpass filter is illustrated in Figure 5.1(a). The regions 0 ! ! c and !>! c are referred to as the passband and stopband, respec- tively. The frequency that separates the passband and stopband is called the cut-off frequency ! c . An ideal lowpass filter has magnitude response jH!j  1 in the fre- quency range 0 ! ! c and has jH!j  0 for !>! c . Thus a lowpass filter passes all low-frequency components below the cut-off frequency and attenuates all high-fre- quency components above ! c . Lowpass filters are generally used when the signal components of interest are in the range of DC to the cut-off frequency, but other higher frequency components (or noise) are present. The magnitude response of an ideal highpass filter is illustrated in Figure 5.1(b). The regions ! ! ! c and 0 !<! c are referred to as the passband and stopband, respec- tively. A highpass filter passes all high-frequency components above the cut-off fre- quency ! c and attenuates all low-frequency components below ! c . As discussed in Chapter 1, highpass filters can be used to eliminate DC offset, 60 Hz hum, and other low frequency noises. The magnitude response of an ideal bandpass filter is illustrated in Figure 5.1(c). The regions !<! a and !>! b are referred to as the stopband. The frequencies ! a and ! b are called the lower cut-off frequency and the upper cut-off frequency, respectively. The H(w) H(w) H(w) H(w) w 1 0 w c p 0 w a w b p 0 w a w b p 0 w c p w 1 (a) (b) ww 1 1 (c) (d) Figure 5.1 Magnitude response of ideal filters: (a) lowpass, (b) highpass, (c) bandpass, and (d) bandstop 184 DESIGN AND IMPLEMENTATION OF FIR FILTERS region ! a ! ! b is called the passband. A bandpass filter passes all frequency components between the two cut-off frequencies ! a and ! b , and attenuates all fre- quency components below the frequency ! a and above the frequency ! b . If the passband is narrow, it is more common to specify the center frequency and the bandwidth of the passband. A narrow bandpass filter may be called a resonator (or peaking) filter. The magnitude response of an ideal bandstop (or band-reject) filter is illustrated in Figure 5.1(d). The regions ! ! a and ! ! ! b are referred to as the passband. The region ! a <!<! b is called the stopband. A bandstop filter attenuates all fre- quency components between the two cutoff frequencies ! a and ! b , and passes all frequency components below the frequency ! a and above the frequency ! b . A narrow bandstop filter designed to attenuate a single frequency component is called a notch filter. For example, a common source of noise is a power line generating a 60 Hz sinusoidal signal. This noise can be removed by passing the corrupted signal through a notch filter with notch frequency at 60 Hz. The design of simple notch filters was introduced in Section 4.5.1. In addition to these frequency-selective filters, an allpass filter provides frequency response jH!j  1 for all frequency !, thus passing all frequencies with uniform gain. These filters do not remove frequency components, but alter the phase response. The principal use of allpass filters is to correct the phase distortion introduced by the physical system and/or other filters. For example, it is used as a delay equalizer. In this application, it is designed such that when cascaded with another digital system, the overall system has a constant group delay in the frequency range of interest. A very special case of the allpass filter is the ideal Hilbert transformer, which produces a 908 phase shift of input signals. 5.1.3 Filter Specifications In practice, we cannot achieve the infinitely sharp cutoff implied by the ideal filters shown in Figure 5.1. This will be shown later by considering the impulse response of the ideal lowpass filter that is non-causal and hence not physically realizable. Instead we must compromise and accept a more gradual cutoff between passband and stopband, as well as specify a transition band between the passband and stopband. The design is based on magnitude response specifications only, so the phase response of the filter is not controlled. Whether this is important depends on the application. Realizable filters do not exhibit the flat passband or the perfect linear phase characteristic. The deviation of jH!j from unity (0 dB) in the passband is called magnitude distortion, and the deviation from the linear phase of the phase response H! is called phase distortion. The characteristics of digital filters are often specified in the frequency domain. For frequency-selective filters, the magnitude response specifications of a digital filter are often given in the form of tolerance (or ripple) schemes. In addition, a transition band is specified between the passband and the stopband to permit the magnitude drop off smoothly. A typical magnitude response of lowpass filter is shown in Figure 5.2. The dotted horizontal lines in the figure indicate the tolerance limits. In the passband, the magnitude response has a peak deviation d p and in the stopband, it has a maximum deviation d s . The frequencies ! p and ! s are the passband edge (cut-off) frequency and the stopband edge frequency, respectively. INTRODUCTION TO DIGITAL FILTERS 185 Passband A p A s Stopband 1+d p 1−d p 0 w p w c w s d s H ( w ) w p Ideal filter Actual filter Transition band 1 Figure 5.2 Magnitude response and performance measurement of a lowpass filter As shown in Figure 5.2, the magnitude of passband defined by 0 ! ! p approxi- mates unity with an error of Æd p . That is, 1 À d p jH!j 1  d p ,0 ! ! p : 5:1:4 The passband ripple, d p , is a measure of the allowed variation in magnitude response in the passband of the filter. Note that the gain of the magnitude response is normalized to 1 (0 dB). In practical applications, it is easy to scale the filter output by multiplying the output by a constant, which is equivalent to multiplying the whole magnitude response by the same constant gain. In the stopband, the magnitude approximates 0 with an error d s . That is, jH!j d s , ! s ! p: 5:1:5 The stopband ripple (or attenuation) describes the maximum gain (or minimum attenuation) for signal components above the ! s . Passband and stopband deviations may be expressed in decibels. The peak passband ripple, d p , and the minimum stopband attenuation, d s , in decibels are given as A p  20 log 10 1  d p 1 À d p  dB 5:1:6 and A s À20 log 10 d s dB: 5:1:7 Thus we have 186 DESIGN AND IMPLEMENTATION OF FIR FILTERS d p  10 A p =20 À 1 10 A p =20  1 5:1:8 and d s  10 ÀA s =20 : 5:1:9 Example 5.1: Consider a filter specified as having a magnitude response in the passband within Æ0:01. That is, d p  0:01. From (5.1.6), we have A p  20 log 10 1:01 0:99   0:1737 dB: When the minimum stopband attenuation is given as d s  0:01, we have A s À20 log 10 0:0140 dB: The transition band is the area between the passband edge frequency ! p and the stopband edge frequency ! s . The magnitude response decreases monotonically from the passband to the stopband in this region. Generally, the magnitude in the transition band is left unspecified. The width of the transition band determines how sharp the filter is. It is possible to design filters that have minimum ripple over the passband, but a certain level of ripple in this region is commonly accepted in exchange for a faster roll-off of gain in the transition band. The stopband is chosen by the design specifications. Generally, the smaller d p and d s are, and the narrower the transition band, the more complicated (higher order) the designed filter becomes. An example of a narrow bandpass filter is illustrated in Figure 5.3. The center frequency ! m is the point of maximum gain (or maximum attenuation for a notch filter). If a logarithm scale is used for frequency such as in many audio applications, the center frequency at the geometric mean is expressed as ! m   ! a ! b p , 5:1:10a H(w) w 1 2 1 w a w m w b Figure 5.3 Magnitude response of bandpass filter with narrow bandwidth INTRODUCTION TO DIGITAL FILTERS 187 where ! a and ! b are the lower and upper cut-off frequencies, respectively. The bandwidth is the difference between the two cut-off frequencies for a bandpass filter. That is, BW  ! b À ! a : 5:1:10b The 3-dB bandwidth commonly used in practice is defined as jH! a j  jH! b j  1  2 p  0:707: 5:1:11 Another way of describing a resonator (or notch) filter is the quality factor defined as Q  ! m 2pBW : 5:1:12 There are many applications that require high Q filters. When a signal passes through a filter, it is modified both in amplitude and phase. The phase response is an important filter characteristic because it affects time delay of the different frequency components passing through the filter. If we consider a signal that consists of several frequency components, the phase delay of the filter is the average time delay the composite signal suffers at each frequency. The group delay function is defined as T d ! Àdf! d! , 5:1:13 where f! is the phase response of the filter. A filter is said to have a linear phase if its phase response satisfies f!Àa!, À p ! p 5:1:14 or f!b À a!, À p ! p 5:1:15 These equations show that for a filter with a linear phase, the group delay T d ! given in (5.1.13) is a constant a for all frequencies. This filter avoids phase distortion because all sinusoidal components in the input are delayed by the same amount. A filter with a nonlinear phase will cause a phase distortion in the signal that passes through it. This is because the frequency components in the signal will each be delayed by a different amount, thereby altering their harmonic relationships. Linear phase is important in data communications, audio, and other applications where the temporal relationships between different frequency components are critical. The specifications on the magnitude and phase (or group delay) of H! are based on the steady-state response of the filter. Therefore they are called the steady-state speci- fications. The speed of the response concerns the rate at which the filter reaches the steady-state response. The transient performance is defined for the response right after 188 DESIGN AND IMPLEMENTATION OF FIR FILTERS the application of an input signal. A well-designed filter should have a fast response, a small rise time, a small settling time, and a small overshoot. In theory, both the steady-state and transient performance should be considered in the design of a digital filter. However, it is difficult to consider these two specifications simultaneously. In practice, we first design a filter to meet the magnitude specifications. Once this filter is obtained, we check its phase response and transient performance. If they are satisfactory, the design is completed. Otherwise, we must repeat the design process. Once the transfer function has been determined, we can obtain a realization of the filter. This will be discussed later. 5.2 FIR Filtering The signal-flow diagram of the FIR filter is shown in Figure 3.6. As discussed in Chapter 3, the general I/O difference equation of FIR filter is expressed as ynb 0 xnb 1 xn À 1ÁÁÁb LÀ1 xn À L  1  LÀ1 l0 b l xn À l, 5:2:1 where b l are the impulse response coefficients of the FIR filter. This equation describes the output of the FIR filter as a convolution sum of the input with the impulse response of the system. The transfer function of the FIR filter defined in (5.2.1) is given by Hzb 0  b 1 z À1 ÁÁÁb LÀ1 z ÀLÀ1   LÀ1 l0 b l z Àl : 5:2:2 5.2.1 Linear Convolution As discussed in Section 3.2.2, the output of the linear system defined by the impulse response h(n) for an input signal x(n) can be expressed as ynxnÃhn  I lÀI hlxn À l: 5:2:3 Thus the output of the LTI system at any given time is the sum of the input samples convoluted by the impulse response coefficients of the system. The output at time n 0 is given as yn 0   I lÀI hlxn 0 À l: 5:2:4 Assuming that n 0 is positive, the process of computing the linear convolution involves the following four steps: FIR FILTERING 189 1. Folding. Fold x(l) about l  0 to obtain xÀl. 2. Shifting. Shift xÀl by n 0 samples to the right to obtain xn 0 À l. 3. Multiplication. Multiply h(l)byxn 0 À l to obtain the products hlÁxn 0 À l for all l. 4. Summation. Sum all the products to obtain the output yn 0  at time n 0 . Repeat steps 2±4 in computing the output of the system at other time instants n 0 . This general procedure of computing convolution sums can be applied to (5.2.1) for calculating the FIR filter output y(n). As defined in (3.2.15), the impulse response of the FIR filter is hl 0, l < 0 b l ,0 l < L 0, l ! L. @ 5:2:5 If the input signal is causal, the general linear convolution equation defined in (5.2.3) can be simplified to (5.2.1). Note that the convolution of the length M input with the length L impulse response results in length L  M À 1 output. Example 5.2: Consider an FIR filter that consists of four coefficients b 0 , b 1 , b 2 , and b 3 . From (5.2.1), we have yn  3 l0 b l xn À l, n ! 0: This yields n  0, y0b 0 x0, n  1, y1b 0 x1b 1 x0, n  2, y2b 0 x2b 1 x1b 2 x0, n  3, y3b 0 x3b 1 x2b 2 x1b 3 x0: In general, we have ynb 0 xnb 1 xn À 1b 2 xn À 2b 3 xn À 3, n ! 3: The graphical interpretation is illustrated in Figure 5.4. As shown in Figure 5.4, the input sequence is flipped around (folding) and then shifted to the right over the filter coefficients. At each time instant, the output value is the sum of products of overlapped coefficients with the corresponding input data 190 DESIGN AND IMPLEMENTATION OF FIR FILTERS [...]... applications where data is already collected and stored for later processing, i.e., the processing is not done in real time In these cases, the `current' time n can be located arbitrarily as the data is processed, so that the current output of the filter may depend on past, current, and future input values Such a filter is `non-realizable' in real time, but is easy to implement for the stored data The non-causal... IMPLEMENTATION OF FIR FILTERS Coefficients buffer Signal buffer b0 x(n − 2) bL−1 x(n) x(n − 1) b2 Figure 5.10 x(n) b1 x (n − L + 1) Tables of coefficient vector and signal buffer x(n − 1) x(n − 2) x(n − L + 2)x(n − L + 1) Current Time, n Next data x(n) Discarded x(n − 1) x(n − 2) Figure 5.11 x(n − L + 1) Next time, n+1 Refreshing the signal buffer for FIR filtering The signal buffer is refreshed in every sampling... x…n À L ‡ 1† is discarded and other signals are shifted one location to the right in the buffer A new sample (from ADC in real- time application) is inserted to the memory location labeled as x(n) The FIR filtering operation that computes y(n) using (5.2.29) is then performed The process of refreshing the signal buffer shown in Figure 5.11 requires intensive processing time if the operation is not implemented... with coefficients f0:25, 0:5, 0:25g for smoothing estimated pitch in speech processing 5.2.4 Realization of FIR Filters An FIR filter can be realized to operate either on a block basis or a sample-by-sample basis In the block processing case, the input is segmented into multiple blocks Filtering is performed on one block at a time, and the resulting output blocks are recombined to form the overall output... expressed as M ˆ H H …z† ˆ hH …n†zÀn : …5:3:6† nˆÀM It is clear that this filter is not physically realizable in real time since the filter must produce an output that is advanced in time with respect to the input A causal FIR filter can be derived by delaying the hH …n† sequence by M samples That is, by shifting the time origin to the left of the vector and re-indexing the coefficients as bHl ˆ hH …l À M†,... samples x(n) and x…n À L† in the circular 201 DESIGN OF FIR FILTERS Signal buffer pointer for next x(n) x(n − L + 1) x(n − L + 2) Coefficient buffer pointer Signal buffer pointer at time n x(n) x(n − 1) bL−2 b0 bL−1 b2 x(n − 2) x(n − 3) (a) b1 b3 (b) Figure 5.12 Circular buffers for FIR filter: (a) circular buffer for holding the signals for FIR filtering The pointer to x…n† is updated in the counterclockwise... x…n À L ‡ 1† and we wait for the next input signal The next input at time n ‡ 1 is written to the x…n À L ‡ 1† position, and is referred to as x(n) for the next iteration This is permitted because the old x…n À L ‡ 1† signal dropped off the end of our delay chain after the previous calculation as shown in Figure 5.11 The circular buffer implementation of a signal buffer, or a tapped-delay-line is very... hardware The most efficient method for handling a signal buffer is to load the signal samples into a circular buffer, as illustrated in Figure 5.12(a) Instead of shifting the data forward while holding the buffer addresses fixed, the data is kept fixed and the addresses are shifted backwards (counterclockwise) in the circular buffer The beginning of the signal sample, x(n), is pointed at with a pointer... 5.10 In order to compute the output at any time, we simply have to multiply the corresponding values in each table and sum the results That is, y…n† ˆ b0 x…n† ‡ b1 x…n À 1† ‡ Á Á Á ‡ bLÀ1 x…n À L ‡ 1†: …5:2:29† In FIR filtering, the coefficient values are constant, but the data in the signal buffer changes every sampling period, T That is, the x(n) value at time n becomes x…n À 1† in the next sampling... 1 zeros to its right At time n ˆ 0, the only non-zero product comes from b0 and x(0) which are time aligned It takes the filter L À 1 iterations before it is completely overlapped with the input sequence The first L À 1 outputs correspond to the transient behavior of the FIR filter For n ! L À 1, the filter aligns over the non-zero portion of the input sequence That is, the signal buffer of FIR filter . used as design prototypes for digital IIR filters, and will be briefly introduced in Chapter 6. Real- Time Digital Signal Processing. Sen M Kuo, Bob H Lee. collected and stored for later processing, i.e., the processing is not done in real time. In these cases, the `current' time n can be located arbitrarily

Ngày đăng: 24/12/2013, 01:16