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

PCM Digital Communication Lab Guide

The document demonstrates pulse code modulation (PCM) using MATLAB. It shows the encoding and decoding of an analog signal using an 8-bit PCM system with 8 samples per period. In the encoding, the analog signal is sampled, quantized to 8-bit levels, and converted to a binary code. The maximum quantization error between the original and quantized signals is determined. In the decoding, the binary code is converted back to decimal indices, used to recover the quantized values, and thus reconstruct the original analog signal. The original and recovered signals are plotted for comparison.

Uploaded by

photoid user1
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)
24 views10 pages

PCM Digital Communication Lab Guide

The document demonstrates pulse code modulation (PCM) using MATLAB. It shows the encoding and decoding of an analog signal using an 8-bit PCM system with 8 samples per period. In the encoding, the analog signal is sampled, quantized to 8-bit levels, and converted to a binary code. The maximum quantization error between the original and quantized signals is determined. In the decoding, the binary code is converted back to decimal indices, used to recover the quantized values, and thus reconstruct the original analog signal. The original and recovered signals are plotted for comparison.

Uploaded by

photoid user1
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

DEPARTMENT OF COMPUTER &

SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST,
RAWALPINDI

EC-431 Digital Communication

LabNumber 07

NIMRA AKMAL
CE 41 B
288608
Lab # 07: Demonstration of Pulse Code Modulation

Objective:
To demonstrate the principle of PCM (pulse code modulation) and implementation of a PCM
based digital communication system.

Tasks:

1. Plot a difference delta of the sampled signal and quantized signal in Fig. 3. Compare
them using different line specs on same graph. How much is the maximum quantization
error?
clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system : ');
n1=input('Enter number of samples in a period : ');
L=2^n;

% % Signal Generation + Sampling Operation


x=0:2*pi/n1:4*pi; %4pi to plot two cycles for visibility and n1 number
of samples per period have to be selected

Vmax=8;
s=Vmax.*sin(x);%Vmax.*sin(x)
subplot(4,1,1);
plot(s);
title('Source Analogue Signal');
ylabel('Amplitude');
xlabel('Time');
subplot(4,1,2);
stem(s);grid on; title('Sampled Signal'); ylabel('Amplitude');
xlabel('Time');

%Quantizer for our PCM encoder case


Vmin=-Vmax;
delta=(Vmax-Vmin)/L; %step size delta
part=Vmin:delta:Vmax; % Levels are
between Vmin and Vmax with difference of delta- Without quantization
code=Vmin-(delta/2):delta:Vmax+(delta/2); % Contains
Quantized values
[ind,q]=quantiz(s,part,code);
% Now, ind will contain index number and q contain quantized values
l1=length(ind);
l2=length(q);

for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started
from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==Vmin-(delta/2)) % To make quantized value in between the
levels
q(i)=Vmin+(delta/2);
end
end
subplot(4,1,3);
stem(q,'r*');grid on; % Display the Quantized values
title('Quantized Signal');
ylabel('Amplitude');
xlabel('Time');

% subplot(4,1,4);
% stem(s);
% hold on
% stem(q,'r*');

subplot(4,1,4);
diff= s-q;
stem(diff);
title('Difference of s and q');
mx=max(diff);
2. Run your whole PCM encoder code (whose output in Fig; 3 and 4) for a 8-bit PCM i.e.,
n=8. Use a sampling period of 8 also i.e., n1 =8. Plot Fig. 3 and 4 again as above. Also
give the values of ind and code matrices as mentioned in the PCM encoding section
above.
clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system : ');
n1=input('Enter number of samples in a period : ');
L=2^n;

% % Signal Generation + Sampling Operation


x=0:2*pi/n1:4*pi; %4pi to plot two cycles for visibility and n1 number of
samples per period have to be selected

Vmax=8;
s=Vmax.*sin(x);%Vmax.*sin(x)
subplot(4,1,1);
plot(s);
title('Source Analogue Signal');
ylabel('Amplitude');
xlabel('Time');
subplot(4,1,2);
stem(s);grid on; title('Sampled Signal'); ylabel('Amplitude');
xlabel('Time');

%Quantizer for our PCM encoder case


Vmin=-Vmax;
delta=(Vmax-Vmin)/L; %step size delta
part=Vmin:delta:Vmax; % Levels are
between Vmin and Vmax with difference of delta- Without quantization
code=Vmin-(delta/2):delta:Vmax+(delta/2); % Contains
Quantized values
[ind,q]=quantiz(s,part,code);
% Now, ind will contain index number and q contain quantized values
l1=length(ind);
l2=length(q);

for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started
from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==Vmin-(delta/2)) % To make quantized value in between the levels
q(i)=Vmin+(delta/2);
end
end
subplot(4,1,3);
stem(q,'r*');grid on; % Display the Quantized values
title('Quantized Signal');
ylabel('Amplitude');
xlabel('Time');
% subplot(4,1,4);
% stem(s);
% hold on
% stem(q,'r*');

subplot(4,1,4);
diff= s-q;
stem(diff);
title('Difference of s and q');

figure
code=de2bi(ind,'left-msb');
k=1;
for i=1:l1
for j=1:n
coded(k)=code(i,j);
% convert code matrix to a coded row vector
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(2,1,1); grid on;
stem(coded);
% Display the encoded signal
[a b]= size(code);
axis([0 a*b -1 2]); title('Encoded Signal');
ylabel('Amplitude');
xlabel('Time Index');

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


stairs(coded);
% Display the encoded signal
[a b]= size(code);
axis([0 a*b -1 2]);
%title('Encoded Signal');
ylabel('Amplitude');
xlabel('Time Index');
3. Demodulation of PCM signal
Demodulate the PCM encoded signal above to recover the original analogue signal. Plot
the two on same graph with different color and line specs to compare results.

Hint: Use reshape to convert the coded vector above and use bi2dec to convert the binary
indices back to decimal. Then get back the quantized value using,
q =delta*index + Vmin + (delta/2);
clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system : ');
n1=input('Enter number of samples in a period : ');
L=2^n;

% % Signal Generation + Sampling Operation


x=0:2*pi/n1:4*pi; %4pi to plot two cycles for visibility and n1 number
of samples per period have to be selected

Vmax=8;
s=Vmax.*sin(x);%Vmax.*sin(x)
subplot(4,1,1);
plot(s);
title('Source Analogue Signal');
ylabel('Amplitude');
xlabel('Time');
subplot(4,1,2);
stem(s);grid on; title('Sampled Signal'); ylabel('Amplitude');
xlabel('Time');

%Quantizer for our PCM encoder case


Vmin=-Vmax;
delta=(Vmax-Vmin)/L; %step size delta
part=Vmin:delta:Vmax; % Levels are
between Vmin and Vmax with difference of delta- Without quantization
code=Vmin-(delta/2):delta:Vmax+(delta/2); % Contains
Quantized values
[ind,q]=quantiz(s,part,code);
% Now, ind will contain index number and q contain quantized values
l1=length(ind);
l2=length(q);

for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started
from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==Vmin-(delta/2)) % To make quantized value in between the
levels
q(i)=Vmin+(delta/2);
end
end
subplot(4,1,3);
stem(q,'r*');grid on; % Display the Quantized values
title('Quantized Signal');
ylabel('Amplitude');
xlabel('Time');

% subplot(4,1,4);
% stem(s);
% hold on
% stem(q,'r*');

subplot(4,1,4);
diff= s-q;
stem(diff);
title('Difference of s and q');

figure
code=de2bi(ind,'left-msb');
k=1;
for i=1:l1
for j=1:n
coded(k)=code(i,j);
% convert code matrix to a coded row vector
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(2,1,1); grid on;
stem(coded);
% Display the encoded signal
[a b]= size(code);
axis([0 a*b -1 2]); title('Encoded Signal');
ylabel('Amplitude');
xlabel('Time Index');

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


stairs(coded);
% Display the encoded signal
[a b]= size(code);
axis([0 a*b -1 2]);
%title('Encoded Signal');
ylabel('Amplitude');
xlabel('Time Index');

% Demodulation of PCM encoded signal


decode = reshape(coded, n, length(coded)/n)';
index = bi2de(decode, 'left-msb')';
q = delta*index + Vmin + (delta/2);

% Plot the quantized values and recovered analog signal


figure
subplot(3,1,1)
stem(q, 'r*');
title('Recovered Signal')
ylabel('Amplitude')
xlabel('Time Index')

subplot(3,1,2)
plot(q, 'r*'); hold on
plot(s, 'b--')
title('Quantized Signal and Recovered Analog Signal')
ylabel('Amplitude')
xlabel('Time')
Ind:

Index

Common questions

Powered by AI

In the PCM encoding process, the `ind` matrix contains the indices of the quantized levels mapping the sampled analogue signal into discrete values using these indices. The `code` matrix stores the binary representation of these indices, providing the encoded signal in a format suitable for digital transmission. During decoding, the `code` matrix is reshaped and converted back into the `ind` matrix to retrieve the quantized levels. This procedure allows accurate reconstruction of the quantized signal through inverse operations, ensuring that transmission errors are minimized .

The PCM encoding process involves the following steps: Firstly, the analogue signal is sampled at a consistent rate to obtain discrete values. Next, these sampled values undergo quantization where they are rounded to the nearest discrete value defined by the quantization levels. This is where the 'step size' or delta plays a crucial role; it defines the distance between quantization levels and determines the quantization resolution. A smaller delta results in more quantization levels and less quantization error, thus providing a more accurate representation of the signal .

The demodulation process in PCM retrieves the original analogue signal by reversing the encoding steps. Initially, the binary-coded indices are reshaped and converted back to integer indices using binary-to-decimal conversion. These indices are then mapped back to their corresponding quantized amplitude levels using the formula q = delta*index + Vmin + (delta/2). Challenges during this process include ensuring synchronization between the encoded and decoded signals and accurately reconstructing the signal within the bounds of quantization error and potential noise contamination introduced during transmission .

Key components in a PCM-based digital communication system include a sampler, quantizer, encoder, digital transmission channel, decoder, and a reconstruction filter. The sampler samples the incoming analogue signal at a specified frequency, creating discrete time instances. The quantizer assigns each sample to a discrete value, introducing quantization levels. The encoder then converts these levels into a binary format suitable for digital transmission. After transmission over the digital channel, the decoder reconstructs the binary data back to quantized values. Finally, a reconstruction filter processes these values to generate a continuous analogue signal, achieving complete signal transmission .

The choice of bit depth (n) in PCM systems involves a trade-off between performance and resource utilization. A higher bit depth increases the number of quantization levels, improving signal fidelity by reducing quantization error. This yields a more accurate reconstruction of the analogue signal. However, higher bit depths also lead to increased data rates, requiring more bandwidth and storage, as each sample is represented by more bits. Conversely, lower bit depths reduce resource demands but increase quantization error, potentially leading to more noticeable inaccuracies in signal reproduction. Balancing these factors is crucial for optimizing system performance while considering resource constraints .

Quantization in Pulse Code Modulation introduces quantization error by mapping a continuous range of values to a finite set of levels, resulting in a difference between the actual and quantized values. This error is inherent in the quantization process, as each sampled signal value is approximated to the nearest value within the set levels. Strategies to minimize quantization error include increasing the number of quantization levels by utilizing a higher bit-depth system, which effectively decreases the step size (delta) between levels, thus providing a finer granularity and closer approximation to the original signal .

Pulse Code Modulation ensures that signals can be reconstructed after transmission through noisy channels by converting the continuous analogue signal into a series of discrete values represented in binary form. This digital representation is inherently more resistant to noise because digital systems can distinguish between discrete values even in the presence of interference, whereas analogue signals may suffer from significant distortion. Additionally, error detection and correction algorithms can be applied to the binary data to further enhance signal integrity, ensuring reliable reconstruction of the original signal despite channel noise .

The sampling frequency in PCM is crucial because it determines how often the analogue signal is sampled and directly affects the fidelity of signal reconstruction. According to the Nyquist-Shannon sampling theorem, to accurately reconstruct the original signal, it must be sampled at a frequency at least twice the maximum frequency present in the signal. If the sampling frequency is too low, aliasing can occur, leading to distortion in the reconstructed signal. Higher sampling frequencies can produce more accurate representations of the analogue signal but at the expense of increased data rates and storage requirements .

Plotting both the quantized signal and the originally demodulated signal together after PCM demodulation is necessary to visually assess the accuracy and effectiveness of the demodulation process. This comparison reveals how closely the reconstructed signal follows the quantized levels used during encoding and highlights any discrepancies due to system limitations or noise. It helps identify the impact of quantization error and any potential signal distortion introduced during transmission, aiding in system validation and performance evaluation .

Converting indices of quantized values into binary form is necessary because digital communication systems operate using binary data for efficient storage, processing, and transmission. Binary representation aligns with the digital nature of circuits and computer architectures, allowing for ease in operations such as error detection and correction. This conversion ensures the encoded signal is compatible with digital transmission systems and affects encoding efficiency by balancing the trade-off between bit-rate and signal fidelity. Lower bit-depth binary representations use less bandwidth but increase quantization error, while higher bit-depths improve fidelity but require more resources .

You might also like