Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

MATLAB Program for Pulse Code Modulation m file

Pulse-code modulation (PCM) is a method used to digitally represent sampled analog signals. It is the standard form of digital audio in computers, compact discs, digital telephony and other digital audio applications. In a PCM stream, the amplitude of the analog signal is sampled regularly at uniform intervals, and each sample is quantized to the nearest value within a range of digital steps.

MATLAB Program: 

a=4;
fm=2;
fs=100*fm;
t=0:1/fs:1;%for sampling
x=a*sin(2*pi*fm*t);%let us take one simple sin signla for Pulse code modulation
subplot(5,1,1);
plot(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('Original message signal');
subplot(5,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('Sampled message signal');
enc=[];

for(i=1:length(x))
 if (x(i)>0 && x(i)<=1)
 e=[1 0 0];
 xq(i)=0.5;
 elseif (x(i)>1 && x(i)<=2)
 e=[1 0 1];
 xq(i)=1.5;
 elseif (x(i)>2 && x(i)<=3)
 e=[1 1 0];
 xq(i)=2.5;
 elseif (x(i)>3 && x(i)<=4)
 e=[1 1 1];
 xq(i)=3.5;
 elseif (x(i)>-4 && x(i)<=-3)
 e=[0 0 0];
 xq(i)=-3.5;
 elseif (x(i)>-3 && x(i)<=-2)
 e=[0 0 1];
 xq(i)=-2.5;
 elseif (x(i)>-2 && x(i)<=-1)
 e=[0 1 0];
 xq(i)=-1.5;
 else (x(i)>-1 && x(i)<=0)
 e=[0 1 1];
 xq(i)=-0.5;
 end
 enc=[enc e];
 end
 subplot(5,1,3);
 plot(t,xq,'b');
 title('Quantised signla');

% decoding(Receiver section)


 X_Q=[];
 for i=1:3:length(enc)-2
 if(enc(i)==0 && enc(i+1)==0 && enc(i+2)==0)
 x_q=-3.5;
 elseif(enc(i)==0 && enc(i+1)==0 && enc(i+2)==1)
 x_q=-2.5;
 elseif(enc(i)==0 && enc(i+1)==1 && enc(i+2)==0)
 x_q=-1.5;
 elseif(enc(i)==0 && enc(i+1)==1 && enc(i+2)==1)
 x_q=-0.5;
 elseif(enc(i)==1 && enc(i+1)==0 && enc(i+2)==0)
 x_q=0.5;
 elseif(enc(i)==1 && enc(i+1)==0 && enc(i+2)==1)
 x_q=1.5;
 elseif(enc(i)==1 && enc(i+1)==1 && enc(i+2)==0)
 x_q=2.5;
 elseif(enc(i)==1 && enc(i+1)==1 && enc(i+2)==1)
 x_q=3.5;
 end
 X_Q=[X_Q x_q];
 end
 subplot(5,1,4);
 plot(t,X_Q);
 title('Decoded signal');
 [num,den]=butter(6,4*fm/fs);
 recon=filter(num,den,X_Q);
 subplot(5,1,5);
 plot(t,recon);
 title('Reconstructed signal in the receiver');


Output:





No comments

Popular Posts

Followers