0% found this document useful (0 votes)
53 views

Sameer Jameel - Lab 10

This document describes designing digital FIR filters using window functions. It discusses ideal lowpass filters and how to truncate the impulse response using a window to obtain a causal FIR filter. Popular window functions like rectangular, Hann, Hamming, and Kaiser are described. The document provides a MATLAB example to design a lowpass FIR filter with specified passband and stopband edges and ripple using the Hamming window, and verifies it meets the specifications. It also gives tasks to design the same lowpass filter using the Kaiser window, and to design a specified bandpass filter using a window function.

Uploaded by

Muhammad Sameer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Sameer Jameel - Lab 10

This document describes designing digital FIR filters using window functions. It discusses ideal lowpass filters and how to truncate the impulse response using a window to obtain a causal FIR filter. Popular window functions like rectangular, Hann, Hamming, and Kaiser are described. The document provides a MATLAB example to design a lowpass FIR filter with specified passband and stopband edges and ripple using the Hamming window, and verifies it meets the specifications. It also gives tasks to design the same lowpass filter using the Kaiser window, and to design a specified bandpass filter using a window function.

Uploaded by

Muhammad Sameer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EE-384: Digital Signal Processing Spring 2021

Laboratory 10: FIR Filter Windowing design


Instructor: Mr Ammar Naseer EE UET New Campus

Aims
In digital signal processing there are two important types of systems. The first type of system performs
signal filtering in the time domain and hence are called digital filters. The second type of systems
provide signal representation in the frequency domain and are called spectrum analyzers. In Lab 6 we
described signal representations using the DFT. In this lab sessions we will study several basic design
algorithms for FIR filters. These designs are mostly of the frequency selective type; that is, we will design
primarily multiband lowpass, highpass, bandpass, and bandstop filters.

Pre-Lab:
Window Design Techniques
The basic idea behind the window design is to choose a proper ideal frequency-selective filter (which
always has a noncausal, infinite-duration impulse response) and then to truncate (or window) its
impulse response to obtain a linear-phase and causal FIR filter. Therefore the emphasis in this method is
on selecting an appropriate windowing function and an appropriate ideal filter. We will denote an ideal
frequency-selective filter by , which has a unity magnitude gain and linear-phase characteristics
over its passband, and zero response over its stopband. An ideal LPF of bandwidth is given by

| |
( ) { (10.1)
| |

Where is also called the cutoff frequency, and α is called the sample delay. The impulse response of
this filter is of infinite duration and is given by

[ ( )] ∫ ( ) (10.2)
[ ]

Note that is symmetric with respect to α, a fact useful for linear phase FIR filter. To obtain an FIR
filter from , one has to truncate on both sides. To obtain a causal and linear-phase FIR filter
h(n) of length M, we must have

Page 1
Laboratory 10: FIR Filter Windowing design 10.2

{ (10.3)

This operation is called "windowing." In general, h(n) can be thought of as being formed by the product
of and a window function w(n) as follows:

(10.4)

Where

{ (10.5)

Basic window design idea: For the given filter specifications, choose the filter length M and a window
function w(n) for the narrowest main lobe width and the smallest side lobe attenuation possible. Note
that the passband tolerance and the stopband tolerance cannot be specified independently. We
generally take care of alone, which results in .

The following finite-duration sequences are some popular windows:

Table shown below provide a summary of window function characteristics in terms of their transition
widths (as a function of M) and their minimum stopband attenuations in dB.. Note that the transition
widths and the stopband attenuations increase as we go down the table. The Hamming window appears
to be the best choice for many applications.

Table 10.1: Summary of commonly used window function characteristics


Laboratory 10: FIR Filter Windowing design 10.3

Kaiser window: This is one of the most useful and optimum windows. It is optimum in the sense of
providing a large main lobe width for the given stopband attenuation, which implies the sharpest
transition width. This window can provide different transition widths for the same M, which is
something other windows lack. Kaiser has developed empirical design equations, which we provide
below

Given , , and

Norm transition width

(10.6)

Choose for specified as

(10.7)

The window length M is then chosen to satisfy

(10.8)

Matlab implementation

MATLAB provides several functions to implement window functions discussed in this section. A brief
description of these functions follows.

 w=boxcar(M) returns the M-point rectangular window function in array w.


 w=hann(M) returns the M-point Hann window function in array w.
 w=hamming(M) returns the M-point Hamming window function in array w.
 w=kaiser(M,beta) returns the beta-valued M-point rectangular window function in array w.

Using these functions, we can use MATLAB to design FIR filters based on the window technique, which
also requires an ideal lowpass impulse response hd(n). Therefore it is convenient to have a simple
routine that creates hd(n) as shown here.

function hd = ideal_lp(wc,M);
% Ideal LowPass filter computation
% __________________________________
% [hd] = ideal lp(wc,M)
% hd = ideal impulse response between 0 to M-1
% wc = cutoff frequency in radians
% M = length of the ideal filter
Laboratory 10: FIR Filter Windowing design 10.4

%
alpha = (M-1)/2; n = [0:1:(M-1)];
m = n - alpha;
fc = wc/pi;
hd = fc*sinc(fc*m);
end

We will also need the ideal bandpass filter impulse response hd(n). Note that this impulse response can
be obtained from two ideal lowpass magnitude responses, provided they have the same phase
response.

The ideal bandstop impulse response can also he determined from the ideal lowpass impulse response
using similar method and its function in command window would be represented as

>> hd = ideal_lp(wc1, M) - ideal_lp(wc2, M);

Therefore the MATLAB function ideal_lp is sufficient to determine the impulse response of an ideal
bandpass and bandstop filter.

To display the frequency-domain plots of digital filters, MATLAB provides the freqz function, which we
used in earlier experiments. Using this function, we have developed a modified version, called freqz_m,
which returns the magnitude response in absolute as well as in relative dB scale, the phase response,
and the group delay response.

function [db,mag,pha,grd,w] = freqz_m(b,a);


% Modified version of freqz subroutine
% ______________________________________________
% [db,mag,pha,grd,w] = freqz_m(b,a);
% db = Relative magnitude in dB computed over 0 to pi radians
% mag = absolute magnitude computed over 0 to pi radians
% pha = Phase response in radians over 0 to pi radians
% grd = Group delay over 0 to pi radians
% w = 501 frequency samples between 0 to pi radians
% b = numerator polynomial of H(z) (for FIR: b=h)
% a = denominator polynomial of H(z) (for FIR: a=[1])
%
[H,w] = freqz(b,a,1000,'whole');
H = (H(1:1:501))';
w = (w(1:1:501))';
mag = abs(H); db = 20*log10((mag+eps)/max(mag));
Laboratory 10: FIR Filter Windowing design 10.5

pha = angle(H); grd = grpdelay(b,a,w);


end

10A. Design a digital FIR lowpass filter with the following specifications:

Choose an appropriate window function from Table. Determine the impulse response and provide a plot
of the frequency response of the designed filter.

Both the Hamming and Blackman windows can provide attenuation of more than 50 dB. Let us choose
the Hamming window, which provides the smaller transition band and hence has the smaller order.
Although we do not use the passband ripple value of Rp = 0.25 dB in the design, we will have to check
the actual ripple from the design and verify that it is indeed within the given tolerance. The design steps
are given in the following MATLAB script.

>> wp = 0.2*pi;
>> ws = 0.3*pi;
>> tr_width = ws - wp;
>> M = ceil(6.6*pi/tr_width) + 1
M =
67
>> n=[0:1:M-1];
>> wc = (ws+wp)/2; % Ideal LPF cutoff frequency
>> hd = ideal_lp(wc,M);
>> w_ham = (hamming(M))';
>> h = hd .* w_ham;
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> deltaw = 2*pi/1000;
>> Rp=-(min(db(1:1:wp/ deltaw+1)));% Actual Passband Ripple Rp=0.0394
>> As=-round(max(db(ws/deltaw+1:1:501)));%Min Stopband attenuation
As=52
>> subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
>> axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('hd(n)')
>> subplot(2,2,2); stem(n,w_ham);title('Hamming Window')
>> axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)')
>> subplot(2,2,3); stem(n,h);title('Actual Impulse Response')
>> axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('h(n)')
>> subplot(2,2,4); plot(w/pi,db);title('Magnitude Response in
dB');grid;
>> axis([0 1 -100 10]); xlabel('frequency in pi units');
ylabel('Decibels')
Laboratory 10: FIR Filter Windowing design 10.6

Main Lab
10B: For the design specifications given in 10A, choose the Kaiser window to design the necessary
lowpass filter.

10C: Design the following digital bandpass filter using window function from Table

Lower stopband edge: ,

Lower passband edge: ,

Upper passband edge: ,

upper stopband edge: ,

These quantities are shown in Figure

You might also like