0% found this document useful (0 votes)
49 views10 pages

LAB 8 - Sampling and Reconstruction of Signals

Uploaded by

Jahanzaib Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views10 pages

LAB 8 - Sampling and Reconstruction of Signals

Uploaded by

Jahanzaib Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Name : Muhammad Jahanzeb

Roll No: 0032-Bsc-Engg-EE-21

LAB 8

Sampling and Reconstruction of Signals


Instructions:

• 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:

1. Digital Signal Processing using MATLAB: A problem solving companion, Vinay K.


Ingle and John G. Proakis, 4th Edition, Cengage Learning, 2016
2. Discrete Time Signal Processing, Alan. V. Oppenheim and Ronald. W. Schafer, 3 rd
Edition, Prentice Hall, 2010
3. Digital Signal Processing: Principles, Algorithms, and Applications, John G.
Proakis and Dimitris G. Manolakis, 4th Edition, Prentice Hall, 2007

1. SAMPLING AND RECONSTRUCTION OF ANALOG SIGNALS

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)

while the sampling frequency 𝐹𝑆, measured in samples/sec, is given by

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

𝑋𝐶(Ω) = 0, |Ω| > Ω0. (6)

1.1.1 SAMPLING THEOREM


A band-limited signal 𝑥(𝑡) with bandwidth 𝐹0 (in Hz) can be reconstructed from its sample values 𝑥[𝑛] =
𝑥(𝑛𝑇) if the sampling frequency 𝐹𝑆 = 1/𝑇 is greater than twice the bandwidth 𝐹0 of 𝑥(𝑡), i.e.

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 𝜔 = 𝜋).

1.1.2 MATLAB IMPLEMENTATION

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

𝑥𝐺(𝑚) = 𝑥(𝑚∆𝑡) (8)

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

𝑥𝐺(𝑚) = 𝑒−1000|𝑚 5×10−5| for .

Now, to study the effects of sampling, we sample 𝑥(𝑡) at 𝐹𝑆


period of 𝑇 = 0.2 msecs, to obtain 𝑥[𝑛] = 𝑥(𝑛𝑇). We note that
samples/sec, which gives a sampling
for .
Following is the MATLAB script for this implementation.
Code:
% Parameters X = fftshift(fft(fftshift(xn))); %
Dt = 5e-5; % Sampling interval for Efficient DTFT using FFT
continuous-time signal
T = 0.2e-3; % Sampling period for discrete- % Plotting
time signal figure;
F_0 = 2000; % Maximum frequency for Fourier subplot(3, 1, 1);
Transform plot(m*Dt*1000, xG);
hold on;
% Time vectors stem(n*T*1000, xn);
m = -100:100; xlabel('Time (ms)');
n = -25:25; ylabel('Amplitude');
title('Analog and Discrete-Time Signals');
% Generate analog and discrete-time signals legend('Analog Signal', 'Discrete-Time
xG = exp(-1000*abs(m*Dt)); Signal');
xn = exp(-1000*abs(n*T));
subplot(3, 1, 2);
% Continuous-Time Fourier Transform (CTFT) plot(Omega/(2*pi*1000), abs(Xc));
K = 500; % Number of frequency points xlabel('Frequency (kHz)');
Omega = (-K:K) * (2*pi*F_0/K); % Frequency ylabel('Magnitude');
vector title('Continuous-Time Fourier Transform');
Xc = fftshift(fft(fftshift(xG))) * Dt; %
Efficient CTFT using FFT subplot(3, 1, 3);
plot(w/pi, abs(X));
% Ensure Omega and Xc have the same length xlabel('Normalized Frequency (pi)');
Omega = Omega(1:length(Xc)); ylabel('Magnitude');
title('Discrete-Time Fourier Transform');
% Discrete-Time Fourier Transform (DTFT)
w = (-K:K) * (pi/K); % Frequency vector

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:

• First, the samples are converted into a weighted impulse train:

𝑥𝑆 . (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

1.2.1 MATLAB IMPLEMENTATION


The ideal reconstruction or low-pass or interpolation filter in (12) is implemented in MATLAB as

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:

>> n = n1:n2; t = t1:t2; m = (1/Dt)*t;


>> xr = xn * sinc( (1/T) * ( ones(length(n), 1)*m*Dt - (n.')*T*ones(1, length(m)) ) );

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

Using the values of 𝑚, 𝑛, ∆𝑡 and 𝐹0 from Example 1, sample 𝑥(𝑡) = 𝑒−1000|𝑡| at

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;

% Calculate Discrete-Time Fourier Transform (DTFT) of xn


X = zeros(1, length(w)); % Initialize X as a zero vector of the same length as w
for i = 1:length(w)
X(i) = sum(xn .* exp(-1i * w(i) * n)); % DTFT formula
end

% Subplot 1: Analog and Discrete-Time Signals


subplot(3,1,1);
plot(m*Dt*1000, xG);
xlabel('t (msec)');
ylabel('Amplitude');
hold on; % Retain the current plot
stem(n*T*1000, xn); % Plot the discrete-time signal
legend('Analog signal', 'Discrete-time signal');
title('Analog and Discrete-Time Signals');

% Subplot 2: Continuous-Time Fourier Transform


subplot(3,1,2);
plot(Omega/(2*pi*1000), Xc);
xlabel('Frequency (KHz)');
ylabel('Amplitude');
title('Continuous-Time Fourier Transform');

% Subplot 3: Discrete-Time Fourier Transform


subplot(3,1,3);
plot(w/pi, abs(X)); % Plot the magnitude of the DTFT
xlabel('Frequency (in pi units)');
ylabel('Amplitude');
title('Discrete-Time Fourier Transform');

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.,

𝑥𝑟(𝑡) = 𝑥[𝑛], 𝑛𝑇 ≤ 𝑡 ≤ (𝑛 + 1)𝑇,

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

You might also like