DC Lab Exp6 17l238 Rep
DC Lab Exp6 17l238 Rep
AIM:
To design and implement Line Coding schemes mbler using Scilab 6.1.0.
REQUIREMENTS:
THEORY:
A line code is the code used for data transmission of a digital signal over a transmission line. This
process of coding is chosen so as to avoid overlap and distortion of signal such as inter-symbol
interference.
Types of Line Coding
There are 3 types of Line Coding:
1. Unipolar
2. Polar
3. Bi-polar
Unipolar Signaling
Unipolar signaling is also called as On-Off Keying. The presence of pulse represents a 1 and the absence
of pulse represents a 0.
There are two variations in Unipolar signaling:
1. Non Return to Zero NRZ
2. Return to Zero RZ
Polar Signaling
In this type of Polar signaling, a High in data is represented by a positive pulse, while a Low in data is
represented by a negative pulse.
Bipolar Signaling
This is an encoding technique which has three voltage levels namely +, - and 0. Such a signal is called
as duo-binary signal.
An example of this type is Alternate Mark Inversion AMI. For a 1, the voltage level gets a transition from
+ to – or from – to +, having alternate 1s to be of equal polarity. A 0 will have a zero voltage level.
1. Bipolar NRZ
2. Bipolar RZ
17L238
In telecommunication and data storage, Manchester code (also known as phase encoding, or PE) is a
line code in which the encoding of each data bit is either low then high, or high then low, for equal time.
It is a self-clocking signal with no DC component.
A sequence of four consecutive zeros in encoded using a special "violation" bit. This bit has the same
polarity as the last 1-bit that was sent using the AMI encoding rule. Further refinement is necessary to
prevent a DC voltage from being introduced by excessive runs of zeros. THe voliation bit alternates
between + and - pulses for every consecutive group of four zeros.
SCILAB
Scilab code
Unipolar encoding
clc;
clear ;
close ;
//Uni-Polar NRZ
z =0; // Starting value on axis
for i =1:length(x)
t=[z:1:z+1]
subplot (3,1,1)
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1,-1]
title("Data")
plot (t ,x(i)) // Pl o t c u r r e n t da ta b i t
subplot(3,1 ,2)
a=gca() ;
a.data_bounds=[0 -1.5; length(x) 1.5]
a.grid=[1 -1]
title ("Unipolar NRZ")
if( x(i) ==0)
plot (t,0)
else
plot (t,1)
end
z = z+1
end
//Uni-Polar RZ
z =0;
for i =1:length(x)
t =[z:0.5:z+1]
//subplot (2,1,1)
17L238
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1 -1]
subplot (3,1,3)
a=gca();
a.data_bounds =[0 -1.5;length(x) 1.5]
Output
Polar encoding
clc;
clear ;
close ;
//Polar NRZ
17L238
z =0; // Starting value on axis
for i =1:length(x)
t=[z:1:z+1]
subplot (3,1,1)
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1,-1]
title("Data")
plot (t ,x(i))
subplot(3,1 ,2)
a=gca() ;
a.data_bounds=[0 -1.5; length(x) 1.5]
a.grid=[1 -1]
title ("Polar NRZ")
if( x(i) ==0)
plot (t,-1)
else
plot (t,1)
end
z = z+1
end
//Polar RZ
z =0; //starting value on x axis
for i =1:length(x)
t =[z:0.5:z+1]
//subplot (2,1,1)
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1 -1]
subplot (3,1,3)
a=gca();
a.data_bounds =[0 -1.5;length(x) 1.5]
z=z+1;
end
17L238
Output
Bipolar encoding
clc;
clear ;
close ;
//Bi-Polar NRZ
z =0; // Starting value on axis
k1=-1
for i =1:length(x)
t=[z:1:z+1]
subplot (3,1,1)
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1,-1]
title("Data")
plot (t ,x(i)) // Pl o t c u r r e n t da ta b i t
subplot(3,1 ,2)
a=gca() ;
a.data_bounds=[0 -1.5; length(x) 1.5]
a.grid=[1 -1]
title ("Bipolar NRZ")
if( x(i) ==0)
plot (t,0)
else
k1=-k1
plot (t,k1)
end
z = z+1
end
17L238
//Bi-Polar RZ
z =0;
k2=1
for i =1:length(x)
t =[z:0.5:z+1]
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1 -1]
subplot (3,1,3)
a=gca();
a.data_bounds =[0 -1.5;length(x) 1.5]
z=z+1;
end
Output
17L238
clc;
clear ;
close ;
//Manchester
z =0;
for i =1:length(x)
t =[z:0.5:z+1]
//subplot (2,1,1)
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1 -1]
subplot (3,1,2)
a=gca();
a.data_bounds =[0 -1.5;length(x) 1.5]
z=z+1;
end
//Differential Manchester
z =0;
k=1
17L238
for i =1:length(x)
t =[z:0.5:z+1]
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1 -1]
subplot (3,1,3)
a=gca();
a.data_bounds =[0 -1.5;length(x) 1.5]
Output
clc;
clear ;
17L238
close ;
z =0;
c=0;
count=0;
k=1;
for i =1:length(x)
t =[z:0.5:z+1]
//subplot (2,1,1)
a=gca();
a.data_bounds=[0 -1.5;length(x) 1.5]
a.grid =[1 -1]
subplot (3,1,2)
a=gca();
a.data_bounds =[0 -1.5;length(x) 1.5]
17L238
else
plot(t,0)
end
elseif(x(i)==1)
count=count+1
c=0
plot(t,k)
k=-k;
end
z=z+1;
end
Output
PSD Calculation
clc
clear all
clc
Rb=1;
Tb=1/Rb;
f=0:0.05*Rb:2*Rb;
x=f*Tb;
P=Tb*(sinc(x).*sinc(x));
figure(1)
plot(f,P,'r')
grid on;
xlabel('f ---->')
ylabel('Power Spectral Density ---->')
title('PSD for Polar Signal')
//unipolar
P1=0.5*Tb*(sinc(x).*sinc(x))+ 0.5 *dirac(f);
figure(2)
plot(f,P1,'r')
grid on
17L238
box on
xlabel('f ---->')
ylabel('Power Spectral Density ---->')
title('PSD for Unipolar Signal')
P2=Tb*(sinc(x/2)).^2.*(sin(pi*x/2)).^2;
figure(3)
plot(f,P2,'r')
grid on
box on
xlabel('f ---->')
ylabel('Power Spectral Density ---->')
title('PSD for Manchester Signal')
P3=Tb*(sinc(x/2)).^2.*(sin(pi*x)).^2;
hold on
figure(4);
plot(f,P3,'r')
grid on
box on
xlabel('f ---->')
ylabel('Power Spectral Density ---->')
title('PSD for Bipolar Signal')
hold on;
figure(1);
plot(f,P,'r')
plot(f,P1,'g')
plot(f,P2,'b')
plot(f,P3,'m')
grid on
box on
xlabel('f ---->')
ylabel('Power Spectral Density ---->')
title('PSD for Various Binary Line Codes')
legend('PSD for Polar Signal','PSD for Unipolar Signal',...
'PSD for Manchester Signal','PSD for Bipolar Signal')
Output
17L238
RESULT
Thus, the different line coding schemes have been designed, implemented and verified
successfully.
17L238