PCM in Digital Communications
PCM in Digital Communications
Department of ECE
Digital Communications Lab (22EC2208L) AY2023-23
In modern communication, real world analog signals are converted into digital signals using
sampling and quantization operations (collectively called analog-to-digital conversion, or ADC).
Sampling is the process of converting a continuous time signal into a discrete time signal by
measuring the signal's amplitude at regular intervals of time. These discrete signals are
processed by digital signal processors, and the processed signals are converted into analog
signals back using a reconstruction operation (called digital-to-analog conversion or DAC).
Objectives:
(a) Understand the basic theory of Pulse Code Modulation and Demodulation and their
elements.
(b) Development of Matlab codes to generate and display the results of Pulse Code
Modulation and Demodulation systems.
(c) Evaluate the performance of Pulse Code Modulation and Demodulation systems.
Learning Outcomes:
After the successful completion of this experiment, students will be able to:
1. Understand the PCM modulation and demodulation process.
2. Develop MATLAB code for PCM modulation and demodulation process.
3. Computing the quantization error
4. Observing the effect of reconstructed signal quality.
Brief theory:
1
Alec Reeves in 1937. It is the standard form for digital audio in computers and
various Blu-ray, Compact Disc and DVD formats, as well as other uses such as
digital telephone systems. A PCM stream is a digital representation of an analog
signal, in which the magnitude of the analogue signal is sampled regularly at
uniform intervals, with each sample being quantized to the nearest value within a
range of digital steps.
Fig1 Illustrate the PCM encoder that consist off sampling, quantization and
Sampling: The first step in the PCM encoding process is sampling the analog signals, sample every Ts
secs, where Ts is referred to as the sampling interval that satisfies the Nyquist theorem. Usually a flat-
top sampling process is used.
Quantization: Sampling results in a series of pulses of varying amplitude values ranging between two
limits: and . The amplitude values are infinite between the two limits. It needs to map the
infinite amplitude values onto a finite set of known values. This is achieved by dividing the distance
The midpoint of each zone is assigned a value from 0 to L-1 (resulting in L values). Each sample falling
in a zone is then approximated to the value of the midpoint. The higher the value of L, the less distorted a
signal is recovered.
Binary encoding: The quantized sequence is encoded into binary stream with appropriate
number of bits.
2
Fig1: Illustration of sampling, quantization and reconstruction process.
PCM Decoder: To recover an analog signal from a digitized signal we follow the following
steps and illustrated in the following Fig2.:
Worked Example:
3
Consider the following data for PCM modulation and demodulation:
(a) A sinusoidal signal with unit amplitude and frequency of 2 Hz. Consider sampling rate
20 Samp/sec. Add a DC voltage of say 1.1 V to this signal.
(b) A pulse train with pulse duration of 10 msec and repletion frequency of 40.
Development of Matlab codes to generate:
(i) A message signal with given parameters and its plot.
(ii) A rectangular pulse train and its plot.
(iii) Sampled signal from the above message signal and pulse train and its plot. Compare
the sampled signal with the original message signal and its plot.
(iv) Quantized signal and display for a given number of bits. Compare with the sampled,
original signals and its plot.
(v) Encoded signal and its plot.
(vi) Decoded signal and its plot.
(vii) Recovered signal and its plot.
(viii) Evaluate the effect of various sampling rates and number of bits.
Solution: The Matlab code for the given problem is illustrated below:
% ============
% PCM ENCODING
% ============
clear; close all; clc;
% Creating sampling to define time index
fss = 1.e4; Tss = 1/fss;
4
figure(1);
plot(t,m,'b','LineWidth',2);
title('Original Signal');
xlabel('Time -->'); ylabel('Amplitude');
axis([0 2 0 2.25]);grid on;
% =================
% Pulse Train Signal
% =================
% Generation of pulse train
D = 40;
d = Ts/D:Ts:2+Ts/D;
p = pulstran(t,d,'rectpuls',1/(fs*D));
figure(2);
plot(t,p,'k','LineWidth',2);
title('Pulsetrain Signal');
xlabel('Time -->'); ylabel('Amplitude');
axis([0 2 0 1.15]);grid on;
5
% =================
% Sampled signal
% =================
ms = m.*p;
figure(3);
plot(t,ms,'m','LineWidth',2);
hold on;plot(t,m,'b--','LineWidth',2);
hold off;
title('Sampled Signal');
xlabel('Time -->'); ylabel('Amplitude');
axis([0 2 0 2.15]);grid on;
6
figure(4);
subplot(3,1,1);plot(t,m,'b','LineWidth',2);
title('Original Signal');
xlabel('Time -->'); ylabel('Amplitude');
axis([0 2 0 2.25]);grid on;
subplot(3,1,2);plot(t,p,'k','LineWidth',2);
title('Pulsetrain Signal');
xlabel('Time -->'); ylabel('Amplitude');
axis([0 2 0 1.15]);grid on;
subplot(3,1,3);plot(t,ms,'m','LineWidth',2);
hold on;plot(t,m,'b--','LineWidth',2);
hold off;
title('Sampled Signal');
xlabel('Time -->'); ylabel('Amplitude');
axis([0 2 0 2.15]);grid on;
% =================
% Quantized Msg
% =================
qm = quant(ms,2/16);
figure(5);
stem(t,qm,'m','filled','LineWidth',2);
hold on;plot(t,ms,'b','LineWidth',2);
% hold on;plot(t,m,'k--','LineWidth',2);
hold off;
title('Sampled Signal');
xlabel('Time -->'); ylabel('Amplitude');
7
axis([0 2 0 2.15]);grid on;
legend('Quantized','Sampled');
% =================
% ENCODING MSG
% =================
em = 8*(qm);
% x = zeros(size(qm));
j = 1;
for i=1:length(em)
if ((((i>1)&&(em(i)~=em(i-1)))||(i==1))&&(em(i)~=0))
x(j) = em(i)-1;
j=j+1;
end
end
z = dec2bin(x,5);
z = z';
z = z(:);
z = str2num(z);
s = 2*(z')-1;
Tb = 2/length(s);
fb = 0.5/Tb;
BL = Tb/Tss;
y = ones(BL,1);
bit = 5*y*s;
8
bit = bit(:);
bit = bit'; % Polar NRZ bit stream
figure()
plot(t,bit,'b','LineWidth',2)
xlabel('t -->');
ylabel('Amplitude');
title('POLAR NRZ ENCODED');
grid;
axis([0 0.5 -5.25 5.25]);
% =============
% PCM Demodulation
% =============
% PCM Decoding
rb = bit(ceil(Tb/(Tss)):(Tb/Tss):length(bit));
rb = (rb+5)/10;
l = length(rb);
for i = 1:l/5
q = rb((5*i)-4:5*i);
q = num2str(q);
x1(i) = bin2dec(q);
9
e(i) = x1(i)+1;
end
e = e/8;
y1 = ones(1,ceil((Ts/D)/Tss));
y2 = zeros(1,(Ts/Tss)-length(y1));
y3 = [y1 y2];
y3 = y3';
% =============
% Recovery of samples signals from encoded data
% =============
figure()
plot(t,ms1,'b','LineWidth',2);
title('Recovered Sampled Msg')
grid;
xlabel('t -->');
ylabel('Amplitude');
axis([0 2 0 2.25]);
% =============
% Recovery of Message signal from sampled signal
% =============
% Filtering Sampled Signal
[n,w] = buttord(f/fss,(f+1)/fss,.6,4);
[a,b] = butter(n,w,'low');
rm = filter(a,b,ms1);
rm = rm*50; % Recieved Orignal Signal
figure();
10
plot(t,rm,'m','LineWidth',2);
hold on; plot(t,m,'k--','LineWidth',2); hold off;
title('Recovered Analog Msg')
grid;
xlabel('t -->');
ylabel('Amplitude');
axis([0 2 0 2.25]);
Assignment Tasks:
Task1: (a) Comment on the reconstructed signal.
(b) Repeat the above problem without dc 1.1 V.
(b) Repeat the above problem with uniform quantizing levels of (i) 4 (ii) 8 (iii)
16.
(c) Repeat the above problem with different sampling rates.
Viva Questions:
1. What will happen when the sampling rate is greater than Nyquist rate?
2. Differentiate between sampling and quantizing processes.
3. Which type of sampling (ideal, natural or flat top) and why?
11
4. Is the quantization error is positive or negative?
5. Mention some applications of PCM.
12