Lecture22_DigitalFilters04_0

CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
7.3. Window Method
We have seen that in the design of FIR filters, Gibbs oscillations are produced in the passband
and stopband, which are not desirable features of the FIR filter. To solve this problem,
window method (Fourier transform design with window method) is developed.
The Gibbs oscillations mainly result from the abrupt truncation of the infinite-length
coefficient sequence of impulse response of the FIR filter. A window function is a symmetrical
function which can gradually weight the designed FIR coefficients down to zeros at both ends
of for the range βˆ’π‘΄ ≀ 𝒏 ≀ 𝑴. Applying the window sequence to the filter coefficients gives
π’‰π’˜ (𝒏) = 𝒉(𝒏) βˆ™ π’˜(𝒏)
where, π’˜(𝒏) designates the window function. Commonly used window functions in FIR filters
are:
1. Rectangular Window:
(7.15)
π’˜π’“π’†π’„ (𝒏) = 𝟏,
βˆ’π‘΄β‰€π’β‰€π‘΄
2. Triangular (Bartlett) Window:
(7.16)
π’˜π’•π’“π’Š (𝒏) = 𝟏 βˆ’
|𝒏|
,
𝑴
βˆ’π‘΄β‰€π’β‰€π‘΄
3. Hanning Window:
(7.16)
𝒏𝝅
),
𝑴
π’˜π’‰π’‚π’ (𝒏) = 𝟎. πŸ“ + 𝟎. πŸ“ 𝐜𝐨𝐬 (
βˆ’π‘΄β‰€π’β‰€π‘΄
4. Hamming Window:
(7.16)
𝒏𝝅
),
𝑴
π’˜π’‰π’‚π’Ž (𝒏) = 𝟎. πŸ“πŸ’ + 𝟎. πŸ’πŸ” 𝐜𝐨𝐬 (
βˆ’π‘΄β‰€π’β‰€π‘΄
5. Blackman Window:
(7.16)
𝒏𝝅
πŸπ’π…
) + 𝟎. πŸŽπŸ– 𝐜𝐨𝐬 (
),
𝑴
𝑴
π’˜π’ƒπ’π’‚π’„π’Œ (𝒏) = 𝟎. πŸ’πŸ + 𝟎. πŸ“ 𝐜𝐨𝐬 (
βˆ’π‘΄β‰€π’β‰€π‘΄
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia
CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
Example 7.5
(a) Calculate the filter coefficients for a 3-tap FIR lowpass filter with a cutoff frequency of
800 Hz and a sampling rate of 8000 Hz using the Hamming window function.
(b) Determine the transfer function and difference equation of the designed FIR system.
(c) Compute and plot the frequency response.
Solution
Part (a): We first determine the normalized cutoff frequency
πŸ–πŸŽπŸŽ
𝛀𝒄 = πŸπ… 𝒇𝒄 𝑻𝒔 = πŸπ… × πŸ–πŸŽπŸŽπŸŽ = 𝟎. πŸπ… radians
In this case πŸπ‘΄ + 𝟏 = πŸ‘, therefore, using table 7.1
π›€πœ
,
𝒏=𝟎
𝛑
𝒉(𝒏) = {
sin(π›€πœ 𝒏)
βˆ’π‘΄ ≀ 𝒏 ≀ 𝑴
𝝅𝒏
Therefore,
𝒉(𝟎) =
π›€πœ 𝟎. πŸπ…
=
= 𝟎. 𝟐
𝝅
𝝅
𝒉(𝟏) =
sin(π›€πœ ) sin(𝟎. πŸπ…)
=
= 𝟎. πŸπŸ–πŸ•πŸ
𝝅
𝝅
𝒉(βˆ’πŸ) = 𝒉(𝟏) = 𝟎. πŸπŸ–πŸ•πŸ (using symmetry)
The windowed impulse response is calculated as
π’‰π’˜ (𝟎) = 𝒉(𝟎) π’˜π’‰π’‚π’Ž (𝟎) = 𝟎. 𝟐 × πŸ. 𝟎 = 𝟎. 𝟐
π’‰π’˜ (𝟏) = 𝒉(𝟏) π’˜π’‰π’‚π’Ž (𝟏) = 𝟎. πŸπŸ–πŸ•πŸ × πŸŽ. πŸŽπŸ– = 𝟎. πŸŽπŸπŸ’πŸ—πŸ•
π’‰π’˜ (βˆ’πŸ) = 𝒉(βˆ’πŸ) π’˜π’‰π’‚π’Ž (βˆ’πŸ) = 𝟎. πŸπŸ–πŸ•πŸ × πŸŽ. πŸŽπŸ– = 𝟎. πŸŽπŸπŸ’πŸ—πŸ•
Delaying 𝒉(𝒏) by 𝑴 = 𝟏 samples, we get π’ƒπŸŽ = π’‰π’˜ (βˆ’πŸ) = 𝟎. πŸŽπŸπŸ’πŸ—πŸ•, π’ƒπŸ = π’‰π’˜ (𝟎) = 𝟎. 𝟐,
and π’ƒπŸ = π’‰π’˜ (𝟏) = 𝟎. πŸŽπŸπŸ’πŸ—πŸ•.
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia
CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
Part (b): Therefore, the transfer function in this case is
𝑯(𝒛) = π’ƒπŸŽ + π’ƒπŸ π’›βˆ’πŸ + π’ƒπŸ π’›βˆ’πŸ = 𝟎. πŸŽπŸπŸ’πŸ—πŸ• + 𝟎. πŸπ’›βˆ’πŸ + 𝟎. πŸŽπŸπŸ’πŸ—πŸ•π’›βˆ’πŸ
The difference equation is
π’š(𝒏) = 𝟎. πŸŽπŸπŸ’πŸ—πŸ•π’™(𝒏) + 𝟎. πŸπ’™(𝒏 βˆ’ 𝟏) + 𝟎. πŸŽπŸπŸ’πŸ—πŸ•π’™(𝒏 βˆ’ 𝟐)
Part (c): The frequency response of the filter is
𝑯(𝒆𝒋𝛀 ) = 𝟎. πŸŽπŸπŸ’πŸ—πŸ• + 𝟎. πŸπ’†βˆ’π’‹π›€ + 𝟎. πŸŽπŸπŸ’πŸ—πŸ•π’†βˆ’πŸπ’‹π›€
It can be written as
𝑯(𝒆𝒋𝛀 ) = π’†βˆ’π’‹π›€ (𝟎. πŸŽπŸπŸ’πŸ—πŸ•π’†π’‹π›€ + 𝟎. 𝟐 + 𝟎. πŸŽπŸπŸ’πŸ—πŸ•π’†βˆ’πŸπ’‹π›€ )
= π’†βˆ’π’‹π›€ (𝟎. 𝟐 + 𝟎. πŸŽπŸπŸ’πŸ—πŸ•(𝒆𝒋𝛀 + π’†βˆ’πŸπ’‹π›€ )) = π’†βˆ’π’‹π›€ (𝟎. 𝟐 + 𝟎. πŸŽπŸπŸ’πŸ—πŸ• × πŸcos(𝛀))
= π’†βˆ’π’‹π›€ (𝟎. 𝟐 + 𝟎. πŸŽπŸπŸ—πŸ—πŸ’ cos(𝛀))
Thus, the magnitude frequency response is
|𝑯(𝒆𝒋𝛀 )| = 𝟎. 𝟐 + 𝟎. πŸŽπŸπŸ—πŸ—πŸ’ cos(𝛀)
And the phase response is
βˆ π‘―(𝒆𝒋𝛀 ) = {
βˆ’π›€,
βˆ’π›€ + 𝝅
𝟎. 𝟐 + 𝟎. πŸŽπŸπŸ—πŸ—πŸ’ cos(𝛀) > 0
𝟎. 𝟐 + 𝟎. πŸŽπŸπŸ—πŸ—πŸ’ cos(𝛀) < 0
A MATLAB program to plot the frequency response is given in the following.
%
% Example 7.5
%
fs = 8000;
B = [0.01497 0.2 0.01497];
A = [1];
[h w] = freqz(B, A, 1024);
f = w*fs/(2*pi);
phi = 180*unwrap(angle(h))/pi;
figure
subplot(2,1,1), plot(f, 20*log10(abs(h))); grid on;
axis([0 fs/2 -30 0]);
xlabel('Frequency (Hz)'); ylabel('Magnitude');
subplot(2,1,2), plot(f, phi); grid on;
axis([0 fs/2 -200 50]);
xlabel('Frequency (Hz)'); ylabel('Phase (degrees)');
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia
CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
Figure 7.4: Frequency response in Example 7.2
Example 7.6
(a) Design a 5-tap FIR bandreject filter with a lower cutoff frequency of 2000 Hz, an upper
cutoff frequency of 2400 Hz and a sampling rate of 8000 Hz using the Hamming window
method.
(b) Determine the transfer function.
Solution
Part (a): We first determine the normalized cutoff frequencies
𝟐𝟎𝟎𝟎
𝛀𝑳 = πŸπ… 𝒇𝑳 𝑻𝒔 = πŸπ… × πŸ–πŸŽπŸŽπŸŽ = 𝟎. πŸ“π… radians
πŸπŸ’πŸŽπŸŽ
𝛀𝑯 = πŸπ… 𝒇𝑯 𝑻𝒔 = πŸπ… × πŸ–πŸŽπŸŽπŸŽ = 𝟎. πŸ”π… radians
In this case πŸπ‘΄ + 𝟏 = πŸ“, therefore, using table 7.1
𝝅 βˆ’ 𝛀𝑯 + 𝛀𝑳
𝒏=𝟎
𝝅
𝒉(𝒏) = {
𝐬𝐒𝐧(𝛀𝑯 𝒏) 𝐬𝐒𝐧(𝛀𝑯 𝒏)
βˆ’
+
βˆ’πŸ ≀ 𝒏 ≀ 𝟐
𝒏𝝅
𝒏𝝅
Therefore,
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia
CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
𝒉(𝟎) =
𝝅 βˆ’ 𝛀𝑯 + 𝛀𝑳 𝝅 βˆ’ 𝟎. πŸ”π… + 𝟎. πŸ“π…
=
= 𝟎. πŸ—
𝝅
𝝅
𝒉(𝟏) = βˆ’
𝐬𝐒𝐧(𝛀𝑯 ) 𝐬𝐒𝐧(𝛀𝑯 )
𝐬𝐒𝐧(𝟎. πŸ”π…) 𝐬𝐒𝐧(𝟎. πŸ“π…)
+
=βˆ’
+
= 𝟎. πŸŽπŸπŸ“πŸ“πŸ–
𝝅
𝝅
𝝅
𝝅
𝒉(𝟐) = βˆ’
𝐬𝐒𝐧(πŸπ›€π‘― ) 𝐬𝐒𝐧(𝛀𝑯 𝟐)
𝐬𝐒𝐧(𝟏. πŸπ…) 𝐬𝐒𝐧(𝝅)
+
=βˆ’
+
= 𝟎. πŸŽπŸ—πŸ‘πŸ“πŸ“
πŸπ…
πŸπ…
𝝅
𝝅
𝒉(βˆ’πŸ) = 𝒉(𝟏) = 𝟎. πŸŽπŸπŸ“πŸ“πŸ– (using symmetry)
𝒉(βˆ’πŸ) = 𝒉(𝟐) = 𝟎. πŸŽπŸ—πŸ‘πŸ“πŸ“ (using symmetry)
Applying the Hamming window function, we have
𝟎×𝝅
π’˜π’‰π’‚π’Ž (𝟎) = 𝟎. πŸ“πŸ’ + 𝟎. πŸ’πŸ” 𝐜𝐨𝐬 (
) = 𝟏. 𝟎
𝟐
𝟏×𝝅
π’˜π’‰π’‚π’Ž (𝟏) = 𝟎. πŸ“πŸ’ + 𝟎. πŸ’πŸ” 𝐜𝐨𝐬 (
) = 𝟎. πŸ“πŸ’
𝟐
𝟐×𝝅
π’˜π’‰π’‚π’Ž (𝟐) = 𝟎. πŸ“πŸ’ + 𝟎. πŸ’πŸ” 𝐜𝐨𝐬 (
) = 𝟎. πŸŽπŸ–
𝟐
π’˜π’‰π’‚π’Ž (βˆ’πŸ) = π’˜π’‰π’‚π’Ž (𝟏) = 𝟎. πŸ“πŸ’ (using symmetry)
π’˜π’‰π’‚π’Ž (βˆ’πŸ) = π’˜π’‰π’‚π’Ž (𝟐) = 𝟎. πŸŽπŸ– (using symmetry)
The windowed impulse response is calculated as
π’‰π’˜ (𝟎) = 𝒉(𝟎) π’˜π’‰π’‚π’Ž (𝟎) = 𝟎. πŸ— × πŸ. 𝟎 = 𝟎. πŸ—
π’‰π’˜ (𝟏) = 𝒉(𝟏) π’˜π’‰π’‚π’Ž (𝟏) = 𝟎. πŸŽπŸπŸ“πŸ“πŸ– × πŸŽ. πŸ“πŸ’ = 𝟎. πŸŽπŸŽπŸ–πŸ’πŸ
π’‰π’˜ (𝟐) = 𝒉(𝟐) π’˜π’‰π’‚π’Ž (𝟐) = 𝟎. πŸŽπŸ—πŸ‘πŸ“πŸ“ × πŸŽ. πŸŽπŸ– = 𝟎. πŸŽπŸŽπŸ•πŸ’πŸ–
π’‰π’˜ (βˆ’πŸ) = 𝒉(βˆ’πŸ) π’˜π’‰π’‚π’Ž (βˆ’πŸ) = 𝟎. πŸŽπŸπŸ“πŸ“πŸ– × πŸŽ. πŸ“πŸ’ = 𝟎. πŸŽπŸŽπŸ–πŸ’πŸ
π’‰π’˜ (βˆ’πŸ) = 𝒉(βˆ’πŸ) π’˜π’‰π’‚π’Ž (βˆ’πŸ) = 𝟎. πŸŽπŸ—πŸ‘πŸ“πŸ“ × πŸŽ. πŸŽπŸ– = 𝟎. πŸŽπŸŽπŸ•πŸ’πŸ–
Delaying 𝒉(𝒏) by 𝑴 = 𝟐 samples, we get π’ƒπŸŽ = π’‰π’˜ (βˆ’πŸ) = 𝟎. πŸŽπŸŽπŸ•πŸ’πŸ–, π’ƒπŸ = π’‰π’˜ (βˆ’πŸ) =
𝟎. πŸŽπŸŽπŸ–πŸ’πŸ, π’ƒπŸ = π’‰π’˜ (𝟎) = 𝟎. πŸ—, π’ƒπŸ‘ = π’‰π’˜ (𝟏) = 𝟎. πŸŽπŸŽπŸ–πŸ’πŸ and π’ƒπŸ’ = π’‰π’˜ (𝟐) = 𝟎. πŸŽπŸŽπŸ•πŸ’πŸ–.
Part (b): Therefore, the transfer function in this case is
𝑯(𝒛) = π’ƒπŸŽ + π’ƒπŸ π’›βˆ’πŸ + π’ƒπŸ π’›βˆ’πŸ + π’ƒπŸ‘ π’›βˆ’πŸ‘ + π’ƒπŸ’ π’›βˆ’πŸ’
= 𝟎. πŸŽπŸŽπŸ•πŸ’πŸ– + 𝟎. πŸŽπŸŽπŸ–πŸ’πŸπ’›βˆ’πŸ + 𝟎. πŸ—π’›βˆ’πŸ + 𝟎. πŸŽπŸŽπŸ–πŸ’πŸπ’›βˆ’πŸ‘ + 𝟎. πŸŽπŸŽπŸ•πŸ’πŸ–π’›βˆ’πŸ’
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia
CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
FIR Filter Length Estimation using Window Functions
Given the required passband ripples specification and stopband attenuation, the appropriate
window length can be estimated based on the performances of the window functions. For
illustrative purpose, we use the lowpass filter frequency domain specification (the same can
be extended to other types of filter specifications).
The normalized transition band frequency is
defined as
βˆ†π’‡ = |𝒇𝒔𝒕𝒐𝒑 βˆ’ 𝒇𝒑𝒂𝒔𝒔 |/𝒇𝒔
Based on this, the FIR filter lengths for
various window functions are given in Table
7.7 below. It can be noted that the cutoff
frequency is determined by
𝒇𝒄 = (𝒇𝒔𝒕𝒐𝒑 βˆ’ 𝒇𝒑𝒂𝒔𝒔 )/𝟐
The passband ripple is defined as
πœΉπ’‘ 𝒅𝑩 = 𝟐𝟎 βˆ™ log10 (𝟏 + πœΉπ’‘ )
while the stopband attenuation is defined as
πœΉπ’” 𝒅𝑩 = βˆ’πŸπŸŽ βˆ™ log 10 (πœΉπ’” )
Table 7.7: Filter length estimation using window (βˆ†π’‡ = |𝒇𝒔𝒕𝒐𝒑 βˆ’ 𝒇𝒑𝒂𝒔𝒔 |/𝒇𝒔 )
Window
Type
Rectangular
Hanning
Hamming
Blackman
Window
Function π’˜(𝒏), βˆ’π‘΄ ≀ 𝒏 ≀ 𝑴
𝟏
𝒏𝝅
𝟎. πŸ“ + 𝟎. πŸ“ 𝐜𝐨𝐬 ( )
𝑴
𝒏𝝅
𝟎. πŸ“πŸ’ + 𝟎. πŸ’πŸ” 𝐜𝐨𝐬 ( )
𝑴
𝒏𝝅
πŸπ’π…
𝟎. πŸ’πŸ + 𝟎. πŸ“ 𝐜𝐨𝐬 ( ) + 𝟎. πŸŽπŸ– 𝐜𝐨𝐬 (
)
𝑴
𝑴
Window
Length
𝑡 = 𝟎. πŸ—/βˆ†π’‡
Passband
Ripple (dB)
0.7416
Stopband
Attenuation
(dB)
21
𝑡 = πŸ‘. 𝟏/βˆ†π’‡
0.0546
44
𝑡 = πŸ‘. πŸ‘/βˆ†π’‡
0.0194
53
𝑡 = πŸ“. πŸ“/βˆ†π’‡
0.0017
74
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia
CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
Example 7.10
Design a bandpass FIR filter with the following specifications:
Lower Stopband
= 0 - 500 Hz
Passband
= 1600 - 2300 Hz
Upper Stopband
= 3500 - 4000 Hz
Stopband Attenuation
= 50 dB
Passband ripple
= 0.05dB
Sampling rate
= 8000 Hz
Determine the FIR filter length and the cutoff frequency to be used in the design equation.
Solution
We first determine the normalized transition band
|πŸπŸ”πŸŽπŸŽ βˆ’ πŸ“πŸŽπŸŽ|
= 𝟎. πŸπŸ‘πŸ•πŸ“
πŸ–πŸŽπŸŽπŸŽ
|πŸ‘πŸ“πŸŽπŸŽ βˆ’ πŸπŸ‘πŸŽπŸŽ|
βˆ†π’‡πŸ =
= 𝟎. πŸπŸ“
πŸ–πŸŽπŸŽπŸŽ
βˆ†π’‡πŸ =
The filter lengths based on above transition bands (for Hamming window) are
πŸ‘. πŸ‘
= πŸπŸ’
𝟎. πŸπŸ‘πŸ•πŸ“
πŸ‘. πŸ‘
π‘΅πŸ =
= 𝟐𝟐
𝟎. πŸπŸ“
The nearest higher odd 𝑡 is chosen as for the Hamming window
𝑡 = πŸπŸ“
π‘΅πŸ =
The lower and higher cutoff frequencies for the bandpass filter will be
πŸπŸ”πŸŽπŸŽ + πŸ“πŸŽπŸŽ
= πŸπŸŽπŸ“πŸŽ 𝑯𝒛
𝟐
πŸ‘πŸ“πŸŽπŸŽ + πŸπŸ‘πŸŽπŸŽ
π’‡πŸ =
= πŸπŸ—πŸŽπŸŽ 𝑯𝒛
𝟐
π’‡πŸ =
The normalized lower and higher cutoff frequencies for the bandpass filter will be
πŸπŸŽπŸ“πŸŽ
𝛀𝑳 = πŸπ… 𝒇𝑳 𝑻𝒔 = πŸπ… ×
= 𝟎. πŸπŸ”πŸπŸ“π… 𝐫𝐚𝐝𝐒𝐚𝐧𝐬
πŸ–πŸŽπŸŽπŸŽ
𝛀𝑯 = πŸπ… 𝒇𝑯 𝑻𝒔 = πŸπ… ×
πŸπŸ—πŸŽπŸŽ
= 𝟎. πŸ•πŸπŸ“π… 𝐫𝐚𝐝𝐒𝐚𝐧𝐬
πŸ–πŸŽπŸŽπŸŽ
In this case πŸπ‘΄ + 𝟏 = πŸπŸ“ will be the number of taps for the bandpass filter.
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia
CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
A MATLAB program to plot the frequency response is given in the following.
%
% Example 7.10
%
Ntap = 25;
% number of filter taps
Ftype = 3;
% lowpass filter
WnL = 0.2625*pi;
% lower cutoff frequency
WnH = 0.725*pi;
% upper cutoff frequency
Wtype = 4;
% Hamming window type
fs = 8000;
% sampling rate
% use firwd to compute B coefficients
B = firwd(Ntap, Ftype, WnL, WnH, Wtype);
A = 1;
omega = 0:0.01:pi;
fHz = omega*fs/(2*pi);
% frequency response of the fir filter
[hz, w] = freqz(B, A, omega);
magnitude = 20*log10(abs(hz));
phase = 180*unwrap(angle(hz))/pi;
figure,
subplot(2,1,1); plot(fHz,
magnitude,'k','LineWidth',2); grid on;
xlabel('Frequency (Hz)'); ylabel('Magnitude
response(dB)');
subplot(2,1,2); plot(fHz, phase,'k','LineWidth',2);
grid on;
xlabel('Frequency (Hz)'); ylabel('Phase
response(degrees)');
Figure 7.18: Frequency response in Example 7.2
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia
CEN352 Digital Signal Processing
by Dr. Anwar M. Mirza
Lecture No. 22
Date: December, 2012
Department of Computer Engineering
College of Computer & Information Sciences, King Saud University
Ar Riyadh, Kingdom of Saudi Arabia