You are on page 1of 5

Name: Dev Mehta Date: August 3, 2021

Reg. no.: 19BEC1300


Experiment-1
Pulse coded modulation

Aim: Illustrate pulse coded modulated signal.

Software used: Matlab

Theory: Pulse Code Modulation is a method of converting an analog signal into a digital signal.
Analog signal is characterized by the fact that its amplitude can take on any value over a continuous
range. This means that it can take on an infinite number of values. In PCM an analog signal is first
sampled at a rate higher than the Nyquist rate, and then the samples are quantized. It is assumed
that the analog signal is distributed on an interval denoted by [-Xmax, Xmax], and the number of
quantization levels is large.

MATLAB Code:
clc
close all;
n=input('Enter no. of samples per cycle: ');
t=0:2*pi/n:4*pi;
%define the time component
A=4;
%define the message signal
ms=A*sin(t);
%plot the message signal
figure(1);
plot(t,ms,'r');
title('Message Signal');
xlabel('time');
ylabel('amplitude');
figure(2);
stem(t,ms,'r');
title('Message Signal');
xlabel('Time');
ylabel("Amplitude")
%quantization %2
x=input('Enter no. of bits per sample: ');
%define the number of quantization levels
L=2^x;
%define xmin xmax of the signal
xmax=5;
xmin=-5;
%step size
del=(xmax-xmin)/L;
%partion the signal
partition=xmin:del:xmax;
%define the decision level
decision_level=xmin-(del/2):del:xmax+(del/2);
[index,quantis]=quantiz(ms,partition,decision_level);
figure(3);
%ploting Quantized Signal
stem(quantis);
title('Quantized Signal');
xlabel('Time');
ylabel("Amplitude")
l1=length(index);
%encoding
for i=1:l1
if(index(i)~=0)
index(i)=index(i)-1;
end
end
%decimal to binary
code=de2bi(index,'left-msb')
k=1;
%rearranging the code in a horizontal sequence for plotting
for i=1:l1
for j=1:x
coded(k)=code(i,j)
j=j+1;
k=k+1;
end
i=i+1;
end

OUTPUT CONSOLE:

Enter no. of samples per cycle: 20


Enter no. of bits per sample: 2

code =

0 1
1 0
1 0
1 1
1 1
1 1
1 1
1 1
1 0
1 0
1 0
0 1
0 1
0 0
0 0
0 0
0 0
0 0
0 1
0 1
0 1
1 0
1 0
1 1
1 1
1 1
1 1
1 1
1 0
1 0
1 0
0 1
0 1
0 0
0 0
0 0
0 0
0 0
0 1
0 1
0 1
Output Waveforms:
INFERENCE: In this simulation, we have quantized a sine wave signal (message) and encode it to
binary bits, and reconstructed the sine wave from binary bits.

You might also like