Sameer Jameel - Lab 10
Sameer Jameel - Lab 10
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 .
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.
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
(10.6)
(10.7)
(10.8)
Matlab implementation
MATLAB provides several functions to implement window functions discussed in this section. A brief
description of these functions follows.
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
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.
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