0% found this document useful (0 votes)
33 views

Sampling Matlab

This document contains MATLAB code to demonstrate a PCM (pulse code modulation) system for digitizing and encoding an analog signal. It samples an analog sinusoidal signal, quantizes the sample values, encodes the quantized values into binary code, and decodes and reconstructs the signal. Key steps include sampling the analog signal, quantizing the samples, encoding the quantized values into binary using left-most significant bit coding, and decoding/reconstructing the signal.

Uploaded by

Sara Williams
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Sampling Matlab

This document contains MATLAB code to demonstrate a PCM (pulse code modulation) system for digitizing and encoding an analog signal. It samples an analog sinusoidal signal, quantizes the sample values, encodes the quantized values into binary code, and decodes and reconstructs the signal. Key steps include sampling the analog signal, quantizing the samples, encoding the quantized values into binary using left-most significant bit coding, and decoding/reconstructing the signal.

Uploaded by

Sara Williams
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

clc;

close all;
clear all;
n=input('enter n values for n bit pcm system');
n1=input('enter number of samples in a periodic');
l=2^n;
x=0:1/100:4*pi;
y=8*sin(x);
figure(1);
subplot(3,1,1);
plot(x,y);
title('analog signal');
ylabel('amplitude');
xlabel('time');
grid on;
x=0:2*pi/n1:4*pi;
s=8*sin(x);
subplot(3,1,2);
stem (s);
grid on;
title('sampled signal');
ylabel('amplitude');
xlabel('time');
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);
l1=length(ind);
l2=length(q);
for i=1:l1
if (ind(i)~=0)
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if (q(i)==vmin-(del/2))
q(i)=vmin+del/2;
end
end
subplot(3,1,3);
stem(q);
grid on;
title('quantised signal');
ylabel('amplitude');
xlabel('time');
figure(2)
code=de2bi(ind,'left-msb');

k=1;
for i=1:l1
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 signl');
ylabel('amplitube----->');
xlabel('time----->');
qunt=reshape(coded,n,length(coded)/n);
index=bi2de(qunt','left-msb');
q=del*index+vmin+(del/2);
subplot(2,1,2);
grid on;
plot(q);
title('demdulated signal');
ylabel('amplitube----->');
xlabel('time----->');

You might also like