Experiment no: 04
Experiment name: Experiment on pulse code modulation using matlab software.
Objective:
   Generating a pcm signal
   Investigate the magnitude spectrum of the pcm signal
Equipment:
   A computer
   Matlab software
Code:
clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system:');
m=input('Enter number of sample in a period:');
L=2^n;
X=0:2*pi/m:4*pi;
S=8*sin(X);
subplot(3,1,1);
plot(S);
grid on;
title('Analog signal');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,2);
stem(S);
grid on;
title('Sampled signal');
xlabel('Time');
ylabel('Amplitude');
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax;
code=vmin-(del/2):del:vmax+(del/2);
[ind,q]=quantiz(S,part,code);
A=length(ind);
B=length(q);
for i=1:A
if(ind(i)~=0)
ind(i)=ind(i)-1;
end
     i=i+1;
end
for i=1:B
if(q(i)==vmin-(del/2))
        q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);
grid on;
title('quantize signal');
xlabel('Time');
ylabel('Amplitude');
figure;
code=de2bi(ind,'left-msb');
k=1;
for i=1:A
for j=1:n;
         coded(k)=code(i,j);
         j=j+1;
         k=k+1;
end
     i=i+1;
end
subplot(2,1,1);
grid on;
stairs(coded);
axis([0 100 -2 3]);
title('Encoded signal');
xlabel('Time');
ylabel('Amplitude');
grid on;
qunt=reshape(coded,n,length(coded)/n);
index=de2bi(qunt','left-msb');
q=del*index+vmin+(del/2);
subplot(2,1,2);
grid on;
title('Demodulated signal');
xlabel('Time');
ylabel('Amplitude');
output:
                  Fig: The input-output of PCM
Simulation Process of PCM :
          Fig: output signal of PCM from simulation.
Discussion: