LAB 8 - Sampling and Reconstruction of Signals
LAB 8 - Sampling and Reconstruction of Signals
LAB 8
• All tasks must be completed in this lab session for full credit.
• Students must show the output and MATLAB code for each task to the instructor
before proceeding to the next task.
References:
In many applications, for example, in digital communications, real-world analog signals are converted into
digital signals using sampling and quantization operations (collectively called analog-to-digital conversion, or
ADC). These discrete-time signals are processed by digital signal processors, and the processed signals are
converted into analog signals using a reconstruction operation (called digital-to-analog conversion, or DAC).
Using Fourier analysis, we can describe the sampling operation from the frequency-domain viewpoint, analyze
its effects, and then address the reconstruction operation. We will also assume that the number of quantization
levels is sufficiently large that the effect of quantization on discrete signals is negligible.
1.1 SAMPLING
Let 𝑥(𝑡) be an analog (absolutely integrable) signal. Its continuous-time Fourier transform (CTFT) is given by
𝑋𝐶 𝑒−𝑗Ω𝑡𝑑𝑡, (1)
where Ω is an analog frequency in rad/sec. The inverse continuous-time Fourier transform is given by
𝑥 . (2)
We now sample 𝑥(𝑡) at sampling interval 𝑇 seconds apart to obtain the discrete-time signal 𝑥[𝑛] as
𝑥[𝑛] = 𝑥(𝑛𝑇).
Let 𝑋 be the discrete-time Fourier transform of 𝑥[𝑛]. Then it can be shown [2, 3] that 𝑋(𝜔) is a
countable sum of amplitude-scaled, frequency-scaled, and translated versions of the Fourier transform 𝑋𝐶(Ω),
i.e.,
𝑋 . (3)
𝑘
This relation is known as the aliasing formula. The analog and digital frequencies are related through the
following relation
𝜔 = Ω𝑇, (4)
1
𝐹𝑆 = .
(5) 𝑇
From (3), we observe that, in general, the discrete signal is an aliased version of the corresponding analog signal
because higher frequencies are aliased into lower frequencies if there is an overlap between the consecutive 𝑋𝐶
(𝜔𝑇 − ). However, it is possible to recover the Fourier transform 𝑋𝐶(Ω) from 𝑋(𝜔) (or equivalently, the
2𝜋 𝑘
𝑇
analog 𝑥(𝑡) from its samples 𝑥[𝑛]) if the infinite replicas of 𝑋𝐶(Ω) do not overlap with each other to form
𝑋(𝜔), which is true only for bandlimited analog signals, i.e., those analog signal 𝑥(𝑡) for which
2
𝐹𝑆 > 2𝐹0. (7)
Otherwise, aliasing would occur in 𝑥[𝑛]. The sampling rate of 2𝐹0 for an analog band-limited signal is called the
Nyquist rate.
Note that after 𝑥(𝑡) is sampled, the highest analog frequency that 𝑥[𝑛] represents is 𝐹𝑆/2 (or 𝜔 = 𝜋).
However, if we sample 𝑥(𝑡) on a fine grid that has a sufficiently small time-increment to yield a smooth plot
In a strict sense, it is not possible to analyze analog signals using MATLAB unless we use the Symbolic toolbox.
and a large enough maximum time to show all the modes, then we can approximate its analysis. Let ∆𝑡 be the
grid interval such that . Then, the grid sequence
can be used as an array to simulate an analog signal. The sampling interval 𝑇 should not be confused with the
grid interval ∆𝑡, which is used strictly to represent an analog signal in MATLAB. Similarly, the Fourier
transform relation in (1) should also be approximated in light of (8) as follows:
𝑋𝐶 . (9)
𝑚 𝑚
Now if 𝑥(𝑡), and hence 𝑥𝐺(𝑚), is of finite duration, then (9) is similar to the discrete-time Fourier transform, given
below in (10), and hence can be implemented in MATLAB in a similar fashion to analyze the sampling phenomenon.
𝑗𝜔𝑘𝑛
, 𝜔𝑘 = 𝜋 𝑘,𝑘 = 0,1, … , 𝑀. (10)
𝑋𝑒
𝑀
𝑛
Example 1
Let 𝑥(𝑡) = 𝑒−1000|𝑡|. Then, using (1), we find the continuous-time Fourier transform as
𝑡
𝑑𝑡 = 0.002 .
Ω 2 𝑋𝐶 𝑒 𝑒
1 + ( 1000)
In order to evaluate 𝑋𝐶(Ω) numerically, we have to approximate 𝑥(𝑡) with the grid sequence 𝑥𝐺(𝑚), for
which, value of 𝑇 is required. From the above expression of 𝑋𝐶(Ω), we see that
3
𝑋𝐶 .
Hence, we choose Ω0 = 2𝜋(2000) rad/sec or 𝐹0 = 2000 Hz as the bandwidth of the signal 𝑥(𝑡). Choosing
the sampling frequency 𝐹𝑆 = 2𝐹0 (the Nyquist rate), we can find the grid interval as
,
𝐹𝑆
from which we can choose ∆𝑡 = 5 × 10−5 secs. Then, 𝑥𝐺(𝑚) = 𝑥(𝑚 5 × 10−5). Also, since 𝑒
, we approximate 𝑥(𝑡) with a finite-duration signal over the time interval
0. . Hence, the grid sequence, which is a MATLAB implementation of 𝑥(𝑡), is given by
4
Figure 1: Implementation of Example 1 in MATLAB
Task 1
Simulate the above piece of code in MATLAB. Why does the DTFT look similar to the CTFT ?
Task 2
Sample the signal in Example 1 at 𝐹𝑆 = 1000 samples/sec. Does the DTFT in this case look different from the
CTFT ? If yes, then why ?
5
1.2 SIGNAL RECONSTRUCTION
From the sampling theorem, it is clear that if we sample bandlimited analog signal 𝑥(𝑡) above its Nyquist rate,
then it can be reconstructed from its samples 𝑥[𝑛]. This reconstruction can be thought of as a two-step process:
𝑥𝑆 . (11)
𝑛=−∞
• Then, the impulse train is filtered through an ideal low-pass filter whose spectrum and impulse response
is given by [2, 3]
𝜋𝜋
Ω 𝑇, Ω ∈ [− ,] , sin 𝜋𝑡/𝑇
𝐻𝑟(Ω) = 𝑇 rect ( )={ 𝑇𝑇 ℎ𝑟(𝑡) = . (12)
2𝜋/𝑇 𝜋𝑡/𝑇
0, otherwise.
The reconstructed signal is then given by
∞
sin 𝜋(𝑡 − 𝑛𝑇)/𝑇
𝑥𝑟. (13)
𝑛=−∞
with a period of 𝑇.
The expression in (13) is the ideal interpolation formula from signal reconstruction from its samples generated
sin 𝜋(𝑚∆𝑡)/𝑇
6
ℎ𝑟(𝑚∆𝑡) = , (14)
𝜋(𝑚∆𝑡)/𝑇
which gives the reconstructed signal, from the discrete-time sequence 𝑥[𝑛], 𝑛1 ≤ 𝑛 ≤ 𝑛2, as
𝑛2
sin 𝜋(𝑚∆𝑡 − 𝑛𝑇)/𝑇
𝑥𝑟(𝑚∆𝑡) ≈ ∑ 𝑥[𝑛] , 𝑡1 ≤ 𝑚∆𝑡 ≤ 𝑡2. (15)
𝜋(𝑚∆𝑡 − 𝑛𝑇)/𝑇
𝑛=𝑛1
The expression in (15) can be evaluated in MATLAB using the following piece of code:
Note that the command ones(length(n), 1)*m*Dt makes n vertical copies of the row vector m*Dt and the
command (n.')*T*ones(1, length(m)) makes m horizontal copies of the column vector (n.')*T.
Task 3
1. 𝐹𝑆 = 3000 samples/sec,
2. 𝐹𝑆 = 6000 samples/sec,
and reconstruct the analog signal using ideal interpolation formula in (13). Plot the original and reconstructed
analog signals on the same graph for both cases and comment on the similarity/dissimilarity between them.
7
Code:
Dt = 5e-5;
m = -100:100;
xG = exp(-1000*abs(Dt));
T = 0.33e-4;
n = -25:25;
xn = exp(-1000*abs(n*T));
F_0 = 2000;
Omega_0 = 2*pi*F_0;
K = 500;
k = -K:K;
Omega = k*Omega_0/K;
Xc = xG * exp(-1i*Dt*(m.')*Omega) * Dt;
Xc = real(Xc);
K = 500;
k = -K:K;
w = k*pi/K;
8
Exercises:
Use the values of 𝒎, 𝒏, ∆𝒕 and 𝑭𝟎 from Example 1 for 𝒙(𝒕)=𝒆−𝟏𝟎𝟎𝟎|𝒕| in the following
problems.
1. A zero-order-hold interpolation holds the value of the sample until next sample is received, i.e.,
which can be obtained by convolving the impulse train in (11) with a filter having the following impulse
response
1, 0 ≤ 𝑡 ≤ 𝑇,
ℎ0(𝑡) = {
0,
otherwise.
Sample 𝑥(𝑡) at 𝐹𝑆 = 6000 samples/sec and plot the original and zero-order-held reconstructed signal
on the same graph.
Code:
Dt = 5e-5;
m = -100:100;
xG = exp(-1000*abs(m*Dt));
T = 1/6000;
n = -25:25;
xn = exp(-1000*abs(n*T));
t_ZOH = -0.5*T:T:0.5*T;
h0 = (abs(t_ZOH) <= T/2);
xn = double(xn(:));
h0 = double(h0(:));
xr_ZOH = conv(xn, h0, 'same') * T;
subplot(2, 1, 1);
plot(m*Dt*1000, xG, 'k', 'LineWidth', 1.5); hold on;
stem(n*T*1000, xn, 'r', 'MarkerFaceColor', 'r');
plot(n*T*1000, xr_ZOH, 'b--', 'LineWidth', 1.5);
legend('Analog Signal', 'Discrete Signal', 'ZOH Reconstructed Signal');
xlabel('Time (ms)');
ylabel('Amplitude');
title('Zero-Order Hold Interpolation');
9
2. A first-order-hold interpolation joins the consecutive samples of the discrete-time signal with a straight
line to give the reconstructed analog signal. Such reconstructed signal can be obtained by convolving the
impulse train in (11) with a filter having the following impulse response
|𝑡|
ℎ1(𝑡) = {1 − 𝑇, − 𝑇 ≤ 𝑡 ≤ 𝑇,
0, otherwise.
Sample 𝑥(𝑡) at 𝐹𝑆 = 8000 samples/sec and plot the original and first-order-held reconstructed signal
on the same graph.
Code:
Dt = 5e-5;
m = -100:100;
xG = exp(-1000*abs(m*Dt));
T = 1/8000;
n = -25:25;
xn = exp(-1000*abs(n*T));
t_FOH = -T:T:T;
h1 = (1 - abs(t_FOH)/T);
xr_FOH = conv(xn, h1,
'same') * T;
subplot(2, 1, 2);
plot(m*Dt*1000, xG, 'k', 'LineWidth', 1.5); hold on;
stem(n*T*1000, xn, 'r', 'MarkerFaceColor', 'r');
plot(n*T*1000, xr_FOH, 'b--', 'LineWidth', 1.5);
legend('Analog Signal', 'Discrete Signal', 'FOH Reconstructed Signal');
xlabel('Time (ms)');
ylabel('Amplitude');
title('First-Order Hold Interpolation');
10