Lol
Lol
Habib University
EE-252 Signal and Systems
(Lab adapted from DSP First, 2e)
Dr. Basit Memon
Objective: Familiarization with the characterization of FIR filters based on their frequency response
in MATLAB.
In-Lab:
Task 1: Frequency response of FIR filter in MATLAB using freqz command
Task 2: 4-point averaging fir filter
Task 3: Frequency response of Band pass filter in MATLAB.
Task 4: Passband width determination.
Task 5: Designing of passband filter.
Post-lab:
Task 6: FIR filter exercise.
In-Lab:
Frequency response of FIR filters
In the last lab, we got familiar with some discrete-time filters and played with them in the time
domain. In today's lab, we're going to characterize FIR filters based on their frequency response.
The frequency response is denoted by 𝐻(𝑗𝜔), and if the input of an LTI filter is 𝑥[𝑛] = 𝐴𝑒 𝑗𝜔𝑛
then the corresponding output is 𝑦[𝑛] = 𝐻(𝑗𝜔)𝐴𝑒 𝑗𝜔𝑛 . The frequency response is complex.
We can use MATLAB's freqz function to find the frequency response of a filter. As an example
say we want to find the frequency response of a filter described by:
1 1
𝑦[𝑛] = 𝑥[𝑛] + 𝑥[𝑛 − 1]:
2 2
The following MATLAB code can be used:
bb = [0.5, 0.5]; %-- Filter Coefficients
ww = -pi:(pi/100):pi; %-- Frequency vector
H = freqz(bb, 1, ww); %frequency reponse
subplot(2,1,1);
plot(ww, abs(H)), grid on
subplot(2,1,2);
plot(ww, angle(H)), grid on
xlabel(Normalized Radian Frequency)
Task 2: You computed the frequency of a four-point averaging filter earlier. An L-point
averaging filter is:
3
1
𝑦[𝑛] = ∑ 𝑥[𝑛 − 1]:
4
𝑘=0
Evaluate the effect of varying L on the pass-band of this filter.
Band-pass Filter
We can construct a band-pass filter by using an L-point FIR with impulse response:
2
ℎ[𝑛] = cos(𝜔𝑐 𝑛) , 0≤𝑛<𝐿
𝐿
where L is the length of the filter and 𝜔𝑐 is the center frequency for the pass-band.
Task 3: Plot the frequency response of this band-pass filter for 𝜔𝑐 = 0.44𝜋 and L = 10. You
can again use the freqz function. The values of the impulse response are the coefficients of this
filter. The width of the passband is again controlled by L.
Task 4 : Determine the passband width for the previous filter. You can use MATLAB's find
function to do this. Now plot the frequency response for L = 20 and L = 40. How is the passband
width related to the doubling or halving the filter length?
Task 5 (a): Design a bandpass filter that will pass the frequency component at 𝜔 = 0.44𝜋
but reduce the components near 𝜔 = 0.3𝜋 and 𝜔 = 0.7𝜋. The smallest value of L should be
chosen for which any frequency component satisfying |𝜔| ≤ 0.3𝜋 or 0.7𝜋 ≤ |𝜔| ≤ 𝜋 will be
reduced by a factor of 10 or more.
Task 5 (b): Test your filter by applying it to the signal.
2
𝜋 𝜋
𝑥 [𝑛] = 10 𝑐𝑜𝑠(0.3𝜋𝑛) + 40 𝑐𝑜𝑠 (0.44𝜋𝑛 − ) + 20 𝑐𝑜𝑠 (0.7𝜋𝑛 − ).
3 4
Hint: First find the output y[n] and then use fft to find the frequency response of the output as done
previously in Lab 9.
Post Lab
Task 6: Q1 Why do we only need to plot a 2𝜋 length interval for frequency response in
discrete-time?
2. Show that the frequency response of the 4-points averaging filter obtained using Euler's
identity and complex number manipulations is:
2 cos(1.5𝜔) + 2 cos(1.5𝜔) −𝑗1.5𝜔
𝐻 (𝑗𝜔) = [ ]𝑒
4
Verify that you obtained correct response by plotting this function and comparing it against
your previous plot obtained during the lab.