Professional Documents
Culture Documents
Brief Description :
This assignment divided into small programs to generate the
most popular encoding processes :
- NRZL
- NRZI
- AMI
- PSEUDO
- MANCH
- DIFMANCH
and then draws the signal after the encoding is successfully
done ..
Possible Improvements :
The possibility for getting improved comes from handling
more encoding schemes such as B8ZS, HDB3 and also
dealing with modulation the digital data as ASK, FSK and
PSK or other encoding or modulating methods. Trying to
detect errors is also a good thought to understand the
concepts more and more, because dealing with error
requires for sure an excellent understanding and
consideration to the subjects.
Code scheme :
- The common idea is to read a sequence of the binary bits
from a text file ( called here.txt ), then use it in order to encode
these bits by the proper encoding method.
- NRZL, NRZI, AMI and PSEUDO are straight forward ..
They are representations for the 1's and 0's getting after the
encoding ..
- Due to knowledge limitation that we have about the
MATLAB, we forced in MANCH and DIFMANCH encodings
to save a changed copy of the original data in another text file
that have double size of the original one, so that it will be
easier to represent the change in signal in the middle of the bit
duration as MANCH encoding dose ..
Difficulties :
- First and most one was to recognize the program interface
(MATLAB), and to be familiar with the codes used in ..
- we stuck many times in reading from a file, and writing o
another file ..
- The challenging problem was the graphing and represent
the data on a graph ..
- More in graph, we tried many times to make a change in a
time, so that the graph will draw the time in term of the
pulse ..
- We tried to challenge the time the assignment due to and
finish all the encoding schemes of the digital data
represented by digital signal, but we failed. But at least we
tried to do the B8ZS, and we made it with errors ..
Approaches :
Codes Description :
NRZL :
Here the program gets the bits from the our input file "here.txt"
and simply check if it is 0 to represent a '+' pulse, or 1 to
represent a '-' pulse. We are using two matrices. The first one is
uu which gives our values on the y-axis. We fill it with ones if
the input was 1. Thus, it would be represented as the lower
level in the graph. In addition, if the input was 0, we draw a
line of 1's representing the pulse. The other matrix is tt which
determines time scale on the x-axis.
NRZI :
Again in this code we are doing the same operations except
that we depend on the last entered by the user. At first, we are
assuming that the last pulse was -1 and then continue. If the
input is one, he will first change the pulse variable value to the
MATLAB Codes :
with the input : 010011000010111 found in the here.txt file, we get the following results :
For NRZL :
clear all
load here.txt
x = here;
InputSize = length(x);
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
% Generating the NRZL :
t=[];u=[];
periode= 1;
for i = 1 : InputSize
tt = (i-1)*periode:1: (i)*periode;
if x(i) == 1
uu= zeros(size(tt));
else
uu = ones(size(tt));
end
t=[t tt];
u=[u uu];
end
plot(t,u), axis([0 length(x) -2 2])
grid
xlabel('t(s)')
ylabel('u(t)')
title('NRZL')
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
For NRZI :
clear all
load here.txt
x = here;
InputSize = length(x);
pulse = -1;
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
% Generating the NRZI :
t=[];u=[];
periode= 1;
for i = 1 : InputSize
tt = (i-1)*periode:1: (i)*periode;
if x(i) == 1
if pulse == 1
pulse = -1;
uu= zeros(size(tt));
else
pulse = 1;
uu = ones(size(tt));
end
else
if pulse == 1
uu = ones(size(tt));
else
uu= zeros(size(tt));
end
end
t=[t tt];
u=[u uu];
end
plot(t,u), axis([0 length(x) -2 2])
grid
xlabel('t(s)')
ylabel('u(t)')
title('NRZI')
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
For AMI :
clear all
load here.txt
x = here;
InputSize = length(x);
pulse = -1;
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
% Generating the AMI :
t=[];u=[];
periode= 1;
for i = 1 : InputSize
tt = (i-1)*periode:1: (i)*periode;
if x(i) == 1
if pulse == 1
pulse = -1;
uu = -1*ones(size(tt));
else
pulse = 1;
uu = ones(size(tt));
end
else
uu= zeros(size(tt));
end
t=[t tt];
u=[u uu];
end
plot(t,u), axis([0 length(x) -2 2])
grid
xlabel('t(s)')
ylabel('u(t)')
title('AMI')
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
For PSEUDO :
clear all
load here.txt
x = here;
InputSize = length(x);
pulse = -1;
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
% Generating the PSEUDO :
t=[];u=[];
periode= 1;
for i = 1 : InputSize
tt = (i-1)*periode:1: (i)*periode;
if x(i) == 0
if pulse == 1
pulse = -1;
uu = -1*ones(size(tt));
else
pulse = 1;
uu = ones(size(tt));
end
else
uu= zeros(size(tt));
end
t=[t tt];
u=[u uu];
end
plot(t,u), axis([0 length(x) -2 2])
grid
xlabel('t(s)')
ylabel('u(t)')
title('PSEUDO')
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
For MANCH :
clear all
load here.txt
x = here;
InputSize = length(x);
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
% Generating the MANCH :
counter = 1;
for i = 1 : InputSize
if x(i) == 1
y(counter) = '1';
fid = fopen('MANCH.txt','w');
fprintf(fid,'%c \n',y);
fclose(fid)
y(counter+1) = '0';
fid = fopen('MANCH.txt','w');
fprintf(fid,'%c \n',y);
counter = counter + 2;
else
y(counter) = '0';
fid = fopen('MANCH.txt','w');
fprintf(fid,'%c \n',y);
fclose(fid)
y(counter+1) = '1';
fid = fopen('MANCH.txt','w');
fprintf(fid,'%c \n',y);
counter = counter + 2;
end
fclose(fid)
end
clear all
load MANCH.txt
x = MANCH;
InputSize = length(x);
t=[];u=[];
periode= 1;
for i = 1 : InputSize
tt = (i-1)*periode:1: (i)*periode;
if x(i) == 1
uu = zeros(size(tt));
else
uu = ones(size(tt));
end
t=[t tt];
u=[u uu];
end
plot(t/2,u), axis([0 length(x)/2 -2 2])
grid
xlabel('t(s)')
ylabel('u(t)')
title('MANCH')
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
For DIFMANCH :
clear all
load here.txt
x = here;
InputSize = length(x);
pulse = -1 ;
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
% Generating the DIFMANCH :
counter = 1;
for i = 1 : InputSize
if x(i) == 1
if pulse == 1
y(counter) = '0';
fid = fopen('DIFMANCH.txt','w');
fprintf(fid,'%c \n',y);
fclose(fid)
y(counter+1) = '1';
fid = fopen('DIFMANCH.txt','w');
fprintf(fid,'%c \n',y);
counter = counter + 2;
pulse = -1;
else
y(counter) = '1';
fid = fopen('DIFMANCH.txt','w');
fprintf(fid,'%c \n',y);
fclose(fid)
y(counter+1) = '0';
fid = fopen('DIFMANCH.txt','w');
fprintf(fid,'%c \n',y);
counter = counter + 2;
pulse = 1;
end
else
if pulse == 1
y(counter) = '1';
fid = fopen('DIFMANCH.txt','w');
fprintf(fid,'%c \n',y);
fclose(fid)
y(counter+1) = '0';
fid = fopen('DIFMANCH.txt','w');
fprintf(fid,'%c \n',y);
counter = counter + 2
else
y(counter) = '0';
fid = fopen('DIFMANCH.txt','w');
fprintf(fid,'%c \n',y);
fclose(fid)
y(counter+1) = '1';
fid = fopen('DIFMANCH.txt','w');
fprintf(fid,'%c \n',y);
counter = counter + 2;
end
end
end
fclose(fid)
clear all
load DIFMANCH.txt
x = DIFMANCH;
InputSize = length(x);
pulse = -1 ;
t=[];u=[];
periode= 1;
for i = 1 : InputSize
tt = (i-1)*periode:1: (i)*periode;
if x(i) == 1
uu = zeros(size(tt));
else
uu = ones(size(tt));
end
t=[t tt];
u=[u uu];
end
plot(t/2,u), axis([0 length(x)/2 -2 2])
grid
xlabel('t(s)')
ylabel('u(t)')
title('DIFMANCH')
%-----------------------------------------------------%
%#####################################################%
%-----------------------------------------------------%
Output samples :
NRZL :
NRZI :
AMI :
PSEUDO :
MANCH :
DIFMANCH :