You are on page 1of 5

EEE4114F - Lab Assignment 2

Work through each of the following questions, and satisfy yourself that you
understand the content. In some cases there is a final Hand in task — you are
expected to generate results for these tasks, and compile them into a single
electronic document (using Microsoft Word, for example).
Your hand-in solutions must be submitted by the due date, either in print form
or electronically.

1. Simple difference equation


(a) Create vectors b and a that contain the coefficients of x[n] and y[n],
respectively, in the following difference equation:

y[n] + 0.9y[n − 2] = 0.3x[n] + 0.6x[n − 1] + 0.3x[n − 2].

(b) Calculate y[n] analytically for x[n] = δ[n], assuming that the system
is causal.
(c) Now create a unit impulse vector, imp, of length 128. Generate the
first 128 points of the impulse response of the filter satisfying the
above difference equation, again making the assumption of causality.
Use stem to plot these values as a discrete-time signal versus time
(see help stem). It may help to plot just the first 10 or 20 points.
(d) Hand in: Using the subplot command, show the impulse sequence
on one set of axes and the filter response on a set of axes below. Use
the same range for the x-variable in both cases.

2. Impulse response with filter


(a) Use the filter function to generate and plot the impulse response

1
h[n] of the following difference equation:
π  1
y[n] − 1.8 cos y[n − 1] + 0.81y[n − 2] = x[n] + x[n − 1].
16 2
Plot h[n] in the range of −10 ≤ n ≤ 100.
(b) Also determine the impulse response analytically and confirm your
results.

3. Frequency response of rational transfer function filters


The MATLAB signal processing toolbox has a function
[H,W] = freqz(B,A,N,’whole’).
This function takes the filter coefficients A = [a(1), · · · , A(N + 1)] and
B = [b(1), · · · , B(M + 1)], and calculates the frequency response

jω b(1) + b(2)e− j ω + · · · + b(M + 1)e− j ωM


H (e ) =
a(1) + a(2)e−j ω + · · · + a(N + 1)e−j ωN
at N frequency points around the unit circle. Note that this response
corresponds to the LCCDE equation

a(1)y[n] + a(2)y[n − 1] + · · · + a(N + 1)y[n − N ] =


b(1)x[n] + b(2)x[n − 1] + · · · + b(M + 1)x[n − M].

Consider the difference equation from the previous question — the system
function is rational:
1 + 12 z −1
H (z) = .
1 − 1.8 cos(π/16)z −1 + 0.81z −2
The freqz function can be used to find the frequency response, since
evaluating the z-transform on the unit circle is equivalent to finding points
on the DTFT.
(a) Write a function myfreqz that emulates the behaviour of the function

2
freqz. Use this to make plots of the magnitude and phase of the
system specified above, with 512 frequency samples around the entire
unit circle. Note that for a complex sequence x, abs(x) can be used
to find the magnitude, and angle(x) the phase.
(b) Is this a highpass, lowpass, allpass, bandpass, or bandstop filter?
(c) Hand in: A plot (two axes on the same figure, using subplot) of the
magnitude and phase of the frequency response (for ω from 0 to 2π ) of

y[n] + 0.13y[n − 1] + 0.52y[n − 2] + 0.3y[n − 3] =


0.16x[n] − 0.48x[n − 1] + 0.48x[n − 2] − 0.16x[n − 3].

4. Computing the DTFT of a finite-length signal


The DTFT of a signal x[n] is

X

X (e ) = x[n]e− j ωn .
n=−∞

This is valid for infinitely long signals, which is a problem in MATLAB


since we cannot represent such a signal numerically. However, for
finite-duration signals the sum terminates at some limits, and we can
calculate the value of the sum.
Additionally, the DTFT is a function of the continuous variable ω, which
can also not be represented numerically. Nonetheless, we can evalate
samples of the DTFT at a discrete set of points, for example at evenly
spaced frequencies over the interval 0 to 2π .
The DTFT of a finite-duration signal (occupying the range 0 to L − 1 can
therefore be calculated at frequencies wk = 2π k/N using the formula
L−1
X
j ωk
X (e ) = X (e j 2πk/N
)= x[n]e− j (2πk/N)n
n=0

3
for k = 0, 1, . . . , N − 1.
(a) Write a function [H,W] = DTFT(h, N) that computes the DTFT
of the finite-length signal contained in the vector h. The values in this
vector are h = [h[0]h[1] · · · h[L − 1]], and the signal is assumed to
have zero values for n < 0 and n ≥ L. The function must evaluate the
DTFT at N equally-spaced frequency points, which are returned in the
vector W. The values of the DTFT samples must be returned in H.
(b) Use the function just written to find the DTFT of the finite-length pulse

1 0≤n<L
r [n] =
0 elsewhere

for L = 12. Choose the number of frequency samples to be 5 to 10


times the pulse width. Plot the magnitude and phase of the frequency
response obtained on two different sets of axes (using subplot).
Recall that the analytical solution to this problem is
sin(ωL/2) − j ω(L−1)/2
R(e j ω ) = e .
sin(ω/2)
Confirm that this expression gives the same results.
(c) Notice that the zeros of the frequency response are at regularly-spaced
locations. Repeat the DTFT calculation and magnitude plot for L = 15
(an odd-length pulse) and check the zero locations. What is a general
formula for the locations of the zeros?
(d) Hand in: Plots of the magnitude and phase response for
i. A rectangular pulse with length L = 16.
ii. A triangular pulse of the form

2n/L 0 ≤ n ≤ L/2
wt [n] =
2 − 2n/L L/2 < n < L ,

also with L = 16. The magnitude plot should be expressed in dBs:

4
20 log10 |H (e j ω )|. Comment on the difference in the resulting
mainlobe width (the first zero in the frequency response) and the
magnitude of the ripple at higher frequencies.

You might also like