DC Lab 07
DC Lab 07
SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST,
RAWALPINDI
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;
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');
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;
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');
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');
output: