You are on page 1of 18

Digital Signal Processing

1 , n = 0,1,..., ( M − 1) / 2
w(n) = 
0 , elsewhere
The resulting impulse response decays
smoothly towards zero as shown below.

6.4 Some Common Window Functions


a) Hamming Window
One of the most widely used window
functions is the Hamming window which is
defined as

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 13


Digital Signal Processing

 − ( M − 2) / 2 ≤ n ≤ ( M − 1) / 2 ( M .odd )
0.54 + 0.46 cos(2πn / M ) 
w(n) =   −M /2 ≤ n ≤ M /2 ( M .even)

 0 elsewhere

b) Hanning Window
The Hanning window is defined as
 − ( M − 2) / 2 ≤ n ≤ ( M − 1) / 2 ( M .odd )
0.5 + 0.5 cos(2πn / M ) 
w(n) =   −M /2≤ n ≤ M /2 ( M .even)

 0 elsewhere

c) Blackman Window
The Blackman window is defined as
  2πn   4πn − ( M − 2) / 2 ≤ n ≤ ( M − 1) / 2 ( M .odd )
0.42 + 0.5 cos  + 0.08 cos 
w(n) =   M −1   M − 1  −M /2 ≤ n ≤ M /2 ( M .even)

 0 elsewhere

The most relevant features of some of the


most popular window functions are
summurized in Table 6.2.

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 14


Digital Signal Processing

6.5 Summary of the Window Method of


Calculating FIR Filter Coefficients
Step 1: Specify the “ideal” or desired frequency
response H D (ω ) .

Step 2: Using the table provided before, select


the impulse response, hD (n) , of the desired
filter.

Step 3: Select a window function that satisfies


the passband or attenuation specifications and
then determine the number of filter
coefficients.

Step 4: Obtain values of w(n) for the chosen


window function and the values of the actual
FIR coefficients, h(n) , by multiplying hD (n) by
w(n) :
h(n) = hD (n) w(n)

Example: Determine the coefficients of an FIR


lowpass filter to meet the specifications given
below using the window method.

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 15


Digital Signal Processing

Passband edge frequency=1.5kHz


Transition width=0.5kHz
Stopband attenuation>50dB
Sampling frequency, Fs=8kHz

Solution: Using Table 6.1, we select hD (n) for


LPF which is given by
 2 f c sin(nω c )
 , n≠0
hD (n) =  nω c
 2 fc , n=0
From Table, it can be seen that the Hamming,
Blackman and Kaiser windows satisfy the
stopband attenuation requirements. Let us
select the Hamming window for simplicity.

Now, transition width, ∆F = 0.5kHz


∆F 0.5
Normalized transition width, ∆f = = = 0.0625
Fs 8

Using Table 6.2, we obtain that the transition


width for Hamming window is ∆f = 3.3 / M from
which we obtain the filter length as
3.3 3.3
M= = = 52.8  M = 53
∆f 0.0625

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 16


Digital Signal Processing

Then the filter coefficients can be calculated


from h(n) = hD (n) w(n) for − 26 ≤ n ≤ 26 .

However, the cutoff frequency of the resulting


filter is different from the one given in the
specifications (the smearing effect of the
window)
∆F 0.5
f c′ = f c + = 1.5 + = 1.75kHz
(Unnormalized)
2 2
Normalizing this gives 1.75/8=0.21875.

n=0  hD (0) = 2 f c′ = 2 × 0.21875 = 0.4375


w(0) = 0.54 + 0.46 cos(0) = 1
 h(0) = hD (0) w(0) = 0.4375

2 × 0.21875
n=1  hD (1) = sin(2π × 0.21875) = 0.31219
2π × 0.21875

w(1) = 0.54 + 0.46 cos( ) = 0.99677
53
 h(1) = h(−1) = hD (1) w(1) = 0.31118

2 × 0.21875
n=2 hD (2) = sin( 2 × 2π × 0.21875) = 0.06013
2 × 2π × 0.21875

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 17


Digital Signal Processing

2 × 2π
w(2) = 0.54 + 0.46 cos( ) = 0.98713
53
 h(2) = h(−2) = hD (2) w(2) = 0.06012
. . .
. . .
. . .
n=26
2 × 0.21875
hD (26) = sin( 26 × 2π × 0.21875) = −0.01131
26 × 2π × 0.21875
26 × 2π
w(2) = 0.54 + 0.46 cos( ) = 0.08081
53
 h(26) = h(−26) = hD (26) w(26) = −0.000914

Note that the indices of the filter coefficients


run from -26 to 26. To make the filter causal
(necessary for implementation) we add 26 to
eac index so that the indices start at zero.

For instance, after this adjustment, we obtain


h(0+26)=h(26)=0.4375
h(1+26)=h(27)=0.31118
h(2+26)=h(28)=0.06012
. . .
. . .
h(26+26)=h(52)=-0.000914

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 18


Digital Signal Processing

The filter coefficients, with indices adjusted, are


listed in the following Table.

Example: A requirement exists for an FIR filter


to meet the following specifications:
Passband =150-250Hz
Transition width=50Hz

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 19


Digital Signal Processing

Passband ripple= 0.1dB


Stopband attenuation=60dB
Sampling frequency=1kHz

Obtain the filter coefficients and spectrum using


the window method.

Solution: From the specification, the passband


and stopband ripples are
Passband ripple:
 20 log(1 + δ p ) = 0.1dB
0.1
log(1 + δ p ) = = 0.005
20
1 + δ p = 100.005 = 1.01157
δ p = 0.01157
Stopband ripple:
 − 20 log(δ s ) = 60dB
60
log(δ s ) = − = −3
20
δ s = 10 −3 = 0.001
We use the smaller of the ripples,

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 20


Digital Signal Processing

 δ = min(δ p , δ s ) = 0.001
It is clear from Table 6.2 that the attenuation
requirements can be met by the Kaiser or the
Blackman window.

For the Kaiser window, the number of


coefficients is computed by
A − 7.95 60 − 7.95
M≥ = = 72.49
14.36∆f 14.36(50 / 1000)
where A = −20 log10 (δ ) = 60 . The Kaiser
window function is (see Table 6.2)
  2 1/ 2 
  2n   
I o β 1 −    
   M − 1   
w(n) =
I o (β )
Where I o (x ) is the zero-order modified Bessel
function of the first kind. The ripple parameter,
β , is given by
β = 0 if A ≤ 21dB
β = 0.5842( A − 21) 0.4 + 0.007886( A − 21)
if 21dB < A < 50dB
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 21
Digital Signal Processing

β = 0.1102( A − 8.7) if A ≥ 50dB

Clearly, the coefficient computation using


Kaiser window requires tedious computations
by hand. Therefore, we will discuss its
computation method by a MATLAB program
later!

For the Blackman window, an estimate of the


number of filter coefficients is obtained as
(from Table 6.2)
5.5 5 .5
M= = ≈ 110
∆f (50 / 1000)

To account for the smearing effects of the


window function, we compute the cutoff
frequencies as follows
∆f (50 / 1000)
f c′1 = f c1 − = 150 − × 1000 = 125Hz
2 2
∆f (50 / 1000)
f c′2 = f c 2 + = 250 + × 1000 = 275Hz
2 2

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 22


Digital Signal Processing

Finally, using the Blackman window function


given in Table 6.2, we can compute the filter
coefficients.   (EXERCISE)

6.6 FIR Filter Design With MATLAB


The MATLAB Signal Processing Toolbox contains
an excellent set of programs and functions for
the design and analysis of different types of FIR
filters.

For standard, frequency selective linear phase


window based FIR filterd design (lowpass,
highpass, bandpass and bandstop), the key
high-level command in the Toolbox is the fir1
command. The syntax for the fir1 command
is
b=fir1(M-1,Fc)

This command computes and returns N-point


impulse response coefficients of an FIR filter
with a cutoff frequency Fc. The coefficients are
stored in the vector b which are arranged as
negative powers of z:
b( z ) = b(0) + b(1) z −1 + b(2) z −2 + ... + b( M − 1) z − ( M −1)

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 23


Digital Signal Processing

The parameter , M, specifies the order of the


filter. The cutoff frequency, Fc, is normalized
with respect to the Nyquist rate (i.e, half the
sampling frequency) and lies between 0 and 1
(where 1 corresponds to the Nyquist
frequency).

By default, the basic fir1 command applies a


Hamming window and assumes a lowpass filter
(or a bandpass filter if Fc specifies more than
one cutoff frequency).

However, the basic fir1 command can be


extended by specifying the type of filter and/or
the window function. The syntax in these case
is:
b=fir1(M-1,Fc,’filter-type’)
b=fir1(M-1,Fc,window)
b=fir1(M-1,Fc,’filter-type’,window)

For a highpass filter, the word ‘high’ specifies


the filter type, and for bandstop the word ‘stop’
is used. For both bandpass and bandstop filters,
the variable Fc is a vector that specifies the

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 24


Digital Signal Processing

cutoff frequencies. For highpass and bandstop


filters, the filter length must be an odd integer
(even integer results in zero magnitude
response).

MATLAB supports the use of a variety of


window functions including Hamming, Hanning,
boxcar (rectangular), Kaiser, and Chebyshev
windows. The syntax for generating window
coefficients is:
w=boxcar(M)
w=blackman(M)
w=hamming(M)
w=hanning(M)
w=kaiser(M, beta)

Usually, the window command is embedded


into the fir1 command.

Example: Determine the coefficients of a linear


phase FIR lowpass filter with a passband and
stopband edge frequency of 1kHz and 4.3kHz,
respectively.

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 25


Digital Signal Processing

Solution: From Table 6.2, the approximate


relationship between the transition width and
filter length for a Hamming window-based filter
is
3.3 3.3
M≈ = = 10
∆f (4.3 − 1) / 10
The actual cutoff frequency (allowing for the
smearing effect) is
∆F 3.3
f c′ = f c + = 1+ = 2.65kHz
2 2
In MATLAB, the cutoff frequency should be
normalized to half the samling frequency. Thus,
2.65
fc = = 0.53
5

MATLAB m-file:
FS=10000; %Sampling Fre.
fc=0.53; %Cutoff frequency
M=10; %Filter length
hd=fir1(M-1,fc,boxcar(M)); %Ideal
wn=hamming(M); %Calculate coefficients
hn=fir1(M-1,fc,wn); %Obtain win. coeff.
[H,f]=freqz(hn,1,512,FS);%Fre. Res.
mag=20*log10(abs(H));

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 26


Digital Signal Processing

plot(f,mag), grid on
xlabel (‘Frequency (Hz)’)
ylabel (‘MagnitudeResponse(dB)’)

-10

-20
Magnitude Response (dB)

-30

-40

-50

-60

-70

-80

-90
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency(Hz)

Example: Determine the coefficients and plot


the magnitude-frequency response of a
bandpass FIR filter, using the Kaiser window and
MATLAB, that meets the following
specifications:
Passband=150-250Hz

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 27


Digital Signal Processing

Transition width=50Hz
Passband ripple=0.1dB
Stopband attenuation=60dB
Sampling frequency=1kHz

Solution: This problem is identical to Example


on page 19, which gives the filter length, M=73,
and the ripple parameter, β = 5.65 .

MATLAB m-file:
FS=1000;
FN=FS/2;
M=73;
beta=5.65;
fc1=125/FN;
fc2=275/FN;
FC=[fc1 fc2];
hn=fir1(M-1,FC,kaiser(M,beta));
[H,f]=freqz(hn,1,512,FS);
mag=20*log10(abs(H));
plot(f,mag), grid on
xlabel (‘Frequency (Hz)’)
ylabel (‘MagnitudeResponse(dB)’)

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 28


Digital Signal Processing

f=150Hz Log(1)=0dB f=250Hz


20

-20
Magnitude Response (dB)

-40

-60

-80

-100

-120
0 50 100 150 200 250 300 350 400 450 500
Frequency(Hz)

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 29


Digital Signal Processing

CHAPTER 6: Finite Impulse Response (FIR) Filter Design 30

You might also like