0% found this document useful (0 votes)
32 views14 pages

Sampling and Reconstruction of Signals

Uploaded by

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

Sampling and Reconstruction of Signals

Uploaded by

Muhammad Zayed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Title: Study of Sampling, Quantization, and Reconstruction of Analog

Signals
1. Abstract

This experiment illustrates the core principles of sampling, quantization, and


reconstruction of analog signals within the context of Digital Signal Processing (DSP). In
digital systems, continuous analog signals are converted into discrete-time signals
through sampling and quantization, and later reconstructed into analog form using
interpolation techniques. The experiment investigates the mathematical and graphical
relationships between continuous-time and discrete-time signals, highlights the effects of
aliasing caused by under-sampling, and examines Zero-Order Hold (ZOH) and First-
Order Hold (FOH) methods for signal reconstruction. MATLAB was employed to
simulate these processes, visualize signal spectra, and analyze the impact of varying
sampling frequencies on signal quality.

2. Theory

In many Digital Signal Processing (DSP) applications, real-world signals exist in analog
form and must be transformed into digital signals for analysis and manipulation. This
conversion process consists of three key stages: sampling, quantization, and
reconstruction. Sampling captures discrete data points from a continuous-time signal,
quantization maps these samples to discrete amplitude levels, and reconstruction converts
the processed discrete signals back into continuous-time analog form.

2.1 Sampling
If xa(t) is an analog signal, its sampled version is given by x(n) = xa(nTs), where Ts is the
sampling interval and Fs = 1/Ts is the sampling frequency. According to the Sampling
Theorem, the sampling frequency must be at least twice the maximum frequency of the
signal to avoid aliasing: Fs ≥ 2B. The minimum required rate 2B is known as the Nyquist
rate.

2.2 Quantization
Quantization converts each sample to the nearest quantization level. The quantization
error is eq(n) = x(n) – xq(n). The step size is Δ = (xmax – xmin)/(L – 1), where L = 2^b is
the number of levels for a b-bit quantizer. The error is limited to the range –Δ/2 to Δ/2.
Increasing the bit resolution reduces the quantization error.

2.3 Reconstruction
Reconstruction is the process of converting discrete-time samples back into a continuous-
time analog signal using interpolation. The ideal reconstruction method employs sinc
interpolation, where the reconstructed signal 𝑥𝑎 (𝑡)is given by:
xa(t) = Σ x(n) * sinc((t – nTs)/Ts).

In practice, ideal reconstruction is approximated by:


• Zero-Order Hold (ZOH): Each sample value is held constant until the next sample.
• First-Order Hold (FOH): Adjacent samples are joined with straight lines for smoother
reconstruction.

2.4 Frequency Domain Representation


The relationship between the continuous and discrete frequency spectra is given by X(f)
= Fs Σ Xa(f – kFs). This shows that the discrete spectrum consists of repeated versions of
the analog spectrum spaced by Fs. If Fs is too small, the spectra overlap, resulting in
aliasing.

3. Pre-Lab Homework
Given: xa(t) = cos(2000πt) + 3cos(5000πt) + 5cos(9000πt). Each sample is quantized into
4096 voltage levels, and the link operates at 24,000 bits/sec.

i. Nyquist Rate:

The frequencies present in the signal are:

F1 = 1000 Hz, f2 = 2500 Hz, f3 = 4500 Hz

Hence, the Nyquist rate is determined as:

FN = 2 × fmax = 2 × 4500 = 9000 Hz

ii. Sampling Rate, Sampling Interval, and Folding Frequency:

Given data:

Bit rate, bR = 24,000 bits/sec

Quantization levels, L = 4096

Number of bits per sample:

B = log2(L) = log2(4096) = 12 bits

Therefore, Sampling Frequency (FS) is:

FS = bR / b = 24,000 / 12 = 2000 Hz

Sampling interval:
TS = 1 / FS = 1 / 2000 = 0.0005 sec

Folding frequency:

Ffold = FS / 2 = 2000 / 2 = 1000 Hz

iii. Discrete-Time Signal:

After sampling, the discrete-time signal becomes:

X[n] = cos(2π × 1000/2000 × n) + 3cos(2π × 2500/2000 × n) + 5cos(2π × 4500/2000 ×


n)

= cos(πn) + 3cos(5πn/2) + 5cos(9πn/2)

= cos(πn) + 3cos(πn/2) + 5cos(πn/2)

iv. Signal Periodicity:

From the above, the normalized discrete frequencies are:

F1 = ½ Hz, f2 = 5/4 Hz, f3 = 9/4 Hz

As these are rational numbers, the discrete-time signal is periodic.

The fundamental period is the LCM of denominators (2, 4, 4), giving:

Fundamental period, N0 = 4

v. Reconstructed Analog Signal using Ideal Interpolation:

The continuous-time reconstructed signal is obtained as:

Ya(t) = cos(π × 2000t) + 3cos(π/2 × 2000t) + 5cos(π/2 × 2000t)

= cos(2000πt) + 3cos(1000πt) + 5cos(1000πt)

4. Apparatus
• MATLAB Software

5. Experimental Procedure
1. Define the analog signal xa(t) = e^(-10t).
2. Choose two sampling frequencies, Fs1 = 10 Hz and Fs2 = 50 Hz.
3. Sample the signal at both rates and plot discrete-time versions.
4. Compute and plot the spectra using FFT.
5. Quantize the sampled signal into 5 equal levels.
6. Reconstruct the signal using ZOH and FOH interpolation.
7. Compare the reconstructed and original analog signals.

MATLAB Commands Used:

%% DSP Lab Experiment 2

% Study of Sampling, Quantization, and Reconstruction of Analog Signals

clc; clear all; close all;

%% --------- Sampling of xa(t) at Fs = 50 samples/sec ----------

tmin = -1; % Start time (s)

tmax = 1; % End time (s)

t = tmin:0.001:tmax; % Continuous-time axis (for analog plot)

xa = exp(-10*abs(t)); % Analog signal xa(t) = e^(-10|t|)

Fs = 50; % Sampling frequency (samples/sec)

Ts = 1/Fs; % Sampling period (sec)

n = tmin/Ts:tmax/Ts; % Discrete sample indices

x = exp(-10*abs(n*Ts)); % Discrete-time samples x[n] = xa(nTs)

% ---- Plot Analog and Discrete-Time Signals ----

figure(1);

subplot(2,1,1);

plot(t, xa, 'LineWidth', 1.5);

title('Analog Signal x_a(t)');

xlabel('Time (sec)'); ylabel('Amplitude');

subplot(2,1,2);

stem(n, x, 'filled');

title('Discrete-Time Signal x(n)');

xlabel('Sample Index n'); ylabel('Amplitude');


%% --------- Frequency Domain Analysis ----------

F = -100:0.1:100; % Frequency grid (Hz)

W = 2*pi*F; % Continuous angular frequency

f = F/Fs; % Normalized frequency (cycles/sample)

w = 2*pi*f; % Normalized angular frequency (rad/sample)

XaF = 2.*(10./(10^2 + W.^2)); % Continuous-time Fourier Transform

XF = x * exp(-1j*n'*w); % Discrete-time Fourier Transform

% ---- Plot Spectra ----

figure(2);

subplot(3,1,1);

plot(F, abs(XaF), 'LineWidth', 1.3);

title('Spectra of Signals - Continuous Time');

xlabel('Frequency (Hz)'); ylabel('|Xa(F)|');

subplot(3,1,2);

plot(F, abs(XF), 'LineWidth', 1.3);

xlabel('Frequency (Hz)'); ylabel('|X(F/Fs)|');

subplot(3,1,3);

plot(f, abs(XF), 'LineWidth', 1.3);

xlabel('Normalized Frequency (cycles/sample)'); ylabel('|X(f)|');

% ---- Display Spectra in Fundamental Range ----

figure(3);

subplot(2,1,1);

plot(F, abs(XF), 'LineWidth', 1.3);

title('Spectra in Fundamental Range');

xlabel('Frequency (Hz)'); ylabel('|X(F/Fs)|');


axis([-Fs/2 Fs/2 0 inf]);

subplot(2,1,2);

plot(f, abs(XF), 'LineWidth', 1.3);

xlabel('Normalized Frequency (cycles/sample)'); ylabel('|X(f)|');

axis([-0.5 0.5 0 inf]);

%% --------- Reconstruction Using Sinc Interpolation ----------

t = tmin:0.001:tmax;

figure(4); clf;

subplot(2,1,1); hold on;

stem(n*Ts, x, 'r', 'filled');

for i = 1:length(x)

xsinc(i,:) = x(i) * sinc(Fs*(t - (i + min(n) - 1)*Ts)); % Shifted sinc

plot(t, xsinc(i,:), 'b:'); % Plot each sinc component

end

title('Signal Reconstruction using Sinc Interpolation');

xlabel('Time (s)'); ylabel('x(n) * sinc(Fs(t - nTs))');

hold off;

xar = sum(xsinc); % Reconstructed signal

subplot(2,1,2);

plot(t, xar, 'b', 'LineWidth', 1.3); hold on;

plot(t, xa, 'r--', 'LineWidth', 1.2);

legend('Reconstructed Signal', 'Original Signal');

xlabel('Time (s)'); ylabel('Amplitude');

title('Reconstructed vs Original Signal');

%% --------- Quantization Using Built-in Function “quantiz” ----------


fs = 10000; % Sampling frequency for quantization

t = 0:1/fs:0.1; % Time vector

f = 10; % Frequency of the sine signal

sig = 2*sin(2*pi*f*t); % Original sine wave signal

partition = [-1.5, -0.5, 0.5, 1.5]; % Define quantization thresholds

codebook = -2:2; % Quantization levels

[index, quants] = quantiz(sig, partition, codebook); % Quantize signal

figure(5);

plot(t, sig, 'x', 'LineWidth', 1.2); hold on;

plot(t, quants, '.', 'MarkerSize', 10);

legend('Original Signal', 'Quantized Signal');

xlabel('Time (s)'); ylabel('Amplitude');

title('Quantization using quantiz Function');

%% --------- Manual Quantization Using Formula ----------

fs = 40000; % Sampling frequency

f = 50; % Signal frequency

t = 0:1/fs:1/f; % Time vector

A = 2;

x = A*sin(2*pi*f*t); % Original signal

n = 3; % Quantization bits

L = 2^n; % Number of quantization levels

delta = (max(x) - min(x)) / (L - 1); % Step size

xq = min(x) + round((x - min(x))/delta) .* delta; % Quantized signal

figure(6);

plot(t, x, 'r-.', 'LineWidth', 1.2); hold on;


plot(t, xq, 'k-.', 'LineWidth', 1.2);

xlabel('Time (s)'); ylabel('Amplitude');

title('Manual Quantization of Signal');

legend('Original Signal', 'Quantized Signal');

grid on;
6. Lab Report Questions and Answers
Q1. What MATLAB function is used to plot ZOH interpolation? → The function
'stairs()'.

Q2. What MATLAB function is used to plot FOH interpolation? → The function
'interp1(x,y,"linear")'.

Q3. Why must the sampling rate be at least twice the bandwidth? → To satisfy the
Nyquist criterion and prevent aliasing.

Q4. Why is Fs = 50 samples/sec better than Fs = 10 samples/sec? → Higher sampling


rates produce more accurate results and prevent aliasing.

Q5. For xa(t) = sin(20πt) sampled at Ts = 0.01–0.1 sec:


• As Ts increases, sampling rate decreases and reconstruction becomes less accurate.
• When Ts ≥ 0.05, aliasing occurs.
• Smaller Ts values yield smoother reconstructed signals.

%% DSP Lab 2 : Problems for Lab Report

clc; clear; close all;

%% -------- Problem 1: Staircase (ZOH) Interpolation --------

t = 0:0.001:1; xa = sin(4*pi*t); % Example analog signal

Ts = 0.05; Fs = 1/Ts; % Sampling period & frequency


n = 0:Ts:1; x = sin(4*pi*n); % Sampled signal

figure;

stairs(n, x, 'r','LineWidth',1.2); hold on; % ZOH interpolation

plot(t, xa, 'b--','LineWidth',1.2);

title('Problem 1: ZOH (Staircase) Interpolation');

xlabel('Time (s)'); ylabel('Amplitude');

legend('ZOH Output','Original Signal'); grid on;

%% -------- Problem 2: Linear (FOH) Interpolation --------

tq = 0:0.001:1; % Fine time vector for smooth plotting

x_lin = interp1(n, x, tq, 'linear'); % Linear interpolation

figure;

plot(tq, x_lin, 'r','LineWidth',1.2); hold on;

plot(t, xa, 'b--','LineWidth',1.2);

title('Problem 2: Linear (FOH) Interpolation');

xlabel('Time (s)'); ylabel('Amplitude');

legend('Linear Output','Original Signal'); grid on;

%% -------- Problem 3: Sampling Theorem Demonstration --------

B = 10; % Bandwidth = 10 Hz

Fs_good = 2*B; % Nyquist rate (no aliasing)

Fs_bad = 0.8*Fs_good; % Below Nyquist (aliasing)

t = 0:0.001:1;

xa = sin(2*pi*B*t); % 10 Hz sine

% Sampling at good Fs

n1 = 0:1/Fs_good:1; x1 = sin(2*pi*B*n1);

% Sampling below Nyquist


n2 = 0:1/Fs_bad:1; x2 = sin(2*pi*B*n2);

figure;

subplot(2,1,1);

stem(n1, x1,'r','filled'); title('Fs = 20 Hz (No Aliasing)'); grid on;

subplot(2,1,2);

stem(n2, x2,'b','filled'); title('Fs = 16 Hz (<2B) → Aliasing'); grid on;

%% -------- Problem 4: Aliasing Example (Fs=10 vs 50 Hz) --------

t = 0:0.001:1;

xa = sin(20*pi*t); % 10 Hz sine

Fs_list = [10 50]; % Two sampling rates

figure;

for i = 1:length(Fs_list)

Fs = Fs_list(i); Ts = 1/Fs;

n = 0:Ts:1; x = sin(20*pi*n);

t_rec = 0:0.001:1; x_rec = zeros(size(t_rec));

for k = 1:length(n)

x_rec = x_rec + x(k)*sinc(Fs*(t_rec - n(k))); % Reconstruction

end

subplot(2,1,i);

plot(t, xa, 'b', t_rec, x_rec, 'r--','LineWidth',1.2);

title(['Fs = ' num2str(Fs) ' Hz']); ylabel('Amplitude'); grid on;

end

xlabel('Time (s)');

%% -------- Problem 5: Sampling sin(20πt) with Different Ts --------

t = 0:0.001:1; xa = sin(20*pi*t); % 10 Hz analog signal


Ts_values = [0.01 0.03 0.05 0.07 0.1]; % Different Ts

figure;

for i = 1:length(Ts_values)

Ts = Ts_values(i); Fs = 1/Ts;

n = 0:Ts:1; x = sin(20*pi*n);

t_rec = 0:0.001:1; x_rec = zeros(size(t_rec));

% Reconstruction using sinc

for k = 1:length(n)

x_rec = x_rec + x(k)*sinc(Fs*(t_rec - n(k)));

end

subplot(length(Ts_values),1,i);

plot(t, xa, 'b', t_rec, x_rec, 'r--');

title(['T_s = ' num2str(Ts) ' s, F_s = ' num2str(Fs) ' Hz']);

ylabel('x(t)'); grid on;

end

xlabel('Time (s)');
7. Conclusion

This experiment illustrated the key concepts of sampling, quantization, and


reconstruction of analog signals. It demonstrated that undersampling results in aliasing
and information loss, while higher sampling rates enhance the accuracy of the
reconstructed signal. Zero-Order Hold (ZOH) produces a staircase-like reconstruction,
whereas First-Order Hold (FOH) generates a smoother waveform. MATLAB
simulations effectively visualized the differences between ideal and practical
reconstruction, providing a clearer understanding of ADC (Analog-to-Digital
Conversion) and DAC (Digital-to-Analog Conversion) processes.
8. References
[1] J. G. Proakis and D. G. Manolakis, Digital Signal Processing: Principles, Algorithms,
and Applications, 3rd ed. New Delhi, India: Prentice Hall of India, 2003.

[2] MathWorks, “Getting Started with MATLAB.” [Online]. Available:


[Link]

[3] A. V. Oppenheim and A. S. Willsky, Signals and Systems, 2nd ed. New Jersey, USA:
Prentice Hall, 1997.

You might also like