You are on page 1of 4

Practice examples

Q1) Design a 6th order linear phase FIR filter with the following characteristics:
Sampling rate is 8000 Hz, pass-band from 2000 to 3000 Hz.
Write its frequency response, find its impulse response, find the windowed impulse response by using the
Hamming window defined as:

2𝜋𝜋𝜋𝜋
𝑤𝑤(𝑛𝑛) = 0.54 − 0.46 cos � � 𝑓𝑓𝑓𝑓𝑓𝑓 𝑛𝑛 = 0, 1, 2, … … . . , 𝑁𝑁 − 1
𝑁𝑁 − 1
Solution
Designing of FIR filter means to calculate FIR filter coefficients. The coefficients of FIR filter will be equal to its
windowed impulse response 𝑏𝑏𝑘𝑘 = ℎ𝑤𝑤 (𝑛𝑛)

Step-1: Frequency response 𝑯𝑯(𝒌𝒌)

In order to design a 6th order filter, we will need to define an 8 point frequency response. Since𝐹𝐹𝑠𝑠 = 8000 Hz, so
every bin of frequency response will represent 1000 Hz [𝐹𝐹𝑠𝑠 ⁄𝑁𝑁 = 8000⁄8 = 1000 𝐻𝐻𝐻𝐻]. Pass-band is required to
define from 2000 to 3000 Hz. Therefore
𝐻𝐻(𝑘𝑘) = [0 0 1 1 0 1 1 0]

Step-2: Calculation of Impulse response 𝒉𝒉(𝒏𝒏)

Since frequency response and impulse response are transform pairs of each other. Therefore impulse response
ℎ(𝑛𝑛) can be calculated by taking IFFT of frequency response𝐻𝐻(𝑘𝑘).

ℎ(𝑛𝑛) = 𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖 [𝐻𝐻(𝑘𝑘)]


IFFT can be calculated by using either conjugate or swapping method

Note: Since H(K) contains only real numbers therefore its IFFT can also be calculated by just taking FFT and divide
the results of FFT by N.

𝐹𝐹𝐹𝐹𝐹𝐹 [𝐻𝐻(𝑘𝑘)]
ℎ(𝑛𝑛) = 𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖 [𝐻𝐻(𝑘𝑘)] =
𝑁𝑁

Calculate IFFT of 𝐻𝐻(𝑘𝑘) to find ℎ(𝑛𝑛): {Do it yourself using Radix-2 forward FFT}

ℎ(𝑛𝑛) = [ 0.5, − 0.1768, − 0.25, 0.1768, 0, 0.1768, − 0.25, − 0.1768]

Step-3: Make 𝒉𝒉(𝒏𝒏) causal

Note: When we take FFT of anything, frequency domain samples after Fs/2 are actually negative frequencies. When
we take IFFT of anything, time domain samples after half number of samples are actually negative time samples. It
means that the first four samples are actually positive time samples and the last four samples are actually negative
time samples
Make the impulse response start from zero by copy pasting the negative time samples starting at index 0 and copy
pasting the positive time samples after half the number of samples.

ℎ(𝑛𝑛) = [ 0.5, −0.1768, −0.25, 0.1768, 0, 0.1768, −0.25, −0.1768]

ℎ(𝑛𝑛) = [ 0, 0.1768, −0.25, −0.1768, 0.5, −0.1768, −0.25, 0.1768]


Step-4: Make 𝒉𝒉(𝒏𝒏) symmetric

Make the impulse response symmetric (odd number of samples) by dropping one sample at the edge which has no
counterpart at the other edge. This is done to ensure linear phase. In this example that sample is the first sample
'0'.

ℎ(𝑛𝑛) = [0.1768, −0.25, −0.1768, 0.5, −0.1768, −0.25, 0.1768]

Note that after discarding the first sample, ℎ(𝑛𝑛) is now completely symmetrical around the central maximum value
'0.5'

Step-5: Window function

Since the impulse response is truncated, its frequency response will contain ripples in pass band and stop band. To
minimize the ripples and to have a flat frequency response, multiply the impulse response with a smoothing
window.
Hamming window is given:

2𝜋𝜋𝜋𝜋
𝑤𝑤(𝑛𝑛) = 0.54 − 0.46 cos � � 𝑓𝑓𝑓𝑓𝑓𝑓 𝑛𝑛 = 0, 1, 2, … … . . , 𝑁𝑁 − 1
𝑁𝑁 − 1

Since ℎ(𝑛𝑛) contains 7 samples, therefore we are required to calculate seven values of window function 𝑤𝑤(𝑛𝑛) by
substituting N=7 and n=0,1,2,3,4,5, and 6

𝑤𝑤(𝑛𝑛) = [0.08, 0.31, 0.77, 1, 0.77, 0.31, 0.08]

Step-6: Windowed impulse response 𝒉𝒉𝒘𝒘 (𝒏𝒏)

Apply window function 𝑤𝑤(𝑛𝑛) on the impulse response ℎ(𝑛𝑛) through point-by-point multiplication of ℎ(𝑛𝑛) with
𝑤𝑤(𝑛𝑛)

ℎ𝑤𝑤 (𝑛𝑛) = ℎ(𝑛𝑛) ∗ 𝑤𝑤(𝑛𝑛)

ℎ𝑤𝑤 (𝑛𝑛) = [0.014144, −0.0775, −0.136136, 0.5, −0.136136, −0.0775, 0.014144]

The calculated values of ℎ𝑤𝑤 (𝑛𝑛) are the required 6th order FIR filter coefficients.

𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 = 𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 + 1
𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 = 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 − 1
𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 = 7 − 1 = 6

Q2) Design a 6th order linear phase FIR filter with the following characteristics:
Sampling rate is 8000 Hz, stop-band from 2000 to 3000 Hz.
Write its frequency response, find its impulse response, find the windowed impulse response by using the
Hanning window defined as:

2𝜋𝜋𝜋𝜋
𝑤𝑤(𝑛𝑛) = 0.5 − 0.5 cos � � 𝑓𝑓𝑓𝑓𝑓𝑓 𝑛𝑛 = 0, 1, 2, … … . . , 𝑁𝑁 − 1
𝑁𝑁 − 1

Solution
Designing of FIR filter means to calculate FIR filter coefficients. The coefficients of FIR filter will be equal to its
windowed impulse response 𝑏𝑏𝑘𝑘 = ℎ𝑤𝑤 (𝑛𝑛)
Step-1: Frequency response 𝑯𝑯(𝒌𝒌)

In order to design a 6th order filter, we will need to define an 8 point frequency response. Since 𝐹𝐹𝑠𝑠 = 8000 Hz, so
every bin of frequency response will represent 1000 Hz [𝐹𝐹𝑠𝑠 ⁄𝑁𝑁 = 8000⁄8 = 1000 𝐻𝐻𝐻𝐻]. Stop-band is required to
define from 2000 to 3000 Hz. Therefore
𝐻𝐻(𝑘𝑘) = [1 1 0 0 1 0 0 1]

Step-2: Calculation of Impulse response 𝒉𝒉(𝒏𝒏)

Since frequency response and impulse response are transform pairs of each other. Therefore impulse response
ℎ(𝑛𝑛) can be calculated by taking IFFT of frequency response𝐻𝐻(𝑘𝑘).

ℎ(𝑛𝑛) = 𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖 [𝐻𝐻(𝑘𝑘)]


IFFT can be calculated by using either conjugate or swapping method

Note: Since H(K) contains only real numbers therefore its IFFT can also be calculated by just taking FFT and divide
the results of FFT by N.

𝐹𝐹𝐹𝐹𝐹𝐹 [𝐻𝐻(𝑘𝑘)]
ℎ(𝑛𝑛) = 𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖 [𝐻𝐻(𝑘𝑘)] =
𝑁𝑁

Calculate IFFT of 𝐻𝐻(𝑘𝑘) to find ℎ(𝑛𝑛): {Do it yourself using Radix-2 forward FFT}

ℎ(𝑛𝑛) = [ 0.5, 0.1768, 0.25, −0.1768, 0, − 0.1768, 0.25, 0.1768]

Step-3: Make 𝒉𝒉(𝒏𝒏) causal

Note: When we take FFT of anything, frequency domain samples after Fs/2 are actually negative frequencies. When
we take IFFT of anything, time domain samples after half number of samples are actually negative time samples. It
means that the first four samples are actually positive time samples and the last four samples are actually negative
time samples
Make the impulse response start from zero by copy pasting the negative time samples starting at index 0 and copy
pasting the positive time samples after half the number of samples.

ℎ(𝑛𝑛) = [ 0.5, 0.1768, 0.25, −0.1768, 0, − 0.1768, 0.25, 0.1768]

ℎ(𝑛𝑛) = [ 0, − 0.1768, 0.25, 0.1768, 0.5, 0.1768, 0.25, −0.1768]

Step-4: Make 𝒉𝒉(𝒏𝒏) symmetric

Make the impulse response symmetric (odd number of samples) by dropping one sample at the edge which has no
counterpart at the other edge. This is done to ensure linear phase. In this example that sample is the first sample
'0'.

ℎ(𝑛𝑛) = [ −0.1768, 0.25, 0.1768, 0.5, 0.1768, 0.25, −0.1768]

Note that after discarding the first sample, ℎ(𝑛𝑛) is now completely symmetrical around the central maximum value
'0.5'

Step-5: Window function

Since the impulse response is truncated, its frequency response will contain ripples in pass band and stop band. To
minimize the ripples and to have a flat frequency response, multiply the impulse response with a smoothing
window.
Hanning window is given:

2𝜋𝜋𝜋𝜋
𝑤𝑤(𝑛𝑛) = 0.5 − 0.5 cos � � 𝑓𝑓𝑓𝑓𝑓𝑓 𝑛𝑛 = 0, 1, 2, … … . . , 𝑁𝑁 − 1
𝑁𝑁 − 1

Since ℎ(𝑛𝑛) contains 7 samples, therefore we are required to calculate seven values of window function 𝑤𝑤(𝑛𝑛) by
substituting N=7 and n=0,1,2,3,4,5, and 6

𝑤𝑤(𝑛𝑛) = [0, 0.25, 1.75, 1, 1.75, 0.25, 0]

Step-6: Windowed impulse response 𝒉𝒉𝒘𝒘 (𝒏𝒏)

Apply window function 𝑤𝑤(𝑛𝑛) on the impulse response ℎ(𝑛𝑛) through point-by-point multiplication of ℎ(𝑛𝑛) with
𝑤𝑤(𝑛𝑛)

ℎ𝑤𝑤 (𝑛𝑛) = ℎ(𝑛𝑛) ∗ 𝑤𝑤(𝑛𝑛)

ℎ𝑤𝑤 (𝑛𝑛) = [0, 0.0625, 0.3094, 0.5, 0.3094, 0.0625, 0]

The calculated values of ℎ𝑤𝑤 (𝑛𝑛) are the required 6th order FIR filter coefficients.

𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 = 𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 + 1
𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 = 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 − 1
𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 = 7 − 1 = 6

Q3) Design a 6th order linear phase FIR filter with the following characteristics:
Sampling rate is 8000 Hz, pass-band from 0 to 2000 Hz.
Write its frequency response, find its impulse response, find the windowed impulse response by using the
Hamming window defined as:

2𝜋𝜋𝜋𝜋
𝑤𝑤(𝑛𝑛) = 0.54 − 0.46 cos � � 𝑓𝑓𝑓𝑓𝑓𝑓 𝑛𝑛 = 0, 1, 2, … … . . , 𝑁𝑁 − 1
𝑁𝑁 − 1

Q4) Design a 6th order linear phase FIR filter with the following characteristics:
Sampling rate is 8000 Hz, pass-band from 2000 to 4000 Hz.
Write its frequency response, find its impulse response, find the windowed impulse response by using the
Hanning window defined as:

2𝜋𝜋𝜋𝜋
𝑤𝑤(𝑛𝑛) = 0.5 − 0.5 cos � � 𝑓𝑓𝑓𝑓𝑓𝑓 𝑛𝑛 = 0, 1, 2, … … . . , 𝑁𝑁 − 1
𝑁𝑁 − 1

You might also like