Programming Assignment #1 Solutions
EENG 5610
Fall 2025
Digital Signal Processing
100 Points
Objective:
Generate sample audio data in Matlab, compute and analyze autocorrelation.
Requirements:
1. Record an audio clip of your own speech for 20 seconds with 8 kHz sampling rate, 1 channel, 8
bits/sample.
2. Implement/generate a signal containing “echoes” (delayed versions of the audio signal combined
with original audio signal).
3. Compute and analyze autocorrelation functions.
Page 1 of 8
Procedure:
1. Record an audio clip of your own speech for 20 seconds with 8 kHz sampling rate, 1 channel, 8
bits/sample.
2. Save your recording, and playback the speech to ensure you have properly recorded the audio
signal. State your observations from listening to the playback.
Hey I can hear my voice over the speakers successfully playing back the voice sample I recorded!
Now if I could just sing, I’d be a rock star!! The following figure depicts the plot of my audio signal,
s(n).
3. Load your speech file into Matlab, which will be treated as the loudspeaker signal, s(n). Plot the
sampled signal, s(n).
Input Audio Signal
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
0 2 4 6 8 10 12 14 16 18 20
Time (s)
Problem Statement:
An audio signal 𝑠𝑠(𝑡𝑡) generated by a loudspeaker is reflected at two different walls with reflections
coefficients 𝑟𝑟1 and 𝑟𝑟2 . The signal 𝑥𝑥(𝑡𝑡) recorded by a microphone close to the loudspeaker after
sampling is
𝑥𝑥(𝑛𝑛) = 𝑠𝑠(𝑛𝑛) + 𝑟𝑟1 𝑠𝑠(𝑛𝑛 − 𝑘𝑘1 ) + 𝑟𝑟2 𝑠𝑠(𝑛𝑛 − 𝑘𝑘2 )
where 𝑘𝑘1 and 𝑘𝑘2 are the delays of the two echoes.
a) Determine the autocorrelation 𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙)of the signal 𝑥𝑥(𝑛𝑛).
b) Can you obtain 𝑟𝑟1 , 𝑟𝑟2 , 𝑘𝑘1 , and 𝑘𝑘2 by observing 𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙)?
c) What happens if 𝑟𝑟2 = 0?
4. Synthesize/generate the signal 𝑥𝑥(𝑛𝑛) with the parameters 𝑟𝑟1 = 0.6, 𝑟𝑟2 = 0.3, 𝑘𝑘1 = 5 seconds, 𝑘𝑘2 =
12 seconds. Playback the speech to ensure you have properly synthesized/generated x(n).
Described your observations from listening to the playing of x(n). Note: You will need to convert
Page 2 of 8
the given values of k1 and k2 in seconds to the values in the unit of samples when you
synthesize the signal.
The figure above depicts the impulse response of the filter, h(n). The peaks of h(n) correspond to
the following difference equation:
ℎ(𝑛𝑛) = 𝛿𝛿(𝑛𝑛) + 𝑟𝑟1 𝛿𝛿(𝑛𝑛 − 𝑘𝑘1 ) + 𝑟𝑟2 𝛿𝛿(𝑛𝑛 − 𝑘𝑘2 )
where 𝑟𝑟1 = 0.6, 𝑟𝑟2 = 0.3, 𝑘𝑘1 = 𝐹𝐹𝑠𝑠 *5 seconds, 𝑘𝑘2 = 𝐹𝐹𝑠𝑠 *12 seconds and 𝐹𝐹𝑠𝑠 = 8000 samples/sec. When
h(n) is convolved with s(n) to produce x(n), then x(n) contains the input signal s(n) and the attenuated
and delayed versions of s(n) i.e.
𝑥𝑥(𝑛𝑛) = 𝑠𝑠(𝑛𝑛) + 𝑟𝑟1 𝑠𝑠(𝑛𝑛 − 𝑘𝑘1 ) + 𝑟𝑟2 𝑠𝑠(𝑛𝑛 − 𝑘𝑘2 )
Upon playback, I can hear my voice over the speakers successfully playing back the voice sample
I recorded, but I also notice two (2) delayed versions (“echoes”) of my voice sample are also
included in the playback. The plot/curve for x(n) is shown in the following figure.
Page 3 of 8
Output Signal, x(n) = s(n) * h(n)
Delay = [5 12] sec, Amplitude = [0.6 0.3]
1
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
0 2 4 6 8 10 12 14 16 18 20
Time (s)
Page 4 of 8
5. Compute the autocorrelation function of the signal x(n) in Matlab and plot it versus the lag
parameter l in the unit of seconds (not samples).
The normalized autocorrelation function for positive lags of x(n) is depicted in the figure below.
Note the autocorrelation function is symmetric about lag = 0. Note/observe the secondary and
ternary peaks occurring at lags of 5 and 12 seconds respectfully thus indicating strong similarities
within the signal 𝑥𝑥(𝑛𝑛).
Normalized ACF of Output Signal, x(n) = s(n) * h(n)
Delay = [5 12] sec, Amplitude = [0.6 0.3]
1
0.8
0.6
0.4
Amplitude
0.2
-0.2
-0.4
-20 -15 -10 -5 0 5 10 15 20
Lag (s)
Page 5 of 8
The following figure depicts the normalized autocorrelation function respectively for positive and
negative lags of s(n). Note the autocorrelation function is symmetric about lag = 0.
Normalized ACF of input s(n), rss(n)
1
0.8
0.6
0.4
Amplitude
0.2
-0.2
-0.4
-20 -15 -10 -5 0 5 10 15 20
Lag (s)
6. By observing the autocorrelation function plot, can you estimate the values of 𝑟𝑟1 , 𝑟𝑟2 , 𝑘𝑘1 and 𝑘𝑘2 ? If
so, explain.
The autocorrelation function for x(n) is computed as follows:
∞
𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙) = � 𝑥𝑥(𝑛𝑛)𝑥𝑥(𝑛𝑛 − 𝑙𝑙)
𝑛𝑛=−∞
𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙) = � [𝑠𝑠(𝑛𝑛) + 𝑟𝑟1 𝑠𝑠(𝑛𝑛 − 𝑘𝑘1 ) + 𝑟𝑟2 𝑠𝑠(𝑛𝑛 − 𝑘𝑘2 ) ][𝑠𝑠(𝑛𝑛 − 𝑙𝑙) + 𝑟𝑟1 𝑠𝑠(𝑛𝑛 − 𝑙𝑙 − 𝑘𝑘1 ) + 𝑟𝑟2 𝑠𝑠(𝑛𝑛 − 𝑙𝑙 − 𝑘𝑘2 ) ]
𝑛𝑛=−∞
𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙) = (1 + 𝑟𝑟12 + 𝑟𝑟22 )𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙) + 𝑟𝑟1 [𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙 + 𝑘𝑘1 ) + 𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙 − 𝑘𝑘1 )] +
𝑟𝑟2 [𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙 + 𝑘𝑘2 ) + 𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙 − 𝑘𝑘2 )] + 𝑟𝑟1 𝑟𝑟2 [𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙 + 𝑘𝑘1 − 𝑘𝑘2 ) + 𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙 + 𝑘𝑘2 − 𝑘𝑘1 )]
Observe from the above equation that 𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙) will have peaks at 𝑙𝑙 = 0, ± 𝑘𝑘1 , ± 𝑘𝑘2 , and ±
(𝑘𝑘1 +𝑘𝑘2 ). Assuming 𝑘𝑘1 < 𝑘𝑘2 , then we can determine 𝑟𝑟1 and 𝑘𝑘1 . Most notably we observe
and can determine 𝑘𝑘1 = 5 seconds and approximate 𝑟𝑟1 to be 0.35 respectively from the
plots in Procedure 6 and the above expression. The problem is to determine 𝑘𝑘2 and 𝑟𝑟2
from the other peaks. Note the approximated value for 𝑟𝑟1 is off by almost a factor of 2.
Page 6 of 8
7. Compute the autocorrelation function of the signal x(n) in Matlab by setting 𝑟𝑟2 = 0 as in c) (use
the same values as above for other parameters) and plot it versus the lag parameter l in the unit
of seconds (not samples).
For completeness, I reproduced the filter, h(n), for the case where 𝑟𝑟2 = 0, and h(n) is shown in the
following figure.
The output signal resulting from convolving h(n) with s(n) is depicted in the following figure.
Output Signal, x(n) = s(n) * h(n)
Delay = [5] sec, Amplitude = [0.6]
1
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
0 2 4 6 8 10 12 14 16 18 20
Time (s)
Page 7 of 8
The normalized autocorrelation function for positive and negative lags of x(n). Note the
autocorrelation function is symmetric about lag = 0.
Normalized ACF of Output Signal, x(n) = s(n) * h(n)
Delay = [5] sec, Amplitude = [0.6]
1
0.8
0.6
0.4
Amplitude
0.2
-0.2
-0.4
-20 -15 -10 -5 0 5 10 15 20
Lag (s)
8. By observing the autocorrelation function plot, can you estimate the values of r1, and k1? If so,
explain.
The autocorrelation function for x(n) is computed as follows:
∞
𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙) = � 𝑥𝑥(𝑛𝑛)𝑥𝑥(𝑛𝑛 − 𝑙𝑙)
𝑛𝑛=−∞
𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙) = � [𝑠𝑠(𝑛𝑛) + 𝑟𝑟1 𝑠𝑠(𝑛𝑛 − 𝑘𝑘1 ) + 𝑟𝑟2 𝑠𝑠(𝑛𝑛 − 𝑘𝑘2 ) ][𝑠𝑠(𝑛𝑛 − 𝑙𝑙) + 𝑟𝑟1 𝑠𝑠(𝑛𝑛 − 𝑙𝑙 − 𝑘𝑘1 ) + 𝑟𝑟2 𝑠𝑠(𝑛𝑛 − 𝑙𝑙 − 𝑘𝑘2 ) ]
𝑛𝑛=−∞
Setting r2 = 0 results in
𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙) = (1 + 𝑟𝑟12 )𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙) + 𝑟𝑟1 [𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙 + 𝑘𝑘1 ) + 𝑟𝑟𝑠𝑠𝑠𝑠 (𝑙𝑙 − 𝑘𝑘1 )]
Observe from the above equation that 𝑟𝑟𝑥𝑥𝑥𝑥 (𝑙𝑙) will have peaks at 𝑙𝑙 = 0 and ± 𝑘𝑘1 . Then we
can determine 𝑟𝑟1 and 𝑘𝑘1 more easily. Most notably we observe and can determine 𝑘𝑘1 = 5
seconds and 𝑟𝑟1 respectively from the plots in Procedure 7 and the above expression. One
can then estimate 𝑟𝑟1 by setting 𝑙𝑙 = 0 and solving accordingly using the computed data for
rxx and rss. In the case of my voice, my estimate of 𝑟𝑟1 is 𝑟𝑟1 ≈ 0.52 (taking positive root of
the quadratic polynomial). Note the estimate for 𝑟𝑟1 is much closer to the actual 𝑟𝑟1 value.
Page 8 of 8