Digital Signal Processing. The Scientist and Engineers Guide. Steven W. Smith
.pdf
|
Chapter 16- Windowed-Sinc Filters |
287 |
||
|
Time Domain |
|
Frequency Domain |
|
|
1.5 |
|
1.5 |
|
|
b. Ideal filter kernel |
|
a. Ideal frequency response |
|
Amplitude |
1.0 |
Amplitude |
1.0 |
|
0.5 |
0.5 |
|
||
|
|
|
||
0.0 |
|
|
|
|
0.0 |
|
|
-0.5 |
|
|
|
|
-0.5 |
fc |
|
-50 |
-25 |
0 |
25 |
50 |
0 |
0.5 |
|
|
|
Sample number |
|
|
|
Frequency |
|
|
1.5 |
|
|
|
1.5 |
|
|
|
|
c. Truncated-sinc filter kernel |
|
|
|
d. Truncated-sinc frequency response |
|
Amplitude |
1.0 |
|
|
Amplitude |
1.0 |
|
|
0.5 |
|
|
0.5 |
|
|
||
|
|
|
|
|
|
||
|
0.0 |
|
|
|
0.0 |
|
|
|
|
abrupt end |
|
|
|
|
|
|
-0.5 |
M |
|
|
-0.5 |
fc |
|
|
0 |
1 |
|
0 |
0.5 |
||
|
|
Sample number |
|
|
|
Frequency |
|
|
1.5 |
|
|
|
|
e. Blackman or Hamming window |
|
|
1.0 |
|
|
Amplitude |
0.5 |
|
|
|
|
|
|
|
0.0 |
|
|
|
-0.5 |
M |
|
|
0 |
1 |
Sample number
|
1.5 |
|
|
|
1.5 |
|
|
|
|
f. Windowed-sinc filter kernel |
|
|
|
g. Windowed-sinc frequency response |
|
Amplitude |
1.0 |
|
|
Amplitude |
1.0 |
|
|
0.5 |
|
|
0.5 |
|
|
||
|
|
|
|
|
|
||
|
0.0 |
|
|
|
0.0 |
|
|
|
-0.5 |
M |
|
|
-0.5 |
fc |
|
|
0 |
1 |
|
0 |
0.5 |
||
|
|
Sample number |
|
|
|
Frequency |
|
FIGURE 16-1
290 |
The Scientist and Engineer's Guide to Digital Signal Processing |
standard 0.707 (-3dB) used in analog electronics and other digital filters? This is because the windowed-sinc's frequency response is symmetrical between the passband and the stopband. For instance, the Hamming window results in a passband ripple of 0.2%, and an identical stopband attenuation (i.e., ripple in the stopband) of 0.2%. Other filters do not show this symmetry, and therefore have no advantage in using the one-half amplitude point to mark the cutoff frequency. As shown later in this chapter, this symmetry makes the windowedsinc ideal for spectral inversion.
After fC and M have been selected, the filter kernel is calculated from the relation:
h [i ] ' |
sin(2BfC (i & M /2)) |
0.42 & |
0.5 cos |
2Bi |
% |
0.08 cos |
4Bi |
K |
M |
M |
|||||
|
i & M /2 |
|
|
|
|
EQUATION 16-4
The windowed-sinc filter kernel. The cutoff frequency, fC , is expressed as a fraction of the sampling rate, a value between 0 and 0.5. The length of the filter kernel is determined by M, which must be an even integer. The sample number i, is an integer that runs from 0 to M, resulting in M%1 total points in the filter kernel. The constant, K, is chosen to provide unity gain at zero frequency. To avoid a divide-by-zero error, for i ' M/2 , use h[i ] ' 2BfC K .
Don't be intimidated by this equation! Based on the previous discussion, you should be able to identify three components: the sinc function, the M/2 shift, and the Blackman window. For the filter to have unity gain at DC, the constant K must be chosen such that the sum of all the samples is equal to one. In practice, ignore K during the calculation of the filter kernel, and then normalize all of the samples as needed. The program listed in Table 16-1 shows how this is done. Also notice how the calculation is handled at the center of the sinc, i ' M/2 , which involves a division by zero.
This equation may be long, but it is easy to use; simply type it into your computer program and forget it. Let the computer handle the calculations. If you find yourself trying to evaluate this equation by hand, you are doing something very very wrong.
Let's be specific about where the filter kernel described by Eq. 16-4 is located in your computer array. As an example, M will be chosen to be 100. Remember, M must be an even number. The first point in the filter kernel is in array location 0, while the last point is in array location 100. This means that the entire signal is 101 points long. The center of symmetry is at point 50, i.e., M/2 . The 50 points to the left of point 50 are symmetrical with the 50 points to the right. Point 0 is the same value as point 100, and point 49 is the same as point 51. If you must have a specific number of samples in the filter kernel, such as to use the FFT, simply add zeros to one end or the other. For example, with M ' 100 , you could make samples 101 through 127 equal to zero, resulting in a filter kernel 128 points long.
294 |
The Scientist and Engineer's Guide to Digital Signal Processing |
|
100 'LOW-PASS WINDOWED-SINC FILTER |
||
110 |
'This program filters 5000 samples with a 101 point windowed-sinc filter, |
|
120 |
'resulting in 4900 samples of filtered data. |
|
130 ' |
|
|
140 |
DIM X[4999] |
'X[ ] holds the input signal |
150 |
DIM Y[4999] |
'Y[ ] holds the output signal |
160 |
DIM H[100] |
'H[ ] holds the filter kernel |
170 ' |
|
|
180 |
PI = 3.14159265 |
|
190 |
FC = .14 |
'Set the cutoff frequency (between 0 and 0.5) |
200 |
M% = 100 |
'Set filter length (101 points) |
210 ' |
|
|
220 |
GOSUB XXXX |
'Mythical subroutine to load X[ ] |
230 ' |
|
|
240 ' |
'Calculate the low-pass filter kernel via Eq. 16-4 |
|
250 FOR I% = 0 TO 100 |
|
|
260 |
IF (I%-M%/2) = 0 THEN H[I%] = 2*PI*FC |
|
270 |
IF (I%-M%/2) <> 0 THEN H[I%] = SIN(2*PI*FC * (I%-M%/2)) / (I%-M%/2) |
|
280 |
H[I%] = H[I%] * (0.54 - 0.46*COS(2*PI*I%/M%) ) |
|
290 NEXT I% |
|
|
300 ' |
|
|
310 |
SUM = 0 |
'Normalize the low-pass filter kernel for |
320 |
FOR I% = 0 TO 100 |
'unity gain at DC |
330 |
SUM = SUM + H[I%] |
|
340 NEXT I% |
|
|
350 ' |
|
|
360 FOR I% = 0 TO 100 |
|
|
370 |
H[I%] = H[I%] / SUM |
|
380 NEXT I% |
|
|
390 ' |
|
|
400 |
FOR J% = 100 TO 4999 |
'Convolve the input signal & filter kernel |
410 |
Y[J%] = 0 |
|
420 |
FOR I% = 0 TO 100 |
|
430 |
Y[J%] = Y[J%] + X[J%-I%] * H[I%] |
|
440 |
NEXT I% |
|
450 NEXT J% |
|
|
460 '
470 END
TABLE 16-1
a stopband attenuation of at least -120dB (one part in one-million for those that refuse to learn decibels). As previously shown, the Blackman window only provides -74dB (one part in five-thousand). Fortunately, greater stopband attenuation is easy to obtain. The input signal can be filtered using a conventional windowed-sinc filter kernel, providing an intermediate signal. The intermediate signal can then be passed through the filter a second time, further increasing the stopband attenuation to -148dB (1 part in 30 million, wow!). It is also possible to combine the two stages into a single filter. The kernel of the combined filter is equal to the convolution of the filter kernels of the two stages. This also means that convolving any filter kernel with itself results in a filter kernel with a much improved stopband attenuation. The price you pay is a longer filter kernel and a slower roll-off. Figure 16-7a shows the frequency response of a 201 point lowpass filter, formed by convolving a 101 point Blackman windowed-sinc with itself. Amazing performance! (If you really need more than -100dB of stopband attenuation, you should use double precision. Single precision
|
Chapter 16- Windowed-Sinc Filters |
295 |
||
100 'BAND-PASS WINDOWED-SINC FILTER |
|
|||
110 |
'This program calculates an 801 point band-pass filter kernel |
|
||
120 |
' |
|
|
|
130 |
DIM A[800] |
'A[ ] |
workspace for the lower cutoff |
|
140 |
DIM B[800] |
'B[ ] |
workspace for the upper cutoff |
|
150 |
DIM H[800] |
'H[ ] |
holds the final filter kernel |
|
160 |
' |
|
|
|
170 |
PI = 3.1415926 |
|
|
|
180 |
M% = 800 |
'Set filter kernel length (801 points) |
|
|
190 |
' |
|
|
|
200 |
' |
'Calculate the first low-pass filter kernel via Eq. 16-4, |
|
|
210 |
FC = 0.196 |
'with a cutoff frequency of 0.196, store in A[ ] |
|
|
220 FOR I% = 0 TO 800 |
|
|
|
|
230 |
IF (I%-M%/2) = 0 THEN A[I%] = 2*PI*FC |
|
||
240 |
IF (I%-M%/2) <> 0 THEN A[I%] = SIN(2*PI*FC * (I%-M%/2)) / (I%-M%/2) |
|
||
250 |
A[I%] = A[I%] * (0.42 - 0.5*COS(2*PI*I%/M%) + 0.08*COS(4*PI*I%/M%)) |
|
||
260 NEXT I% |
|
|
|
|
270 |
' |
|
|
|
280 |
SUM = 0 |
'Normalize the first low-pass filter kernel for |
|
|
290 |
FOR I% = 0 TO 800 |
'unity gain at DC |
|
|
300 |
SUM = SUM + A[I%] |
|
|
|
310 NEXT I% |
|
|
|
|
320 |
' |
|
|
|
330 FOR I% = 0 TO 800 |
|
|
|
|
340 |
A[I%] = A[I%] / SUM |
|
|
|
350 NEXT I% |
|
|
|
|
360 |
' |
'Calculate the second low-pass filter kernel via Eq. 16-4, |
|
|
370 |
FC = 0.204 |
'with a cutoff frequency of 0.204, store in B[ ] |
|
|
380 FOR I% = 0 TO 800 |
|
|
|
|
390 |
IF (I%-M%/2) = 0 THEN B[I%] = 2*PI*FC |
|
||
400 |
IF (I%-M%/2) <> 0 THEN B[I%] = SIN(2*PI*FC * (I%-M%/2)) / (I%-M%/2) |
|
||
410 |
B[I%] = B[I%] * (0.42 - 0.5*COS(2*PI*I%/M%) + 0.08*COS(4*PI*I%/M%)) |
|
||
420 NEXT I% |
|
|
|
|
430 |
' |
|
|
|
440 |
SUM = 0 |
'Normalize the second low-pass filter kernel for |
|
|
450 |
FOR I% = 0 TO 800 |
'unity gain at DC |
|
|
460 |
SUM = SUM + B[I%] |
|
|
|
470 NEXT I% |
|
|
|
|
480 |
' |
|
|
|
490 FOR I% = 0 TO 800 |
|
|
|
|
500 |
B[I%] = B[I%] / SUM |
|
|
|
510 NEXT I% |
|
|
|
|
520 |
' |
|
|
|
530 |
FOR I% = 0 TO 800 |
'Change the low-pass filter kernel in B[ ] into a high-pass |
|
|
540 |
B[I%] = - B[I%] |
'filter kernel using spectral inversion (as in Fig. 14-5) |
|
|
550 NEXT I% |
|
|
|
|
560 |
B[400] = B[400] + 1 |
|
|
|
570 |
' |
|
|
|
580 |
' |
|
|
|
590 |
FOR I% = 0 TO 800 |
'Add the low-pass filter kernel in A[ ], to the high-pass |
|
|
600 |
H[I%] = A[I%] + B[I%] |
'filter kernel in B[ ], to form a band-reject filter kernel |
|
|
610 |
NEXT I% |
'stored in H[ ] (as in Fig. 14-8) |
|
|
620 |
' |
|
|
|
630 |
FOR I% = 0 TO 800 |
'Change the band-reject filter kernel into a band-pass |
|
|
640 |
H[I%] = -H[I%] |
'filter kernel by using spectral inversion |
|
|
650 NEXT I% |
|
|
|
|
660 |
H[400] = H[400] + 1 |
|
|
|
670 |
' |
'The band-pass filter kernel now resides in H[ ] |
|
|
680 END
TABLE 16-2


c. Frequency response (dB)





























































































































0.50 









































Amplitude













































