University of Illinois at Urbana-Champaign
ECE 311: Digital Signal Processing Lab
LAB 3: SOLUTIONS
Chandra Radhakrishnan Peter Kairouz
Problem 1
2π 1
(a) Using T = Ωs = 104
1 1
x[n] = xa (nT ) = cos 2π × 103 × 4 n + cos 2π × 1.4 × 103 × 4 n
10 10
π 7π
= cos( n) + cos( n)
5 25
(b) Figure 1 shows the plot of magnitude of the sampled version of Xa (Ω). It can be seen from the figure that we can distinguish
between the frequencies.
20
−20
−40
−60
−80
−100
−120
−5000 0 5000
Frequency (Hz)
Figure 1: Problem 1b: Magnitude of the sampled version of Xa (Ω) for N = 5000
(c) Figures 2 and 3 show the magnitude of the sampled version of Xa (Ω) for N = 100 and N = 20 respectively. It can be seen
that for we can distinguish between f1 and f2 for N = 100.
−20
−40
−60
−80
−100
−120
−140
−5000 0 5000
Frequency (Hz)
Figure 2: Problem 1c: Magnitude of the sampled version of Xa (Ω) for N=100
1
8
−2
−5000 0 5000
Frequency (Hz)
Figure 3: Problem 1c: Magnitude of the sampled version of Xa (Ω) for N = 20
(d) The condition that main lobes of the two functions do not overlap is that,
1 4π
N>
T Ω1 − Ω0
4π
= 104
2π × 0.4 × 103
200
= = 50
4
The above result agrees with our observation in Parts (b) and (c).
Problem 2
(a) Plot is given in Fig. 4 below.
(b) The relation between analog frequency Ω and DFT (length-M ) index k is Ω = ω/T = (2πk/M )/T (need to adjust by 2π for
k = 173).
(i) (2π73/256)/(1/240) = 136.9π (2π173/256 − 2π)/(1/240) = −155.6π
(ii) (2π73/256)/(1/30) = 17.1π (2π173/256 − 2π)/(1/30) = −19.5π
(iii) (2π73/256)/(1/5) = 2.85π (2π173/256 − 2π)/(1/5) = −3.24π
(iv) (2π73/256)/(1/120) = 68.4π (2π173/256 − 2π)/(1/120) = −77.8π
(v) (2π73/256)/(1/30) = 17.1π (2π173/256 − 2π)/(1/30) = −19.5π
(vi) (2π73/256)/(1/15) = 8.55π (2π173/256 − 2π)/(1/15) = −9.73π
(c) Consider a single sinusoidal component that is sampled with a sampling period T :
x[n] = A cos (Ω0 nT ) , 0 ≤ n ≤ N − 1
−1
The DTFT of {x[n]N
n=0 } is:
N
X −1
Xd (ω) = A cos (Ω0 nT )e−jωn
n=0
N −1
A X −j(ω−Ω0 T )n
= [e + e−j(ω+Ω0 T )n ]
2 n=0
N −1 AN sinc[(ω − Ω0 T ) N2 ] N −1 AN sinc[(ω + Ω0 T )
N
2]
= e−j(ω−Ω0 T ) 2
1 + e−j(ω+Ω0 T ) 2
2 sinc[(ω − Ω0 T ) 2 ] 2 sinc[(ω + Ω0 T ) 12 ]
= T1 (ω) + T2 (ω)
2
(i) N=64, T=1/240 (ii) N=64, T=1/30
100 40
80
30
60
|X[k]|
|X[k]|
20
40
10
20
0 0
0 50 100 150 200 250 0 50 100 150 200 250
k k
(iii) N=64, T=1/5 (iv) N=32, T=1/120
40 50
40
30
30
|X[k]|
|X[k]|
20
20
10
10
0 0
0 50 100 150 200 250 0 50 100 150 200 250
k k
(v) N=32, T=1/30 (vi) N=32, T=1/15
20 20
15 15
|X[k]|
|X[k]|
10 10
5 5
0 0
0 50 100 150 200 250 0 50 100 150 200 250
k k
Figure 4: Problem 2a: The DFT of the given sequences.
Therefore, the DTFT of a single sinusoidal signal with a finite length consists of two periodic sincs, T1 (ω) and T2 (ω), with
N −1
peaks located at ω = ±Ω0 T . The M-point DFT of {x[n]n=0 } is a set of samples of the DTFT:
2π
X[k] = Xd (ω = k) , k = 0, . . . , M − 1
M
Effect of the number of samples N and the sampling interval T :
i) Number of samples N :
From the Xd (ω) expression obtained at the beginning of part (c), it is seen that N determines the amplitude of the two
periodic sincs (= AN 4π
2 ) and the width of the two mainlobes (= N (in radians) or
2.256
N (in number of indices)). The
larger N gives the higher magnitude peaks. The smaller N gives the wider mainlobes. This hypothesis can be verified
in plots of (ii) and (v) above.
3
ii) Sampling interval T :
The Fourier transform of A cos (Ω0 nT ) has two deltas at Ω = ±Ω0 and the DTFT of the finite duration A cos (Ω0 nT )
has two periodic sincs at ω = ±(Ω0 T mod 2π) (the two periodic sincs will converge to deltas as the number of samples
−1
N increases). By taking a set of M samples of Xd (ω) on [0, 2π), the DFT {X[k]M k=0 } is obtained (M is fixed at 256
in this problem). If |Ω0 T | > π, cos (Ω0 T n) = cos ((Ω0 T mod 2π)n), where (Ω0 T mod 2π) ∈ [−π, π]. Then, the analog
frequency higher than the Nyquist frequency (|Ω0 | > π/T ) is wrapped or aliased to a lower digital frequency and
appears to correspond to a lower analog frequency. This effect can be seen in the plot of case (iii). Note: If an analog
signal is bandlimited to Ωmax , the requirement for no aliasing (Ωmax T < π) in A/D is equivalent to the Nyquist criterion
1
(T < 2fmax ).
(d) There are two points to consider:
i) Using the criterion that there be no more than 50% overlap of the two peaks, then to distinguish the two frequencies it
is required that
2π 2π
NT ≥ = = 1.875
|Ω1 − Ω2 | 2π − 14π
15
Since N T = 2, N T ≥ 1.875, this condition is satisfied.
ii) T must also satisfy the Nyquist criterion
1 1
T < = = 0.5 sec
2fmax 2·1
1 14π
Note: fmax = 2π max (2π, 15 ) = 1. Therefore, choosing T < 0.5 sec would resolve the sinusoidal components in xa (t).
2π
(e) The frequency separation condition used is N T ≥ |Ω1 −Ω2 | . Therefore, for N = 128,
2π 2π 15 1
T ≥ = 14π = ≈
N |Ω1 − Ω2 | 128 2π − 15
1024 64
The Nyquist criterion is also required to avoid aliasing: T < 12 since fmax = 1 Hz. Therefore, the best choice would
1
be approximately 64 ≤ T ≤ 21 . Small T in this interval means fast sampling of the given analog signal. However, the
implementation of fast sampling is usually expensive, and fast sampling is not necessary as long as no aliasing occurs.
Therefore, it is desired that the sampling interval be as long as possible. So, T = 0.5 sec.
(f) With T = 1/30,
2π
NT ≥ ⇒ Nmin = 57
2π − 14π
15
Thus, N = 57 is needed for the separation of the two peaks. Experimenting in MATLAB, it is found that the mainlobes
corresponding to the two sinusoids do not overlap for N = 56 and experience increase overlap for smaller N . In fact, with
MATLAB, Nmin = 40. Note that, as mentioned in the notes, the two peaks may be resolvable even when the mainlobes have
minor overlap. Therefore, the N = 57 estimate for the minimum number of samples is conservative. Zoomed-in plots are
shown in Fig. 5 to highlight the resolution of the sinusoids.
Problem 3
(a) The two sequences are shown below,
x[n] = [1, 1, 1, 1, 1, 1]
h[n] = [0, 1, 2, 3, 4, 5]
Flipping h[n] and performing the convolution yields the following result,
y[n] = [0, 1, 3, 6, 10, 15, 15, 14, 12, 9, 5]
(b) The convolution by conv command can be done as follows,
4
N=39 N=40 N=41
20 20 20
18 18 18
16 16 16
14 14 14
12 12 12
|X[k]|
|X[k]|
|X[k]|
10 10 10
8 8 8
6 6 6
4 4 4
2 2 2
0 0 0
0 10 20 30 40 0 10 20 30 40 0 10 20 30 40
k k k
Figure 5: Problem 2f: Plot for Problem 2f
x = [1 1 1 1 1 1];
h = [0 1 2 3 4 5];
y = conv(x,h);
In this case the sequences start at n = 0, hence the output y is between 0 ≤ n ≤ 8. The result can be plotted using stem
command.
idx = (0:8);
stem(idx,y);
title(’Convolved result for problem 3b’),xlabel(’time index, n’), ylabel(’convolved output, y[n]=h[n]*x[n]’)
The plot of the convolved result is shown in Fig. 6.
Plot for problem 3b
15
convolved output, y[n]=h[n]*x[n]
10
0
0 2 4 6 8 10
time index, n
Figure 6: Problem 3: Plot for Problem 3b
(c) Note that the sequence h[n + 5] is advanced in time. The result will be time shifted with the same sample values. The result
is shown in Fig. 7
5
idx = (0:8)-4;
stem(idx,y);
title(’Convolved result for problem 3b’),xlabel(’time index, n’), ylabel(’convolved output, y[n]=h[n+5]*x[n]’
Plot for problem 3c
15
convolved output, y[n]=h[n+5]*x[n]
10
0
−5 0 5
time index, n
Figure 7: Problem 3: Plot for Problem 3c
Problem 4
(a) The plots for h1 [n] and h2 [n] are shown in Figs. 8 and 9 respectively. Note that the filter command can be used to compute
h1 [n] as shown below,
x = [1 zeros(1,19)];
h1 =filter([1],[1 -3/5],[1 zeros(1,19)]);
Please refer to the MATLAB code func_prob4a for computing h2 [n]. The function can be called by using the input
inp = [1 zeros(1,19)] as shown below,
h2 = func_prob4a(inp);
Plot for problem 4a − h1[n]
1
0.8
Impulse Response, h1[n]
0.6
0.4
0.2
0
0 5 10 15 20
time index, n
Figure 8: Problem 4a: Impulse Response h1 [n]
(b) The step response for System I can be calculated as follows,
6
Plot for problem 4a − h2[n]
1
0.8
Impulse Response, h2[n]
0.6
0.4
0.2
0
0 5 10 15 20
time index, n
Figure 9: Problem 4a: Impulse response h2 [n]
x = [1 zeros(1,19)];
s1 =filter([1],[1 -3/5],[1 ones(1,19)]);
The step response for System II can be computed using the same function func_prob4a. The input vector is inp = ones(1,20),
h2 = func_prob4a(inp);
(c) The convolution for the impulse responses computed in part (a) can be computed using the conv command.
z1 = conv(h1,ones(1,20));
z2 = conv(h2,ones(1,20));
(d) Figures 10 and 11 show the plots of s1,z1 and s2,z2. Note that only the first 20 samples of z1 and z2 are shown.It can be
seen that s1,z1 are the same while s2,z2 are different. This is because System II is a time-varying system. The conv and
filter commands assume that the system is LSI. The commands for generating the plots are shown below,
>> x = (0:19);
>> subplot(2,1,1)
>> stem(x,s1)
>> subplot(2,1,2)
>> stem(x,z1(1:20))
>> subplot(2,1,1)
>> stem(x,s2)
>> subplot(2,1,2)
>> stem(x,z2(1:20))
7
Plot for 4d − sequences s1 and z1
3
s1
1
0
0 5 10 15 20
time index, n
2
z1
1
0
0 5 10 15 20
time index, n
Figure 10: Problem 4a: Impulse Response h1 [n]
Plot for 4d − s2 and z2
2
s2
0
0 5 10 15 20
time index, n
2
z2
0
0 5 10 15 20
time index, n
Figure 11: Problem 4a: Impulse response h2 [n]