Applied Signal Processing
Total Page:16
File Type:pdf, Size:1020Kb
APPLIED SIGNAL PROCESSING 2004 Chapter 1 Digital ¯ltering In this section digital ¯lters are discussed, with a focus on IIR (In¯nite Impulse Re- sponse) ¯lters and their applications. The most important kinds of IIR ¯lter prototypes are discussed in section 1.1, and structures used in the implementation of IIR ¯lters are presented in section 1.2. In section 1.3 some important ¯lters designed for special purposes are discussed. Finally, the application of digital ¯ltering will be illustrated in section 1.4 by two case studies: ² Dual-tone multifrequency (DTMF) generation and detection in digital telephony, and ² Plucked-string ¯lters in synthetic music. 1.1 IIR ¯lter prototypes An IIR ¯lter of order N is described by the di®erence equation y(n) + a1y(n ¡ 1) + ¢ ¢ ¢ + aN y(n ¡ N) = b0x(n) + b1x(n ¡ 1) + ¢ ¢ ¢ + bM x(n ¡ M) (1.1) and it has the transfer function N N¡1 N¡M b0z + b1z + ¢ ¢ ¢ + bM z H(z) = N N¡1 (1.2) z + a1z + ¢ ¢ ¢ + aN IIR ¯lters provide more flexibility than FIR ¯lters due to the feedback from previous outputs. Compared to FIR ¯lters, the denominator polynomial of H(z) provides more freedom to shape the frequency response of the ¯lter. Therefore an IIR ¯lter which achieves a given set of speci¯cations is usually simpler and has much fewer parameters than a FIR ¯lters designed for the same speci¯cations. This property makes IIR ¯lters well suited for a number of applications. On the other hand, IIR ¯lters have some limitations which one should be aware of. Firstly, high-order IIR ¯lters are very sensitive to quantization errors in the coe±cients, 1 which is due to the feedback from previous ¯lter outputs y(n¡k). Quantization e®ects can therefore severely degrade the ¯lter performance, or even make it unstable. In practice this problem can, however, be overcome by using ¯lter implementations which are less sensitive to rounding errors. Secondly, in contrast to FIR ¯lters it is not possible to achieve exact linear phase shift with IIR ¯lters. IIR ¯lters can, however, be designed to achieve an approximately linear phase shift in a frequency band. Morevover, in o®- line (i.e., not real-time) computations, we will see that the ¯ltering of a signal can always be arranged in a way which guarantees zero phase shift. Standard IIR lowpass, highpass, bandpass and bandstop ¯lters are usually designed using a set of standard IIR ¯lter prototypes. These have originally been obtained from classical analog ¯lter prototypes using the bilinear transformation, which takes a continuous-time ¯lter to a discrete-time ¯lter in a way which preserves the general form (lowpass, highpass etc) of the frequency response. The digital prototype ¯lters can, however, also be derived without referring to their analog counterparts. In order to construct digital IIR ¯lters we need a building block whose frequency response magnitude varies with frequency. The transform variable z¡1 is not suitable, as its frequency response e¡j! has a constant magnitude for all frequencies. It turns out that a very useful building block is given by the function 1 ¡ z¡1 z ¡ 1 F (z) = = (1.3) 1 + z¡1 z + 1 which has the frequency response ej! ¡ 1 ej!=2 ¡ e¡j!=2 F (ej!) = = = j tan(!=2) (1.4) ej! + 1 ej!=2 + e¡j!=2 Hence the frequency response of F (z) has an amplitude which grows from zero at ! = 0 to in¯nity at ! = ¼, and the constant phase ¼=2 (90±). This can be exploited as follows. De¯ne the ¯lter 1 H(z) = (1.5) 1 + F (z)= tan(!c=2) Using (1.4), its frequency response is given by jH(ej!)j2 = H(ej!)H(e¡j!) Ã !Ã ! 1 1 = 1 + j tan(!=2)= tan(!c=2) 1 ¡ j tan(!=2)= tan(!c=2) 1 = 2 (1.6) 1 + [tan(!=2)= tan(!c=2)] Hence H(z) is a simple lowpass ¯lter with H(ej!) = 1 for ! = 0, H(ej!) = 0 for ! = ¼, and the cuto® frequency !c. All the IIR ¯lter prototypes discussed below are obtained by various generalizations of this idea. The most important digital IIR ¯lter prototypes are the Butterworth, Chebyshev and elliptic ¯lters. They are characterized by the form of their magnitude frequency 2 responses. Butterworth ¯lters have a monotonically varying response in both passband and stopband. Chebyshev ¯lters of type I have an equiripple response in the passband and a monotonic response in the stopband, whereas type II Chebyshev ¯lters have a monotonic response in the passband and equiripple response in the stopband. Elliptic ¯lters have an equiripple response in both bands. The ¯lters are usually derived as lowpass ¯lters, from which the other ¯lter types (highpass, bandpass and bandstop) are obtained by frequency transformations (see below). The standard ¯lter types are all based on the building block (1.3). Thus, (1.5) is a Butterworth ¯lter of order one with the frequency response de¯ned by (1.6). By replacing the denominator of (1.6) by a Chebyshev polynomial with argument tan(!=2)= tan(!c=2) gives a Chebyshev ¯lter, while using an elliptic function results in an elliptic ¯lter. Butterworth ¯lters. A digital low-pass Butterworth ¯lter BN (z) is a generalization of (1.5) and is con- structed in such a way that the magnitude of its frequency response (gain) is " #1=2 j! 1 jBN (e )j = 2N (1.7) 1 + [tan(!=2)= tan(!c=2)] where N is the ¯lter order and !c is the cuto® frequency. We can see that the frequency j! response magnitude is monotonically decreasing, with BN (e ) = 1 at ! = 0 and j! BN (e ) = 0 at thep Nyquist frequency ! = ¼. At the cuto® frequency !c, the gain j!c is jBN (e )j = 1= 2. Increasing ¯lter order N results in a steeper transition from passband to stopband. Digital Butterworth ¯lters can be synthesized with the Matlab routine [B,A]=butter(N,Wn,'ftype') where Wn denotes the cuto® frequency or, for a bandpass ¯lter, information about the passband. The frequencies are normalized to the interval 0 < Wn < 1, where Wn = 1 corresponds to half the sampling frequency, i.e., ¼ radians per sample. For a lowpass or bandpass ¯lter ftype is omitted, whereas ftype=high or stop is used if a highpass or bandstop ¯lter is designed. The outputs B and A are vectors with the coe±cients of the numerator and denominator polynomials, respectively (cf. equation (1.2). The required minimum order of a digital Butterworth ¯lter for a given set of speci¯cations can be determined with [N,Wn]=buttord(Wp,Ws,Rp,Rs). where Wp and Ws are the normalized passband and stopband edge frequencies, Rp is the maximum deviation in the passband (in dB), and Rs is the minimum attenuation in the stopband (in dB). Chebyshev ¯lters. There are two types of Chebyshev ¯lters. The gain of a Chebyshev ¯lter of type I is equiripple in the passband and monotonically decreasing in the stopband, whereas 3 a Chebyshev ¯lter of type II has a monotonically varying gain in the passband and is equiripple in the stopband. Chebyshev ¯lters involve the Chebyshev polynomials CN [x]. A lowpass Chebyshev ¯lter HN (z) of type I is de¯ned in such a way that it has the frequency response magnitude " #1=2 j! 1 jHN (e )j = 2 2 (1.8) 1 + ² CN [tan(!=2)= tan(!c=2)] where N is the ¯lter order, !c is the cuto® frequency, and ² is a parameter which a®ects the passband ripples. Digital Chebyshev ¯lters can be synthesized with the Matlab routines [B,A]=cheby1(N,Rp,Wn,'ftype') and [B,A]=cheby2(N,Rs,Wn,'ftype'), respectively. The minimum order of digital Chebyshev ¯lters required to achieve a given set of speci¯cations can be determined with [N,Wn]=cheb1ord(Wp,Ws,Rp,Rs) or [N,Wn]=cheb2ord(Wp,Ws,Rp,Rs). Elliptic ¯lters. Elliptic ¯lters have equiripple frequency responses in both the passband and the stop- band. The frequency response magnitude of an elliptic ¯lter of order N is given by " #1=2 j! 1 jHN (e )j = 2 2 (1.9) 1 + ² GN [tan(!=2)= tan(!c=2)] where GN [x] is a rational elliptic function of order N, !c is the cuto® frequency, and ² is a parameter which a®ects the passband ripples. Digital elliptic ¯lters can be synthesized with the Matlab routine [B,A]=ellip(N,Rp,Rs,Wn,'ftype') The required minimum order of a digital elliptic ¯lter for a given set of speci¯cations can be determined with [N,Wn]=ellipord(Wp,Ws,Rp,Rs). Elliptic ¯lters have the important property that they achieve a given set of speci¯cations on the frequency response magnitude with the lowest ¯lter order. This can be compared to the optimal FIR ¯lters, which also have equiripple frequency responses. Elliptic ¯lters are therefore the preferred ¯lter type in IIR ¯lter design. However, elliptic ¯lters have a less linear phase response in the passband than the Butterworth or Chebyshev ¯lters. In applications where the phase response is important these ¯lter types should be considered. 4 Remark 1.1 Observe that all the ¯lters described above have their classical, analogue counterparts. The analog ¯lters are formed in an analogous manner using the building block Fa(s) = s instead of (1.3). Note that Fa(s) has the frequency response Fa(j!) = j!. In analogy with (1.3) the frequency response of Fa(s) has an amplitude which grows from zero at ! = 0 to in¯nity at in¯nite !, and the constant phase ¼=2 (90±).