Skip to content

Instantly share code, notes, and snippets.

@tasfik007
Last active February 28, 2024 17:43
Show Gist options
  • Save tasfik007/ac89bd4791b1739bfebf8e674a56cbd0 to your computer and use it in GitHub Desktop.
Save tasfik007/ac89bd4791b1739bfebf8e674a56cbd0 to your computer and use it in GitHub Desktop.
Line Coding

Signal Convertion with Line Coding Technique

In MatLab

alt text

load input.txt;
m = input;
n = length(m);
x = [];
y = [];
for i=1:n
x=[x i-1 i];
if(m(i)==0)
y=[y 0 0];
else
y=[y 1 1];
end
end
plot(x,y),axis([0,n,-2,2]);
title('Unipolar NRZ');
# tasfik
load input.txt;
m = input;
n = length(m);
x = [];
y = [];
for i=1:n
x=[x i-1 i];
if(m(i)==0)
y=[y 1 1];
else
y=[y -1 -1];
end
end
plot(x,y),axis([0,n,-2,2]);
title('Polar NRZ L');
m = [0 1 0 0 1 1 1 0];
n = length(m);
x = [];
y = [];
a=1;
for i=1:n
x=[x i-1 i];
if(m(i)==1)
y=[y -a -a];
else
y=[y a a];
end
a=y(length(y));
end
plot(x,y),axis([0,n,-2,2]);
title('Polar NRZ I');
m = [0 1 0 0 1];
n = length(m);
x = [];
y = [];
for i=1:n
x=[x i-1 i-1+0.5 i-1+0.5 i];
if(m(i)==0)
y=[y -1 -1 0 0];
else
y=[y 1 1 0 0];
end
end
plot(x,y),axis([0,n,-2,2]);
title('Polar RZ');
m = [0 1 0 0 1 1];
n = length(m);
x = [];
y = [];
for i=1:n
x=[x i-1 i-1+0.5 i-1+0.5 i];
if(m(i)==0)
y=[y 1 1 -1 -1];
else
y=[y -1 -1 1 1];
end
end
plot(x,y),axis([0,n,-2,2]);
title('Manchester');
m = [0 1 0 0 1 1];
n = length(m);
x = [];
y = [];
a = 1;
for i=1:n
x=[x i-1 i-1+0.5 i-1+0.5 i];
if(m(i)==0)
y=[y -a -a a a];
else
y=[y a a -a -a];
end
a=y(length(y));
end
plot(x,y),axis([0,n,-2,2]);
title('Differential Manchester');
m = [0 1 0 0 1 0];
n = length(m);
x = [];
y = [];
a=1;
for i=1:n
x=[x i-1 i];
if(m(i)== 1)
y=[y a a];
a=a*(-1);
else
y=[y 0 0];
end
end
plot(x,y),axis([0,n,-2,2]);
title('Bipolar AMI');
m = [0 1 0 0 1 0];
n = length(m);
x = [];
y = [];
a=1;
for i=1:n
x=[x i-1 i];
if(m(i)== 0)
y=[y a a];
a=a*(-1);
else
y=[y 0 0];
end
end
plot(x,y),axis([0,n,-2,2]);
title('Bipolar Pseudoternary / opposite of AMI');
m = [0 1 0 1 1 0 1 1];
n = length(m);
x = [];
y = [];
cur_lvl=0;
last_non_zero_lvl=-1;
for i=1:n
x=[x i-1 i];
if(m(i)==0)
y=[y cur_lvl cur_lvl];
else
if(cur_lvl~=0)
y=[y 0 0];
cur_lvl=0;
else
y=[y -last_non_zero_lvl -last_non_zero_lvl];
last_non_zero_lvl = last_non_zero_lvl*(-1);
cur_lvl = last_non_zero_lvl;
end
end
end
plot(x,y),axis([0,n,-2,2]);
title('MLT-3');
@tasfik007
Copy link
Author

tasfik007 commented Aug 31, 2019

From Author,

Don't forget to add the input file in your MatLab directory because some codes read their inputs from the input.txt file.
alt text

If you happen to meet the author do offer him a mug of coffee

Don't forget to give a star ✨

@sahillangoo
Copy link

sahillangoo commented Dec 16, 2021

Thanks for sharing 👍
Will Appreciate it, if you add UnipolarReturn to Zero (RZ)

@alsmnd
Copy link

alsmnd commented Nov 5, 2022

Thanks for sharing 👍 Will Appreciate it, if you add UnipolarReturn to Zero (RZ)

ip = input('Enter the last two digit of ID: ');
bin = dec2bin(ip);
m = sprintf('%s', bin)-'0';
n = length(m);
x = [];
y = [];

for i=1:n
x=[x i-1 i-1+0.5 i-1+0.5 i];
if(m(i)==0)
y=[y 0 0 0 0];
else
y=[y 1 1 0 0];
end
end

plot(x,y,'color', 'r','Linewidth',1.5);
axis([0,n,-2,2]);
title('Unipolar RZ');
xlabel('Time');
ylabel('Amplitude');
grid on;

ax = gca;
ax.GridLineStyle = '--';
ax.GridAlpha = 0.2;

for k=1:n
text(k-0.55,1.4,num2str(m(k)));
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment