0% found this document useful (0 votes)
63 views7 pages

DC Lab 07

The document describes tasks related to demonstrating pulse code modulation (PCM) in a digital communication lab. Task 1 involves generating an analog signal, sampling it, quantizing the samples, and plotting the original, sampled, and quantized signals. It also calculates the maximum quantization error. Task 2 describes encoding the quantized sample indices as a binary code and plotting the encoded signal.

Uploaded by

Affra Nazir
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)
63 views7 pages

DC Lab 07

The document describes tasks related to demonstrating pulse code modulation (PCM) in a digital communication lab. Task 1 involves generating an analog signal, sampling it, quantizing the samples, and plotting the original, sampled, and quantized signals. It also calculates the maximum quantization error. Task 2 describes encoding the quantized sample indices as a binary code and plotting the encoded signal.

Uploaded by

Affra Nazir
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/ 7

DEPARTMENT OF COMPUTER &

SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST,
RAWALPINDI

EC-431 Digital Communication

Lab Number 07
Demonstration of Pulse Code Modulation

Submitted By:
Affra Nazir
CE 41 A
325292
LAB TASKS:

Task 1:
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+1:delta:Vmax-1; % 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');
difference_delta = q - s;

subplot(4,1,4)

stem(difference_delta,'g*');
title('Signal with Delta Difference');
ylabel('Amplitude');
xlabel('Time');

Task 1:

code:
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; %4 pi 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(3,1,1);
plot(s,LineWidth=1.5);
title('Source Analogue Signal');
ylabel('Amplitude');
xlabel('Time');
subplot(3,1,2);
stem(s,'filled',LineWidth=1.5);
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(3,1,3);
stem(q,'filled',LineWidth=1.5);
grid on; % Display the Quantized values
title('Quantized Signal');
ylabel('Amplitude');
xlabel('Time');

% Plotting the difference between the sampled and quantized signals


delta_sig = s - q;
figure;
stem(x, delta_sig, 'filled',LineWidth=1.5);
title('Difference between Sampled and Quantized Signal (S - Q)');
xlabel('Time');
ylabel('Delta');
legend('Delta');

% Calculating the maximum quantization error


quant_error = s - q;
max_quant_error = max(abs(quant_error));
fprintf('Maximum quantization error = %f\n', max_quant_error);

output:
Task 2:

Code:
% Encoding Process
figure
code=de2bi(ind,'left-msb');
% Convert the decimal to binary For example, for 6-bit PCM (and 12 samples/period)
ind =31 33 35 35 35 34 32 30 28 27 28 29
31 33 35 35 35 33 32 30 28 27 28 30
31

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');

output:

You might also like