GEC Wayanad ECL332 Communication Lab
Experiment 3
Performance of Waveform Coding Using PCM
Aim
1. Generate a sinusoidal waveform with a DC offset such that the signal takes only
positive amplitude values.
2. Sample and quantize the signal using a uniform quantizer with a number of rep-
resentation levels L. Vary the value of L. Represent each quantized value using a
decimal-to-binary encoder.
3. Compute the signal-to-noise ratio (SNR) in decibels (dB).
4. Plot the SNR versus the number of bits per symbol and observe that the SNR
increases linearly.
THEORY
Pulse Code Modulation (PCM) is a waveform coding technique in which an analog signal
is represented by a sequence of binary codes. In PCM, the continuous-amplitude message
signal is first sampled, then quantized into a finite number of discrete levels, and finally
encoded into binary form for transmission.
Generation of Sinusoidal Signal with DC Offset
The message signal used in this experiment is a sinusoidal waveform with a DC offset to
ensure that the signal remains strictly positive. The signal is defined as
x(t) = sin(2πfm t) + D (1)
where fm is the message frequency.
The DC offset shifts the signal upward, preventing negative amplitude values and
simplifying quantization.
Sampling
The continuous-time signal is sampled at a sampling frequency fs , producing a discrete-
time signal
1
GEC Wayanad ECL332 Communication Lab
n
x[n] = sin 2πfm +D (2)
fs
According to the Nyquist sampling theorem, the sampling frequency must satisfy
fs ≥ 2fm (3)
In this experiment, the sampling frequency is chosen much higher than the Nyquist
rate to avoid aliasing.
Uniform Quantization
The sampled signal is quantized using a uniform quantizer with L quantization levels,
where
L = 2b (4)
and b is the number of bits per symbol.
The quantization step size is given by
xmax − xmin
∆= (5)
L
Each sample is approximated to the nearest quantization level, introducing an error
known as quantization noise.
Encoding
Each quantized sample is represented using a binary code word of length b = log2 L.
This process converts the amplitude information into a digital bit stream suitable for
transmission.
Quantization Error
The quantization error is defined as the difference between the sampled signal and the
quantized signal:
e[n] = x[n] − xq [n] (6)
This error behaves as noise and affects the quality of the reconstructed signal.
Signal-to-Noise Ratio (SNR)
The signal power Ps and noise power Pn are computed as
2
GEC Wayanad ECL332 Communication Lab
N −1
1 X 2
Ps = x [n] (7)
N n=0
N −1
1 X 2
Pn = e [n] (8)
N n=0
The Signal-to-Noise Ratio (SNR) in decibels is given by
Ps
SNRdB = 10 log10 (9)
Pn
Theoretical SNR of PCM
For a uniform quantizer and a sinusoidal input, the theoretical SNR of PCM is approxi-
mated by
SNRdB = 6.02 b + 1.76 (10)
This equation shows that increasing the number of bits per symbol improves the SNR
linearly.
SNR versus Number of Bits
By varying the number of bits per symbol b (and hence L), the SNR is computed and
plotted. The plot demonstrates that the SNR increases linearly with the number of bits,
validating the theoretical prediction.
Algorithm
1. Generate a sinusoidal signal with frequency fm and add a DC offset of 2.
2. Sample the signal at a sampling frequency fs satisfying the Nyquist criterion.
3. Determine the minimum and maximum values of the sampled signal.
4. Select the number of bits per symbol b and compute the number of quantization
levels L = 2b .
5. Design a uniform quantizer using L representation levels.
6. Quantize the sampled signal and obtain the quantized output.
7. Encode the quantized values into binary form.
3
GEC Wayanad ECL332 Communication Lab
8. Compute the quantization error by subtracting the quantized signal from the sam-
pled signal.
9. Calculate the practical SNR using signal and noise power.
10. Compute the theoretical SNR using the PCM SNR formula.
11. Repeat the procedure for different values of b.
12. Plot the SNR versus number of bits per symbol and observe the linear relationship.
MATLAB CODE
% Performance of Waveform Coding Using PCM with Theoretical and Practical SNR
clc;
clear;
close all;
% Generate a sinusoidal waveform with DC offset
time = 0:0.0005:0.05; % Continuous time for plotting
freq_msg = 100;
dc_offset = 2;
signal = sin(2*pi*freq_msg*time) + dc_offset;
% Sampling the signal
freq_sample = 15 * freq_msg;
samp_time = 0:1/freq_sample:0.05;
samp_signal = sin(2*pi*freq_msg*samp_time) + dc_offset;
% Plot Original & Sampled Signal
figure;
plot(time, signal, ’b’, ’LineWidth’, 1.5); hold on;
plot(samp_time, samp_signal, ’rx’, ’MarkerSize’, 6);
xlabel(’Time (s)’);
ylabel(’Amplitude’);
title(’Original and Sampled Signal’);
legend(’Original Signal’, ’Sampled Signal’);
grid on;
4
GEC Wayanad ECL332 Communication Lab
% Uniform Quantizer with varying L
bit_range = 2:8; % Number of bits per symbol
SNR_values = zeros(1, length(bit_range));
SNR_theoretical = zeros(1, length(bit_range));
figure;
for b = bit_range
L = 2^b; % Number of quantization levels
smin = min(samp_signal);
smax = max(samp_signal);
% Define Quantization Levels and Codebook
Quant_levl = linspace(smin, smax, L-1);
codebook = linspace(smin, smax, L);
% Perform Quantization
[index, quants] = quantiz(samp_signal, Quant_levl, codebook);
% Compute Noise
noise = quants - samp_signal;
% Compute Practical SNR
SNR_values(b - 1) = snr(samp_signal, noise);
% Compute Theoretical SNR for PCM
SNR_theoretical(b - 1) = 6.02 * b + 1.76; % Theoretical formula for SNR in dB
% Plot Quantized Signal for each bit depth
subplot(3, 3, b - 1);
plot(samp_time, samp_signal, ’rx’, ’MarkerSize’, 6); hold on;
stairs(samp_time, quants, ’b’, ’LineWidth’, 1.5);
xlabel(’Time (s)’);
ylabel(’Amplitude’);
title([’Quantized Signal (’, num2str(b), ’ bits)’]);
legend(’Sampled Signal’, ’Quantized Signal’);
grid on;
end
% Plot Noise Signal
5
GEC Wayanad ECL332 Communication Lab
figure;
plot(samp_time, noise, ’m.-’, ’LineWidth’, 1.2);
xlabel(’Time (s)’);
ylabel(’Noise Amplitude’);
title(’Noise Signal’);
grid on;
% Plot SNR vs Number of Bits per Symbol
figure;
plot(bit_range, SNR_values, ’o-’, ’LineWidth’, 2, ’DisplayName’, ’Practical SNR’);
hold on;
plot(bit_range, SNR_theoretical, ’s--’, ’LineWidth’, 2, ’DisplayName’, ’Theoretical
xlabel(’Number of Bits per Symbol’);
ylabel(’SNR (dB)’);
title(’SNR vs Number of Bits per Symbol in PCM’);
legend(’show’);
grid on;
Result
A sinusoidal waveform with an appropriate DC offset was successfully generated such that
the signal contained only positive amplitude values. The generated signal was sampled
at a frequency satisfying the Nyquist criterion, ensuring faithful representation of the
original waveform.
The sampled signal was uniformly quantized using different numbers of representation
levels L. Each quantized sample was encoded using a decimal-to-binary encoder. It was
observed that increasing L resulted in finer amplitude resolution and reduced quantization
distortion.
The quantization error was computed for each value of L, and the corresponding
Signal-to-Noise Ratio (SNR) was calculated in decibels. The SNR was found to increase
with the number of bits per symbol.
A plot of SNR versus number of bits per symbol was obtained, which clearly showed
a linear increase in SNR with increasing bit depth. Approximately a 6 dB improvement
in SNR was observed for every additional bit, validating the theoretical performance of
Pulse Code Modulation (PCM).
Thus, the experiment confirms that increasing the number of quantization levels im-
proves signal quality and demonstrates the effectiveness of PCM in waveform coding.
6
GEC Wayanad ECL332 Communication Lab
Output Observations
Figure 1: Original and sampled signal
Figure 2: Quantized signals for different values of bit resolution
7
GEC Wayanad ECL332 Communication Lab
Figure 3: Noise signal
Figure 4: Error Performance of PCM