Professional Documents
Culture Documents
Objectives
The goal of this lab is to study the response of FIR filters to inputs such as complex exponentials
and sinusoids. In the experiments of this lab, you will use firfilt(), or conv(), to implement filters
and freqz() to obtain the filter’s frequency response. As a result, you should learn how to
characterize a filter by knowing how it reacts to different frequency components in the input
Lab Instructions
The students should perform and demonstrate each lab task separately for step-wise evaluation
(please ensure that course instructor/lab engineer has signed each step after ascertaining its
functional verification)
Each group shall submit one lab report on LMS within 6 days after lab is conducted. Lab report
submitted via email will not be graded.
. Students are however encouraged to practice on their own in spare time for enhancing their
All questions should be answered precisely to get maximum credit. Lab report must ensure following
items:
Lab objectives
MATLAB codes
Results (graphs/tables) duly commented and discussed
Conclusion
can be found by using a general complex exponential as an input and observing the output or response.
^
Once the frequency response H (e j ω) has been determined, the effect of the filter on any complex
^
exponential may be determined by evaluating H ( e j ω) at the corresponding frequency. The output signal
y[n], will be a complex exponential whose complex amplitude has a constant magnitude and phase. The
phase describes the phase change of the complex sinusoid and the magnitude describes the gain applied to
the complex sinusoid. The frequency response of a general FIR linear time-invariant system is
In the example above, M = 1, and b0 = 1 /2 and b1 = 1/2 .
For FIR filters, the second argument of freqz( , 1, ) must always be equal to 1. The frequency vector ww
should cover an interval of length 2π for ω^ and its spacing must be fine enough to give a smooth curve
j^
ω
for H ( e ) .Note: we will always use capital HH for the frequency response.
Consult Chapter 6 for a mathematical proof that the outputs from each of these signals will be identical
^
(basically because x1[n] is equal to x2[n].The implication of periodicity is that a plot of H ( e j ω) only
needs to extend over the interval or any other interval of length 2π.
(a) Use Euler’s formula and complex number manipulations to show that the frequency response for the
4-point running average operator is given by:
subplot(2,1,2);
plot(omega_hat, phase);
xlabel('Frequency (\omega)');
ylabel('Phase (radians)');
title('Phase Response');
^
(c) In this part, use freqz.m in MATLAB to compute H (e j ω) numerically (from the filter coefficients and
plot its magnitude and phase versus ω^ . Write the appropriate MATLAB code to plot both the magnitude
^
and phase of H ( e j ω) Follow the example in Section 8.1.2. The filter coefficient vector forthe 4-point
averager is defined via:
bb = 1/4*ones(1,4);
Use the find command to determine the indices where HH is zero, and then use those indices to display
the list of frequencies where HH is zero. Since there might be round-off error in calculating HH, the
subplot(2,1,2);
plot(omega_hat, phase);
xlabel('Frequency (\omega)');
ylabel('Phase (radians)');
title('Phase Response');
(a) Use freqz() in MATLAB to get the frequency responses for the case where α = 0.8 and M = 9.
Plot the magnitude and phase of the frequency response for Filter #1, and also for Filter #2. Which
one of these filters is a lowpass filter?
Code:
ww = -pi:pi/400:pi; %defining ww vector from -pi to pi
bb1 = [1, 0.8^1, 0.8^2, 0.8^3, 0.8^4, 0.8^5, 0.8^6,0.8^7,0.8^8,0.8^9]; %defining
bb for the first filter
bb2 = [1, -0.8]; %defining bb for the second filter
%getting frequency response for the first filter
HH1 = freqz(bb1, 1, ww);
HH2 = freqz(bb2, 1, ww);
figure;
%plotting all of the frequency responses before multiplying
subplot(221);
plot(ww, abs(HH1));
title('Magnitude of Frequency Response of the first filter');
xlabel('Normalised Radian Frequency');
ylabel('Magnitude');
subplot(222);
plot(ww,angle(HH1));
title('Phasor of Frequency Response of the first filter');
xlabel('Normalised Radian Frequency');
ylabel('Angle');
subplot(223);
plot(ww, abs(HH2));
title('Magnitude of Frequency Response of the first filter');
xlabel('Normalised Radian Frequency');
ylabel('Magnitude');
subplot(224);
plot(ww,angle(HH2));
title('Phasor of Frequency Response of the first filter');
xlabel('Normalised Radian Frequency');
ylabel('Angle');
%multiplying the two frequency responses;
HH = HH1 .* HH2;
figure;
%plotting the cascaded system
subplot(211);
plot(ww, abs(HH));
title('Magnitude of Frequency Response after Multiplication');
xlabel('Normalised Radian Frequency');
ylabel('Magnitude');
subplot(212);
plot(ww,angle(HH));
(b) Plot the magnitude and phase of the frequency response of the overall cascaded system.
Combining individual frequency responses in series involves cascading filters, where the output of
one filter feeds into the input of the next. The overall magnitude response results from multiplying
the magnitudes of individual responses, depicting the combined attenuation or amplification effects.
Similarly, the overall phase response arises from summing the phase shifts introduced by each
filter, impacting the total phase shift experienced by the signal. This cascading process allows for
complex frequency shaping, influencing both magnitude and phase characteristics of the output
signal.
will have a zero in its frequency response at ω ^ = ω^n. For example, a filter designed to completely
j 0.5∗ pi∗n
eliminate signals of the form A k e would have the following coefficients because we would pick
the desired nulling frequency to be ω ^ = 0.5π. b0 = 1, b1 = −2 cos(0.5π) = 0, b2 = 1.
(a) Design a filtering system that consists of the cascade of two FIR nulling filters that will eliminate the
following input frequencies: ω^ = 0.44π, and ω ^ = 0.7π. For this part, derive the filter coefficients of
both nulling filters.
Code:
%defining coefficients
b1 = [1, -2*cos(0.44*pi), 1];
b2 = [1, -2*cos(0.7*pi), 1];
%defining both nulling filters
h1 = freqz(b1, 1, ww);
h2 = freqz(b2,1,ww);
%cascading the two filters
h = h1.*h2;
%plotting the cascaded filter
figure;
subplot(211);
plot(ww, abs(h));
title('Magnitude of Frequency Response of Cascaded Null Filter');
xlabel('Normalised Radian Frequency');
ylabel('Magnitude');
subplot(212);
(b) Generate an input signal x[n] that is the sum of three sinusoids:
Make the input signal 150 samples long over the range 0 < n < 149.
Code:
%creating a vector n for the input signal
n = 0:149;
xn = 5*cos(0.3*pi*n)+22*cos(0.44*pi*n-pi/3)+22*cos(0.7*pi*n-pi/4);
figure;
%plotting
plot(n,xn);
title('Input Signal');
xlabel('n');
ylabel('y-axis');
%defining coefficients
b1 = [1, -2*cos(0.44*pi), 1];
b2 = [1, -2*cos(0.7*pi), 1];
%passing xn through first filter
A = filter(b1,1,xn);
%passing the resultant through second filter
B = filter(b2,1,A);
%plotting the first fourty points
figure;
C = B(1:40);
plot(C);
ylabel('y-axis');
xlabel('n');
title('Filtered Signal first 40 points');
(d) Make a plot of the output signal—show the first 40 points. Determine (by hand) the exact
mathematical formula (magnitude, phase and frequency) for the output signal for n ≥ 5.
(e) Plot the mathematical formula determined in (d) with MATLAB to show that it matches the filter
output from filter over the range 5 ≤n ≤ 40.
YES IT MATCHES
(f) Explain why the output signal is different for the first few points. How many “start-up” points are
found, and how is this number related to the lengths of the filters designed in part (a)? Hint: consider
The output signal may exhibit differences in the first few points due to the transient response of the filter. In
digital signal processing, when a filter is applied to a signal, it takes some time for the filter to settle down to
its steady-state response. During this settling period, the output signal may exhibit deviations from the
expected response.
These deviations in the output signal for the first few points are often referred to as "start-up" or transient
effects. These transient effects occur because the filter initially processes incomplete data, especially for the
initial points where past values necessary for filtering are not available. As more input data becomes
available, the filter's output gradually stabilizes to its steady-state response.
The number of "start-up" points is related to the length of the filter. In the given scenario, the filter is
described as a cascade of two length-3 FIR (Finite Impulse Response) filters. When cascading filters, the total
number of start-up points is equal to the sum of the start-up points of individual filters minus the overlap
points.
For a length-3 FIR filter, the start-up points correspond to the first two points because the filter requires two
past input values to produce an output. When cascading two length-3 FIR filters, the total number of start-up
points would be 4 (2 start-up points for each filter) minus the overlap points.
The overlap points refer to the points where the two filters share common computation due to the cascading
operation. In this case, since the filters are identical and fully cascaded, there are no overlap points.
Therefore, the total number of start-up points for the cascade of two length-3 FIR filters is 4. This means that
the output signal may exhibit differences from the expected response for the first 4 points before stabilizing to
its steady-state response.
Conclusion:
has provided valuable insights into the design and analysis of filters for signal processing applications.
Through theoretical understanding and practical experimentation, we have explored the concept of
frequency response and its significance in shaping the characteristics of a filter.
By examining the nulling filter example, we have seen how careful design can selectively attenuate specific
frequency components of a signal while preserving others. Understanding the relationship between the
filter coefficients and the desired nulling frequencies enables us to tailor the filter response to our specific
needs.
Furthermore, we have observed the transient effects that occur in filter systems during the initial stages of
signal processing. These transient effects, often characterized by deviations from the expected response,
highlight the importance of considering the start-up behavior of filters in practical applications.
6.3 References
1. If you are working at home and do not have the function freqz.m, there is a substitute available called
freekz.m in the SP First toolbox
2. If the output of the freqz function is not assigned, then plots are generated automatically; however, the
magnitude is given in decibels which is a logarithmic scale. For linear magnitude plots a separate call to
plot is necessary.
3. For example, the input amplitude of the 0.7π component is 22, so its output amplitude must be less than
2.2.