Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

eIIove *rmstztr*te ‹of echr*‹o}mgy

NAME - ARKAJYOTI

SAHA

REG. NO. - 18BEC0938

SLOT - L37+L38

DCS LAB ASSESSMENT - 1

ASSIGNED BY - PROFF. THANIKAISELVAN

Vellore Institute of Technology


PULSE CODE MODULATION

clc;
clear all;
close all;

a=5;% Peak Amplitude of the signal


fm=2; % Frequency of the sine wave
t=0:1/(100*fm):1; % x axis -- 0 to 1 in steps of 1/200;
201 samples will be in t, plotting is CT
m=a*sin(2*pi*fm*t); % Continous Time Signal, m is
original signal to be sampled

fs=25;% Sampling frequency


Ts=0:1/fs:1; % x axis for sampled signal; 26 samples,
1/fs is sampling time
Xs=a*sin(2*pi*fm*Ts); % Discrete Time signal,
Sampled signal with Ts
% 25 differnt amplitude lelvels avilable out of 26
levels
% it requires 5 bits per levlel
% in this program 25 levles will be converted to 8
levles
% totally 3 bits per lelvel
subplot(3,1,1);
plot(t,m,'r');% plot for Continuous time signal
hold on;% keeping next singnal in the same plot
stem(Ts,Xs,'k'); % Discrete Time signal, ie. Sampled
signal
xlabel('time-->');
ylabel('amp-->');
title('sampling');
legend('message signal','sampled signal');

n=3; % Quanitzed amplitude will conisist 8 values,


L=2^n; % therefore L=8
b=de2bi(0:L-1);
%b=str2double(b);

% 8 different binary values


B=zeros(length(Xs)*n,1); % 26 * 3= 78 bits will the
output
Q=zeros(length(Xs),1); % Totally 26 amplitude levles
in the signal and they are quantized
Sx=-a:(2*a)/L:a;% Quantized amplitude levels;
Toatally 9 values

for i=1:length(Xs)
for j=1:L
if Xs(i)<Sx(j+1) % current amplitude will be
checked with next amplitude in SX
Q(i)=Sx(j+1); % above condition is
satisfied the Q=Sx
B( (n*(i-1)+1) : n*i ) = b(j,:); % B for
stream of bits, b is to take corresponding binary
digits
break;
end
end
end

subplot(3,1,2);
stem(Ts,Xs,'r');
hold on;
stem(Ts,Q);
xlabel('time-->');
ylabel('amp-->');
title('Quantisation');

subplot(3,1,3);
stairs(B); % ploting 78 bits
axis([0 78 -2 3]);
xlabel('time-->');
ylabel('amp-->');
title('Encoding');
CODE SIMULATED IN MATLAB
SBWBKJ.m dcs PCM.m ^ 6
1 - clc;
g - clear ali;
3 - close all;
4
5
6 a=5;% Peak Amplitude of the signal
7 fm=2; % Frequency of the sine wave
s — t=e:1/(100*fm):1; % x axis -- e to 1 in steps of 1/2ee; 2e1 samples wil:
g — m=a*sin(2*pi^fm*t); R Continous Time Signal, m is original signal to b‹
0
1 — fs=25;% Sampling frequency
2 Ts=e:1/fs:1; % x axis for sampled signal; 26 samples, 1/fs is sampling 1
3 Xs=a*sin(2*pi*fm*Ts); % Discrete Time signal, Sampled signal with Ts
4 R 25 differnt amplitude lelvels avilable out of 26 levels
5 R it requires 5 bits per levlel
6 R in this program 25 levies will be converted to 8 levies
7 R totally 3 bits per lelvel
8 — subplot(5,1,1);
9 — plot(t,m, ’r’);% plot for Continuous time signal
0 hold on;% keeping next singnal in the same plot
i stem(Ts,Xs,’k’); % Discrete Time signal, ie. Sampled signal
2 Xlabelf 'time--> '):
SBWBKJ.m dcs PCM.m • °f°
Z* - stem(Ts,Xs,'k'); % Discrete Time signal, ie. Sampled signal
22 - xlabel(’time-->');
23 - ylabel('amp-->');
Z4 - title('sampling');
s — legend(’message signal’,’sampled signal');
26
27

29 n=3; % Quanitzed amplitude will conisist B values,


30 L=2’n; % therefore L=8
31 b=de2bi(0:L-1);

33 Ro=str2double(b);
34
35 R B different binary values
36 B=zeros(length(Xs)*n,1); R 26 * 3= 78 bits will the output
37 Q=zeros(length(Xs),l); % Totally 26 amplitude levles in the signal and they are quan
38 Sx=-a:(2*a)/L:a;X Quantized amplitude levels; Toatally 9 values
39
40 - for i=1:length(Xs)
41 - .- for j=1:L
42 if Xs(i)<Sx(j+1) R current amplitude will be checked with next amplitude in

— '¿ for i=1:length(Xs)


- ! for j:1:L
- if Xs(i)<Sx(j+1) % current amplitude will be checked with next amplitude
- Q(i)=Sx(j+1); % above condition is satisfied the Q=5x
B( (n*(i-1)+1) : n*i ): b(j,:); % B for stream of bits, b is to takf
break;
end
end
' end

- subplot(3,1,2);
stem(Ts,Xs,’r');
hold on;
stem{Ts,Q);
x1abe1('time--›');
ylabel('amp--›');
title('Quantisation');

— subplot(3,1,3);
- stairs(B); % ploting 78 bits
axis ( [B 78 -2 3] ) ;

S7
5s — subplot(3,1,3);
s9 — stairs(B); X ploting 78 bits
60 - axis([0 78 -2 3]);
6i - xlabel(’time-->');
62 ylabel('amp-->');
63 - title('Encoding');
64
OUTPUT IN MATLAB

0 0.1 0.2 0.3 0.4 D.1 0.6 0.T 0.8 0.9


time—>
Quantisation

0 0.4 0.2 0.3 0.8 0.6 OT 08


time—°
Encoding
3

2-

* 1
Eo
-1 -

0 10 20 40 60 Z0
time—›

You might also like