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

MUHAMMAD HASEEB IFTIKHAR

10-ENC-49
LINE CODING:

NRZ:
function nrz(d)
l=length(d);
t=1:l;
lev=5;
tc=1:.5:(l+0.5);
clk=[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ];
y=[zeros(1,l)];
subplot(3,1,1);
stairs(t,d,'linewidth',2);
axis([1 l 0 1.2]);
title('DATA','fontweight','Bold');
subplot(3,1,2);
stairs(tc,clk,'linewidth',2);
axis([1 l 0 1.2]);
title('CLOCK','fontweight','Bold');
for k=1:l
if d(k)==1
y(k)=lev;
else
y(k)=0;
end
subplot(313)
text(k+0.5,lev+1.3,num2str(d(k)),...
'fontweight','bold')
hold on
end
stairs(t,y,'linewidth',2);
axis([1 l 0 lev+3]);
title('NRZ','fontweight','bold');
grid on

M HASEEB IFTIKHAR
DEPT. OF ELECTRONICS ENGINEERING
University of Engineering and Technology, Taxila
PAKISTAN

BIP-NRZ
function bip_nrz(d)
l=length(d);
t=1:l;
lev=5;
tc=1:.5:(l+0.5);
clk=[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ];
y=[zeros(1,l)];
subplot(3,1,1);
stairs(t,d,'linewidth',2);
axis([1 l 0 1.2]);
title('DATA','fontweight','Bold');
subplot(3,1,2);
stairs(tc,clk,'linewidth',2);
axis([1 l 0 1.2]);
title('CLOCK','fontweight','Bold');
for k=1:l
if d(k)==1
y(k)=lev;
else
y(k)=-lev;
end
subplot(313)
text(k+0.5,lev+1.3,num2str(d(k)),...
'fontweight','bold')
hold on
end
stairs(t,y,'linewidth',2);
axis([1 l -lev-1 lev+3]);
title('BIP-NRZ','fontweight','bold');
grid on

RZ
function rz(d)
l=length(d);
t=1:l;
lev=5;
tc=1:.5:(l+0.5);
clk=[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ];
y=[zeros(1,2*l)];
subplot(3,1,1);
stairs(t,d,'linewidth',2);
axis([1 l 0 1.2]);
title('DATA','fontweight','Bold');
subplot(3,1,2);
stairs(tc,clk,'linewidth',2);
axis([1 l 0 1.2]);
title('CLOCK','fontweight','Bold');
for k=1:l
if d(k)==1
y(2*k-1)=lev;
y(2*k)=0;
else
y(2*k-1)=0;
end
subplot(313)
text(k+0.3,lev+1.3,num2str(d(k)),...
'fontweight','bold')
hold on
end
stairs(tc,y,'linewidth',2);
axis([1 l 0 lev+3]);
title('RZ','fontweight','bold');
grid on

BIP-RZ
function b_rz(d)
l=length(d);
t=1:l;
lev=5;
tc=1:.5:(l+0.5);
clk=[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ];
y=[zeros(1,2*l)];
subplot(3,1,1);
stairs(t,d,'linewidth',2);
axis([1 l 0 1.2]);
title('DATA','fontweight','Bold');
subplot(3,1,2);
stairs(tc,clk,'linewidth',2);
axis([1 l 0 1.2]);
title('CLOCK','fontweight','Bold');
for k=1:l
if d(k)==1
y(2*k-1)=lev;
y(2*k)=-lev;
else
y(2*k-1)=-lev;
y(2*k)=-lev;
end
subplot(313)
text(k+0.3,lev+1.3,num2str(d(k)),...
'fontweight','bold')
hold on
end
stairs(tc,y,'linewidth',2);
axis([1 l -lev-1 lev+3]);
title('BIP-RZ','fontweight','bold');
grid on

MANCHASTER
function manc(d)
l=length(d);
t=1:l;
lev=5;
tc=1:.5:(l+0.5);
clk=[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ];
y=[zeros(1,2*l)];
subplot(3,1,1);
stairs(t,d,'linewidth',2);
axis([1 l 0 1.2]);
title('DATA','fontweight','Bold');
subplot(3,1,2);
stairs(tc,clk,'linewidth',2);
axis([1 l 0 1.2]);
title('CLOCK','fontweight','Bold');
for k=1:l
if d(k)==1
y(2*k-1)=lev;
y(2*k)=0;
else
y(2*k-1)=0;
y(2*k)=lev;
end
subplot(313)
text(k+0.3,lev+1.3,num2str(d(k)),...
'fontweight','bold')
hold on
end
stairs(tc,y,'linewidth',2);
axis([1 l 0 lev+3]);
title('MANCHESTER','fontweight','bold');
grid on

AMI
function ami(d)
l=length(d);
t=1:l;
lev=5;
flag=0;
tc=1:.5:(l+.5);
clk=[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ];
y=[zeros(1,2*l)];
subplot(3,1,1);
stairs(t,d,'linewidth',2);
axis([1 l 0 1.2]);
title('DATA','fontweight','Bold');
subplot(3,1,2);
stairs(tc,clk,'linewidth',2);
axis([1 l 0 1.2]);
title('CLOCK','fontweight','Bold');
for k=1:l
if d(k)==1
if flag==0
y(2*k-1)=lev;
y(2*k)=0;
flag=1;
else
y(2*k-1)=-lev;
y(2*k)=0;
flag=0;
end
else
y(2*k-1)=0;
end
subplot(313)
text(k+0.3,lev+1.3,num2str(d(k)),...
'fontweight','bold')
hold on
end
stairs(tc,y,'linewidth',2);
axis([1 l -lev-1 lev+3]);
title('AMI','fontweight','bold');
grid on

You might also like