In MatLab
Last active
February 28, 2024 17:43
-
-
Save tasfik007/ac89bd4791b1739bfebf8e674a56cbd0 to your computer and use it in GitHub Desktop.
Line Coding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 0 1 1 0 |
Thanks for sharing 👍
Will Appreciate it, if you add UnipolarReturn to Zero (RZ)
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
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.