Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Digital Signal Processing. The Scientist and Engineers Guide. Steven W. Smith

.pdf
Скачиваний:
166
Добавлен:
02.05.2014
Размер:
7 Мб
Скачать
☆

fC

0.01

0.025

0.05

0.075

0.1

0.15

0.2

0.25

0.3

0.35

0.40

0.45

Chapter 20Chebyshev Filters

337

 

2 Pole

 

4 Pole

 

6 Pole

 

 

 

a0=

9.567529E-01

 

a0=

9.121579E-01

(!! Unstable !!)

a0=

8.630195E-01

(!! Unstable !!)

a1= -1.913506E+00

b1= 1.911437E+00

a1= -3.648632E+00

b1= 3.815952E+00

a1= -5.178118E+00

b1= 5.705102E+00

a2=

9.567529E-01

b2= -9.155749E-01

a2=

5.472947E+00

b2= -5.465026E+00

a2=

1.294529E+01

b2= -1.356935E+01

 

 

 

a3= -3.648632E+00

b3= 3.481295E+00

a3= -1.726039E+01

b3= 1.722231E+01

 

 

 

a4=

9.121579E-01

b4= -8.322529E-01

a4=

1.294529E+01

b4= -1.230214E+01

 

 

 

 

 

 

a5= -5.178118E+00

b5= 4.689218E+00

 

 

 

 

 

 

a6=

8.630195E-01

b6= -7.451429E-01

a0=

8.950355E-01

 

a0=

7.941874E-01

 

a0=

6.912863E-01

(!! Unstable !!)

a1= -1.790071E+00

b1= 1.777932E+00

a1= -3.176750E+00

b1= 3.538919E+00

a1= -4.147718E+00

b1= 5.261399E+00

a2=

8.950355E-01

b2= -8.022106E-01

a2=

4.765125E+00

b2= -4.722213E+00

a2=

1.036929E+01

b2= -1.157800E+01

 

 

 

a3= -3.176750E+00

b3= 2.814036E+00

a3= -1.382573E+01

b3= 1.363599E+01

 

 

 

a4=

7.941874E-01

b4= -6.318300E-01

a4=

1.036929E+01

b4= -9.063840E+00

 

 

 

 

 

 

a5= -4.147718E+00

b5= 3.223738E+00

 

 

 

 

 

 

a6=

6.912863E-01

b6= -4.793541E-01

a0=

8.001102E-01

 

a0=

6.291694E-01

 

a0=

4.760636E-01

 

a1= -1.600220E+00

b1= 1.556269E+00

a1= -2.516678E+00

b1= 3.077062E+00

a1= -2.856382E+00

b1= 4.522403E+00

a2=

8.001102E-01

b2= -6.441715E-01

a2=

3.775016E+00

b2= -3.641324E+00

a2=

7.140954E+00

b2= -8.676846E+00

 

 

 

a3= -2.516678E+00

b3= 1.949230E+00

a3= -9.521272E+00

b3= 9.007515E+00

 

 

 

a4=

6.291694E-01

b4= -3.990947E-01

a4=

7.140954E+00

b4= -5.328431E+00

 

 

 

 

 

 

a5= -2.856382E+00

b5= 1.702544E+00

 

 

 

 

 

 

a6=

4.760636E-01

b6= -2.303304E-01

a0=

7.142028E-01

 

a0=

4.965350E-01

 

a0=

3.259100E-01

 

a1= -1.428406E+00

b1= 1.338264E+00

a1= -1.986140E+00

b1= 2.617304E+00

a1= -1.955460E+00

b1= 3.787397E+00

a2=

7.142028E-01

b2= -5.185469E-01

a2=

2.979210E+00

b2= -2.749252E+00

a2=

4.888651E+00

b2= -6.288362E+00

 

 

 

a3= -1.986140E+00

b3= 1.325548E+00

a3= -6.518201E+00

b3= 5.747801E+00

 

 

 

a4=

4.965350E-01

b4= -2.524546E-01

a4=

4.888651E+00

b4= -3.041570E+00

 

 

 

 

 

 

a5= -1.955460E+00

b5= 8.808669E-01

 

 

 

 

 

 

a6=

3.259100E-01

b6= -1.122464E-01

a0=

6.362307E-01

 

a0=

3.896966E-01

 

a0=

2.211833E-01

 

a1= -1.272461E+00

b1= 1.125379E+00

a1= -1.558786E+00

b1= 2.161179E+00

a1= -1.327100E+00

b1= 3.058671E+00

a2=

6.362307E-01

b2= -4.195440E-01

a2=

2.338179E+00

b2= -2.033991E+00

a2=

3.317750E+00

b2= -4.390464E+00

 

 

 

a3= -1.558786E+00

b3= 8.789094E-01

a3= -4.423667E+00

b3= 3.523252E+00

 

 

 

a4=

3.896966E-01

b4= -1.610655E-01

a4=

3.317750E+00

b4= -1.684184E+00

 

 

 

 

 

 

a5= -1.327100E+00

b5= 4.414878E-01

 

 

 

 

 

 

a6=

2.211833E-01

b6= -5.767508E-02

a0=

5.001024E-01

 

a0=

2.340973E-01

 

a0=

9.792321E-02

 

a1= -1.000205E+00

b1= 7.158993E-01

a1= -9.363892E-01

b1= 1.263672E+00

a1= -5.875393E-01

b1= 1.627573E+00

a2=

5.001024E-01

b2= -2.845103E-01

a2=

1.404584E+00

b2= -1.080487E+00

a2=

1.468848E+00

b2= -1.955020E+00

 

 

 

a3= -9.363892E-01

b3= 3.276296E-01

a3= -1.958464E+00

b3= 1.075051E+00

 

 

 

a4=

2.340973E-01

b4= -7.376791E-02

a4=

1.468848E+00

b4= -5.106501E-01

 

 

 

 

 

 

a5= -5.875393E-01

b5= 7.239843E-02

 

 

 

 

 

 

a6=

9.792321E-02

b6= -2.639193E-02

a0=

3.849163E-01

 

a0=

1.335566E-01

 

a0=

3.997486E-02

 

a1= -7.698326E-01

b1= 3.249116E-01

a1= -5.342262E-01

b1= 3.904484E-01

a1= -2.398492E-01

b1= 2.441149E-01

a2=

3.849163E-01

b2= -2.147536E-01

a2=

8.013393E-01

b2= -6.784138E-01

a2=

5.996230E-01

b2= -1.130306E+00

 

 

 

a3= -5.342262E-01

b3= 1.412016E-02

a3= -7.994973E-01

b3= -1.063169E-01

 

 

 

a4=

1.335566E-01

b4= -5.392238E-02

a4=

5.996230E-01

b4= -3.463299E-01

 

 

 

 

 

 

a5= -2.398492E-01

b5= -8.882996E-02

 

 

 

 

 

 

a6=

3.997486E-02

b6= -3.278741E-02

a0=

2.858111E-01

 

a0=

7.015302E-02

 

a0=

1.434450E-02

 

a1= -5.716222E-01

b1= -5.423243E-02

a1= -2.806121E-01

b1= -4.541478E-01

a1= -8.606701E-02

b1= -1.076051E+00

a2=

2.858111E-01

b2= -1.974768E-01

a2=

4.209182E-01

b2= -7.417535E-01

a2=

2.151675E-01

b2= -1.662847E+00

 

 

 

a3= -2.806121E-01

b3= -2.361221E-01

a3= -2.868900E-01

b3= -1.191062E+00

 

 

 

a4=

7.015302E-02

b4= -7.096475E-02

a4=

2.151675E-01

b4= -7.403085E-01

 

 

 

 

 

 

a5= -8.606701E-02

b5= -2.752156E-01

 

 

 

 

 

 

a6=

1.434450E-02

b6= -5.722250E-02

a0=

1.997396E-01

 

a0=

3.224553E-02

 

a0=

4.187407E-03

 

a1= -3.994792E-01

b1= -4.291049E-01

a1= -1.289821E-01

b1= -1.265912E+00

a1= -2.512444E-02

b1= -2.315806E+00

a2=

1.997396E-01

b2= -2.280633E-01

a2=

1.934732E-01

b2= -1.203878E+00

a2=

6.281111E-02

b2= -3.293726E+00

 

 

 

a3= -1.289821E-01

b3= -5.405908E-01

a3= -8.374815E-02

b3= -2.904827E+00

 

 

 

a4=

3.224553E-02

b4= -1.185538E-01

a4=

6.281111E-02

b4= -1.694129E+00

 

 

 

 

 

 

a5= -2.512444E-02

b5= -6.021426E-01

 

 

 

 

 

 

a6=

4.187407E-03

b6= -1.029147E-01

a0=

1.254285E-01

 

a0=

1.180009E-02

 

a0=

8.618665E-04

 

a1= -2.508570E-01

b1= -8.070777E-01

a1= -4.720035E-02

b1= -2.039039E+00

a1= -5.171200E-03

b1= -3.455239E+00

a2=

1.254285E-01

b2= -3.087918E-01

a2=

7.080051E-02

b2= -2.012961E+00

a2=

1.292800E-02

b2= -5.754734E+00

 

 

 

a3= -4.720035E-02

b3= -9.897915E-01

a3= -1.723733E-02

b3= -5.645387E+00

 

 

 

a4=

1.180009E-02

b4= -2.046700E-01

a4=

1.292800E-02

b4= -3.394902E+00

 

 

 

 

 

 

a5= -5.171200E-03

b5= -1.177469E+00

 

 

 

 

 

 

a6=

8.618665E-04

b6= -1.836195E-01

a0=

6.372801E-02

 

a0=

2.780754E-03

 

a0=

9.086141E-05

 

a1= -1.274560E-01

b1= -1.194365E+00

a1= -1.112302E-02

b1= -2.764031E+00

a1= -5.451685E-04

b1= -4.470118E+00

a2=

6.372801E-02

b2= -4.492774E-01

a2=

1.668453E-02

b2= -3.122854E+00

a2=

1.362921E-03

b2= -8.755595E+00

 

 

 

a3= -1.112302E-02

b3= -1.664554E+00

a3= -1.817228E-03

b3= -9.543712E+00

 

 

 

a4=

2.780754E-03

b4= -3.502233E-01

a4=

1.362921E-03

b4= -6.079377E+00

 

 

 

 

 

 

a5= -5.451685E-04

b5= -2.140062E+00

 

 

 

 

 

 

a6=

9.086141E-05

b6= -3.247363E-01

a0=

1.868823E-02

 

a0=

2.141509E-04

 

a0=

1.771089E-06

 

a1= -3.737647E-02

b1= -1.593937E+00

a1= -8.566037E-04

b1= -3.425455E+00

a1= -1.062654E-05

b1= -5.330512E+00

a2=

1.868823E-02

b2= -6.686903E-01

a2=

1.284906E-03

b2= -4.479272E+00

a2=

2.656634E-05

b2= -1.196611E+01

 

 

 

a3= -8.566037E-04

b3= -2.643718E+00

a3= -3.542179E-05

b3= -1.447067E+01

 

 

 

a4=

2.141509E-04

b4= -5.933269E-01

a4=

2.656634E-05

b4= -9.937710E+00

TABLE 20-2

 

 

 

 

a5= -1.062654E-05

b5= -3.673283E+00

 

 

 

 

a6=

1.771089E-06

b6= -5.707561E-01

High-pass Chebyshev filters (0.5% ripple)

338

The Scientist and Engineer's Guide to Digital Signal Processing

There are two problems with using tables to design digital filters. First, tables have a limited choice of parameters. For instance, Table 20-1 only provides 12 different cutoff frequencies, a maximum of 6 poles per filter, and no choice of passband ripple. Without the ability to select parameters from a continuous range of values, the filter design cannot be optimized. Second, the coefficients must be manually transferred from the table into the program. This is very time consuming and will discourage you from trying alternative values.

Instead of using tabulated values, consider including a subroutine in your program that calculates the coefficients. Such a program is shown in Table 20- 4. The good news is that the program is relatively simple in structure. After the four filter parameters are entered, the program spits out the "a" and "b" coefficients in the arrays A[ ] and B[ ]. The bad news is that the program calls the subroutine in Table 20-5. At first glance this subroutine is really ugly. Don't despair; it isn't as bad as it seems! There is one simple branch in line 1120. Everything else in the subroutine is straightforward number crunching. Six variables enter the routine, five variables leave the routine, and fifteen temporary variables (plus indexes) are used within. Table 20-5 provides two sets of test data for debugging this subroutine. Chapter 31 discusses the operation of this program in detail.

Step Response Overshoot

Butterworth and Chebyshev filters have an overshoot of 5 to 30% in their step responses, becoming larger as the number of poles is increased. Figure 20-3a shows the step response for two example Chebyshev filters. Figure (b) shows something that is unique to digital filters and has no counterpart in analog electronics: the amount of overshoot in the step response depends to a small degree on the cutoff frequency of the filter. The excessive overshoot and ringing in the step response results from the Chebyshev filter being optimized for the frequency domain at the expense of the time domain.

1.5

 

 

 

 

 

 

 

 

a. Step response

 

 

 

 

 

 

 

 

4 pole

 

 

 

1.0

 

 

 

 

 

 

 

Amplitude

2 pole

 

 

 

 

 

 

 

 

 

 

 

 

 

0.5

 

 

 

 

 

 

 

0.0

 

 

 

 

 

 

 

-10

0

10

20

30

40

50

60

Sample number

 

30

 

 

 

 

 

 

 

b. Overshoot

 

 

 

overshoot

25

 

 

 

 

 

20

 

 

 

 

 

 

 

 

 

 

 

Percent

15

6 pole

 

 

 

 

10

 

 

 

 

 

 

 

 

 

 

 

 

5

 

2 pole

 

 

 

 

0

 

 

 

 

 

 

0

0.1

0.2

0.3

0.4

0.5

 

 

 

Frequency

 

 

FIGURE 20-3

Chebyshev step response. The overshoot in the Chebyshev filter's step response is 5% to 30%, depending on the number of poles, as shown in (a), and the cutoff frequency, as shown in (b). Figure

(a) is for a cutoff frequency of 0.05, and may be scaled to other cutoff frequencies.

Chapter 20Chebyshev Filters

339

Stability

The main limitation of digital filters carried out by convolution is execution time. It is possible to achieve nearly any filter response, provided you are willing to wait for the result. Recursive filters are just the opposite. They run like lightning; however, they are limited in performance. For example, consider a 6 pole, 0.5% ripple, low-pass filter with a 0.01 cutoff frequency. The recursion coefficients for this filter can be obtained from Table 20-1:

a0= 1.391351E-10

a1= 8.348109E-10 b1= 5.883343E+00 a2= 2.087027E-09 b2= -1.442798E+01 a3= 2.782703E-09 b3= 1.887786E+01 a4= 2.087027E-09 b4= -1.389914E+01 a5= 8.348109E-10 b5= 5.459909E+00 a6= 1.391351E-10 b6= -8.939932E-01

Look carefully at these coefficients. The "b" coefficients have an absolute value of about ten. Using single precision, the round-off noise on each of these numbers is about one ten-millionth of the value, i.e., 10&6 . Now look at the "a" coefficients, with a value of about 10&9 . Something is obviously wrong here. The contribution from the input signal (via the "a" coefficients) will be 1000 times smaller than the noise from the previously calculated output signal (via the "b" coefficients). This filter won't work! In short, round-off noise limits the number of poles that can be used in a filter. The actual number will depend slightly on the ripple and if it is a high or low-pass filter. The approximate numbers for single precision are:

TABLE 20-3

Cutoff frequency

0.02

0.05

0.10

0.25

0.40

0.45

0.48

The maximum number of

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

poles for single precision.

Maximum poles

4

6

10

20

10

6

4

 

The filter's performance will start to degrade as this limit is approached; the step response will show more overshoot, the stopband attenuation will be poor, and the frequency response will have excessive ripple. If the filter is pushed too far, or there is an error in the coefficients, the output will probably oscillate until an overflow occurs.

There are two ways of extending the maximum number of poles that can be used. First, use double precision. This requires using double precision in the coefficient calculation as well (including the value for pi ).

The second method is to implement the filter in stages. For example, a six pole filter starts out as a cascade of three stages of two poles each. The program in Table 20-4 combines these three stages into a single set of recursion coefficients for easier programming. However, the filter is more stable if carried out as the original three separate stages. This requires knowing the "a" and "b" coefficients for each of the stages. These can

340

The Scientist and Engineer's Guide to Digital Signal Processing

100 'CHEBYSHEV FILTERRECURSION COEFFICIENT CALCULATION

110

'

 

 

 

 

120

 

 

 

 

'INITIALIZE VARIABLES

130

DIM A[22]

 

 

 

'holds the "a" coefficients upon program completion

140

DIM B[22]

 

 

 

'holds the "b" coefficients upon program completion

150

DIM TA[22]

 

 

 

'internal use for combining stages

160

DIM TB[22]

 

 

 

'internal use for combining stages

170

'

 

 

 

 

180 FOR I% = 0 TO 22

 

 

 

190

A[I%] = 0

 

 

 

 

200

B[I%] = 0

 

 

 

 

210 NEXT I%

 

 

 

 

220

'

 

 

 

 

230

A[2] = 1

 

 

 

 

240

B[2] = 1

 

 

 

 

250

PI = 3.14159265

 

 

 

260

 

 

 

 

'ENTER THE FOUR FILTER PARAMETERS

270

INPUT "Enter cutoff frequency

(0 to .5): ", FC

280

INPUT "Enter

0 for LP, 1 for HP filter:

", LH

290

INPUT "Enter percent ripple

(0 to 29):

", PR

300

INPUT "Enter number of poles (2,4,...20):

", NP

310

'

 

 

 

 

320 FOR P% = 1 TO NP/2

 

 

'LOOP FOR EACH POLE-PAIR

330

'

 

 

 

 

340

GOSUB 1000

 

 

'The subroutine in TABLE 20-5

350

'

 

 

 

 

360

FOR I% = 0 TO 22

 

 

'Add coefficients to the cascade

370

TA[I%] = A[I%]

 

 

 

380

TB[I%] = B[I%]

 

 

 

390

NEXT I%

 

 

 

 

400

'

 

 

 

 

410

FOR I% = 2 TO 22

 

 

 

420

A[I%] = A0*TA[I%] + A1*TA[I%-1] + A2*TA[I%-2]

430

B[I%] =

TB[I%] - B1*TB[I%-1] - B2*TB[I%-2]

440

NEXT I%

 

 

 

 

450

'

 

 

 

 

460 NEXT P%

 

 

 

 

470

'

 

 

 

 

480

B[2] = 0

 

 

 

'Finish combining coefficients

490 FOR I% = 0 TO 20

 

 

 

500

A[I%] = A[I%+2]

 

 

 

510

B[I%] = -B[I%+2]

 

 

 

520 NEXT I%

 

 

 

 

530

'

 

 

 

 

540 SA = 0

 

 

 

'NORMALIZE THE GAIN

550

SB = 0

 

 

 

 

560 FOR I% = 0 TO 20

 

 

 

570

IF LH = 0 THEN SA

= SA

+ A[I%]

 

580

IF LH = 0 THEN SB

= SB

+ B[I%]

 

590

IF LH = 1 THEN SA

= SA

+ A[I%] * (-1)^I%

600

IF LH = 1 THEN SB

= SB

+ B[I%] * (-1)^I%

610 NEXT I%

 

 

 

 

620

'

 

 

 

 

630

GAIN = SA / (1 - SB)

 

 

 

640

'

 

 

 

 

650 FOR I% = 0 TO 20

 

 

 

660

A[I%] = A[I%] / GAIN

 

 

670 NEXT I%

 

 

 

 

680

'

 

 

 

'The final recursion coefficients are in A[ ] and B[ ]

690 END

 

 

 

 

TABLE 20-4

 

 

Chapter 20Chebyshev Filters

341

1000 'THIS SUBROUTINE IS CALLED FROM TABLE 20-4, LINE 340

 

1010 '

 

 

 

1020

'

Variables entering subroutine:

PI, FC, LH, PR, HP, P%

 

1030

'

Variables exiting subroutine:

A0, A1, A2, B1, B2

 

1040

'

Variables used internally:

RP, IP, ES, VX, KX, T, W, M, D, K,

 

1050 '

 

X0, X1, X2, Y1, Y2

 

1060 '

 

 

 

1070 '

 

'Calculate the pole location on the unit circle

 

1080

RP = -COS(PI/(NP*2) + (P%-1) * PI/NP)

 

1090

IP = SIN(PI/(NP*2) + (P%-1) * PI/NP)

 

 

1100 '

 

 

 

1110 '

 

'Warp from a circle to an ellipse

 

1120 IF PR = 0 THEN GOTO 1210

 

 

1130

ES = SQR( (100 / (100-PR))^2 -1 )

 

 

1140

VX = (1/NP) * LOG( (1/ES) + SQR( (1/ES^2) + 1) )

 

1150

KX = (1/NP) * LOG( (1/ES) + SQR( (1/ES^2) - 1) )

 

1160

KX = (EXP(KX) + EXP(-KX))/2

 

 

1170

RP = RP * ( (EXP(VX) - EXP(-VX) ) /2 ) / KX

 

1180

IP = IP * ( (EXP(VX) + EXP(-VX) ) /2 ) / KX

 

1190 '

 

 

 

1200 '

 

's-domain to z-domain conversion

 

1210

T = 2 * TAN(1/2)

 

 

1220

W = 2*PI*FC

 

 

1230

M = RP^2 + IP^2

 

 

1240

D = 4 - 4*RP*T + M*T^2

 

 

1250

X0 = T^2/D

 

 

1260

X1 = 2*T^2/D

 

 

1270

X2 = T^2/D

 

 

1280

Y1 = (8 - 2*M*T^2)/D

 

 

1290

Y2 = (-4 - 4*RP*T - M*T^2)/D

 

 

1300 '

 

 

 

1310 '

 

'LP TO LP, or LP TO HP transform

 

1320

IF LH = 1 THEN K = -COS(W/2 + 1/2) / COS(W/2 - 1/2)

 

1330

IF LH = 0 THEN K = SIN(1/2 - W/2) / SIN(1/2 + W/2)

 

1340

D = 1 + Y1*K - Y2*K^2

 

 

1350

A0 = (X0 - X1*K + X2*K^2)/D

 

 

1360

A1 = (-2*X0*K + X1 + X1*K^2 - 2*X2*K)/D

 

1370

A2 = (X0*K^2 - X1*K + X2)/D

 

 

1380

B1 = (2*K + Y1 + Y1*K^2 - 2*Y2*K)/D

 

 

1390

B2 = (-(K^2) - Y1*K + Y2)/D

 

 

1400 IF LH = 1 THEN A1 = -A1

1410 IF LH = 1 THEN B1 = -B1 1420 '

1430 RETURN

TABLE 20-5

TABLE 20-4 and 20-5

Program to calculate the "a" and "b" coefficients for Chebyshev recursive filters. In lines 270-300, four parameters are entered into the program. The cutoff frequency, FC, is expressed as a fraction of the sampling frequency, and therefore must be in the range: 0 to 0.5. The variable, LH, is set to a value of one for a high-pass filter, and zero for a low-pass filter. The value entered for PR must be in the range of 0 to 29, corresponding to 0 to 29% ripple in the filter's frequency response. The number of poles in the filter, entered in the variable NP, must be an even integer between 2 and 20. At the completion of the program, the "a" and "b" coefficients are stored in the arrays A[ ] and B[ ] (a0 = A[0], a1 = A[1], etc.). TABLE 20-5 is a subroutine called from line 340 of the main program. Six variables are passed to this subroutine, and five variables are returned. Table 20-6 (next page) contains two sets of data to help debug this subroutine. The functions: COS and SIN, use radians, not degrees. The function: LOG is the natural (base e) logarithm. Declaring all floating point variables (including the value of B) to be double precision will allow more poles to be used. Tables 20-1 and 20-2 were generated with this program and can be used to test for proper operation. Chapter 33 describes the mathematical operation of this program.

342

The Scientist and Engineer's Guide to Digital Signal Processing

 

DATA SET 1

DATA SET 2

 

Enter the subroutine with these values:

 

 

 

 

FC

=

0.1

FC

=

0.1

 

LH

=

0

LH

=

1

 

PR

=

0

PR

=

10

 

NP

=

4

NP

=

4

 

P%

=

1

P%

=

2

 

PI

=

3.141592

PI

=

3.141592

These values should be present at line 1200:

RP

= -0.923879

RP

= -0.136178

IP

=

0.382683

IP

=

0.933223

ES

=

not used

ES

=

0.484322

VX

=

not used

VX

=

0.368054

KX

=

not used

KX

=

1.057802

These values should be present at line 1310:

T

=

1.092605

T

=

1.092605

W

=

0.628318

W

=

0.628318

M

=

1.000000

M

=

0.889450

D

=

9.231528

D

=

5.656972

X0

=

0.129316

X0

=

0.211029

X1

=

0.258632

X1

=

0.422058

X2

=

0.129316

X2

=

0.211029

Y1

=

0.607963

Y1

=

1.038784

Y2

= -0.125227

Y2

= -0.789584

These values should be return to the main program:

A0

=

0.061885

A0

=

0.922919

A1

=

0.123770

A1

= -1.845840

A2

=

0.061885

A2

=

0.922919

B1

=

1.048600

B1

=

1.446913

B2

=

-0.296140

B2

=

-0.836653

TABLE 20-6

Debugging data. This table contains two sets of data for debugging the subroutine listed in Table 20-5.

be obtained from the program in Table 20-4. The subroutine in Table 20-5 is called once for each stage in the cascade. For example, it is called three times for a six pole filter. At the completion of the subroutine, five variables are return to the main program: A0, A1, A2, B1, & B2. These are the recursion coefficients for the two pole stage being worked on, and can be used to implement the filter in stages.

CHAPTER

Filter Comparison

21

Decisions, decisions, decisions! With all these filters to choose from, how do you know which to use? This chapter is a head-to-head competition between filters; we'll select champions from each side and let them fight it out. In the first match, digital filters are pitted against analog filters to see which technology is best. In the second round, the windowed-sinc is matched against the Chebyshev to find the king of the frequency domain filters. In the final battle, the moving average fights the single pole filter for the time domain championship. Enough talk; let the competition begin!

Match #1: Analog vs. Digital Filters

Most digital signals originate in analog electronics. If the signal needs to be filtered, is it better to use an analog filter before digitization, or a digital filter after? We will answer this question by letting two of the best contenders deliver their blows.

The goal will be to provide a low-pass filter at 1 kHz. Fighting for the analog side is a six pole Chebyshev filter with 0.5 dB (6%) ripple. As described in Chapter 3, this can be constructed with 3 op amps, 12 resistors, and 6 capacitors. In the digital corner, the windowed-sinc is warming up and ready to fight. The analog signal is digitized at a 10 kHz sampling rate, making the cutoff frequency 0.1 on the digital frequency scale. The length of the windowed-sinc will be chosen to be 129 points, providing the same 90% to 10% roll-off as the analog filter. Fair is fair. Figure 21-1 shows the frequency and step responses for these two filters.

Let's compare the two filters blow-by-blow. As shown in (a) and (b), the analog filter has a 6% ripple in the passband, while the digital filter is perfectly flat (within 0.02%). The analog designer might argue that the ripple can be selected in the design; however, this misses the point. The flatness achievable with analog filters is limited by the accuracy of their resistors and

343

344

The Scientist and Engineer's Guide to Digital Signal Processing

capacitors. Even if a Butterworth response is designed (i.e., 0% ripple), filters of this complexity will have a residue ripple of, perhaps, 1%. On the other hand, the flatness of digital filters is primarily limited by round-off error, making them hundreds of times flatter than their analog counterparts. Score one point for the digital filter.

Next, look at the frequency response on a log scale, as shown in (c) and (d). Again, the digital filter is clearly the victor in both roll-off and stopband attenuation. Even if the analog performance is improved by adding additional stages, it still can't compare to the digital filter. For instance, imagine that you need to improve these two parameters by a factor of 100. This can be done with simple modifications to the windowed-sinc, but is virtually impossible for the analog circuit. Score two more for the digital filter.

The step response of the two filters is shown in (e) and (f). The digital filter's step response is symmetrical between the lower and upper portions of the step, i.e., it has a linear phase. The analog filter's step response is not symmetrical, i.e., it has a nonlinear phase. One more point for the digital filter. Lastly, the analog filter overshoots about 20% on one side of the step. The digital filter overshoots about 10%, but on both sides of the step. Since both are bad, no points are awarded.

In spite of this beating, there are still many applications where analog filters should, or must, be used. This is not related to the actual performance of the filter (i.e., what goes in and what comes out), but to the general advantages that analog circuits have over digital techniques. The first advantage is speed: digital is slow; analog is fast. For example, a personal computer can only filter data at about 10,000 samples per second, using FFT convolution. Even simple op amps can operate at 100 kHz to 1 MHz, 10 to 100 times as fast as the digital system!

The second inherent advantage of analog over digital is dynamic range. This comes in two flavors. Amplitude dynamic range is the ratio between the largest signal that can be passed through a system, and the inherent noise of the system. For instance, a 12 bit ADC has a saturation level of 4095, and an rms quantization noise of 0.29 digital numbers, for a dynamic range of about 14000. In comparison, a standard op amp has a saturation voltage of about 20 volts and an internal noise of about 2 microvolts, for a dynamic range of about ten million. Just as before, a simple op amp devastates the digital system.

The other flavor is frequency dynamic range. For example, it is easy to design an op amp circuit to simultaneously handle frequencies between 0.01 Hz and 100 kHz (seven decades). When this is tried with a digital system, the computer becomes swamped with data. For instance, sampling at 200 kHz, it takes 20 million points to capture one complete cycle at 0.01 Hz. You may have noticed that the frequency response of digital filters is almost always plotted on a linear frequency scale, while analog filters are usually displayed with a logarithmic frequency. This is because digital filters need

Chapter 21Filter Comparison

345

 

 

Analog Filter

 

 

 

(6 pole 0.5dB Chebyshev)

 

1.50

 

 

 

 

 

1.25

a. Frequency response

 

 

 

 

 

 

 

1.00

 

 

 

 

 

Amplitude

 

 

 

 

 

0.75

 

 

 

 

 

0.50

 

 

 

 

 

0.25

 

 

 

 

 

0.00

 

 

 

 

 

0

1000

2000

3000

4000

5000

Frequency (hertz)

 

40

 

 

 

 

 

 

20

c. Frequency response (dB)

 

 

(dB)

0

 

 

 

 

 

-20

 

 

 

 

 

Amplitude

 

 

 

 

 

-40

 

 

 

 

 

-60

 

 

 

 

 

 

 

 

 

 

 

 

-80

 

 

 

 

 

 

-100

 

 

 

 

 

 

0

1000

2000

3000

4000

5000

Frequency (hertz)

 

2.0

 

 

 

 

 

 

 

 

e. Step response

 

 

 

 

Amplitude

1.5

 

 

 

 

 

 

1.0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0.5

 

 

 

 

 

 

 

0.0

 

 

 

 

 

 

 

-0.5

 

 

 

 

 

 

 

-4

-2

0

2

4

6

8

Time (milliseconds)

Digital Filter

(129 point windowed-sinc)

 

1.50

 

 

 

 

 

 

 

1.25

b. Frequency response

 

 

 

 

 

 

 

 

 

 

Amplitude

1.00

 

 

 

 

 

 

0.75

 

 

 

 

 

 

0.50

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0.25

 

 

 

 

 

 

 

0.00

 

 

 

 

 

 

 

0

0.1

0.2

0.3

 

0.4

0.5

 

 

 

Frequency

 

 

 

 

40

 

 

 

 

 

 

 

20

d. Frequency response (dB)

 

 

(dB)

0

 

 

 

 

 

 

-20

 

 

 

 

 

 

Amplitude

 

 

 

 

 

 

-40

 

 

 

 

 

 

-60

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-80

 

 

 

 

 

 

 

-100

 

 

 

 

 

 

 

0

0.1

0.2

0.3

 

0.4

0.5

 

 

 

Frequency

 

 

 

 

2.0

 

 

 

 

 

 

 

 

f. Step response

 

 

 

 

 

1.5

 

 

 

 

 

 

Amplitude

1.0

 

 

 

 

 

 

0.5

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0.0

 

 

 

 

 

 

 

-0.5

 

 

 

 

 

 

 

-40

-20

0

20

40

60

80

Sample number

FIGURE 21-1

Comparison of analog and digital filters. Digital filters have better performance in many areas, such as: passband ripple, (a) vs. (b), roll-off and stopband attenuation, (c) vs. (d), and step response symmetry,

(e) vs. (f). The digital filter in this example has a cutoff frequency of 0.1 of the 10 kHz sampling rate. This provides a fair comparison to the 1 kHz cutoff frequency of the analog filter.

a linear scale to show their exceptional filter performance, while analog filters need the logarithmic scale to show their huge dynamic range.

346

The Scientist and Engineer's Guide to Digital Signal Processing

Match #2: Windowed-Sinc vs. Chebyshev

Both the windowed-sinc and the Chebyshev filters are designed to separate one band of frequencies from another. The windowed-sinc is an FIR filter implemented by convolution, while the Chebyshev is an IIR filter carried out by recursion. Which is the best digital filter in the frequency domain? We'll let them fight it out.

The recursive filter contender will be a 0.5% ripple, 6 pole Chebyshev low-pass filter. A fair comparison is complicated by the fact that the Chebyshev's frequency response changes with the cutoff frequency. We will use a cutoff frequency of 0.2, and select the windowed-sinc's filter kernel to be 51 points. This makes both filters have the same 90% to 10% roll-off, as shown in Fig. 21-2(a).

Now the pushing and shoving begins. The recursive filter has a 0.5% ripple in the passband, while the windowed-sinc is flat. However, we could easily set the recursive filter ripple to 0% if needed. No points. Figure 21-2b shows that the windowed-sinc has a much better stopband attenuation than the Chebyshev. One point for the windowed-sinc.

Figure 21-3 shows the step response of the two filters. Both are bad, as you should expect for frequency domain filters. The recursive filter has a nonlinear phase, but this can be corrected with bidirectional filtering. Since both filters are so ugly in this parameter, we will call this a draw.

So far, there isn't much difference between these two filters; either will work when moderate performance is needed. The heavy hitting comes over two critical issues: maximum performance and speed. The windowed-sinc is a powerhouse, while the Chebyshev is quick and agile. Suppose you have a really tough frequency separation problem, say, needing to isolate a 100

1.5

 

 

 

 

 

 

a. Frequency response

 

 

1.0

 

 

 

 

 

Amplitude

 

 

Chebyshev

 

 

 

 

 

recursive

 

 

0.5

windowed-sinc

 

 

 

 

0.0

 

 

 

 

 

0

0.1

0.2

0.3

0.4

0.5

 

 

Frequency

 

 

 

40

 

 

 

 

 

 

20

b. Frequency response (dB)

 

 

 

 

 

 

 

 

(dB)

0

 

 

 

 

 

-20

 

 

 

 

 

Amplitude

 

 

 

 

 

-40

 

 

 

Chebyshev

 

 

 

 

recursive

 

 

 

 

 

 

-60

windowed-sinc

 

 

 

 

 

 

 

 

 

 

 

 

 

-80

 

 

 

 

 

 

-100

 

 

 

 

 

 

0

0.1

0.2

0.3

0.4

0.5

 

 

 

Frequency

 

 

FIGURE 21-2

Windowed-sinc and Chebyshev frequency responses. Frequency responses are shown for a 51 point windowed-sinc filter and a 6 pole, 0.5% ripple Chebyshev recursive filter. The windowed-sinc has better stopband attenuation, but either will work in moderate performance applications. The cutoff frequency of both filters is 0.2, measured at an amplitude of 0.5 for the windowed-sinc, and 0.707 for the recursive.

Соседние файлы в предмете Электроника