You are on page 1of 16

Theoretical Introduction to The Topic :

Generation of digital codes :


When handling digital signals, we use The Encoding
techniques. In this assignment, we are approaching the
encoding of digital data as digital signals. Encoding into digital
signals has the benefit of using modern digital transmission
and switching methods and it is the basis for Time Division
Multiplexing (TDM). In this process of encoding, we represent
our digital data as either Unipolar Signals; which are defined
as binary data represented by signals of the same polarity, or as
Polar Signals which are binary data represented by signals of
opposite polarity. The schemes available to do so are as
follows.
1. The Nonreturn to Zero (NRZ) Group:
This is represented by Unipolar Signals and include:
a. Nonreturn to Zero-Level (NRZ-L): that represent
0 with a no signal line (0 volt) the 1 with positive
voltages.
b. Nonreturn to Zero Inverted (NRZI): in this
technique we represent 0 with a no-change state in
the signal, and 1 with a change-signal state.
2. The Multi-level Binary Group :
Which is represented by Polar Signals and can be found
in two schemes:
a. Bipolar-AMI (Alternate Mark Invert): in this
method 0 is represented by no line signal and 1 by a
positive or negative pulse having the pulses
alternate in polarity.
b. Pseudoternary: this is a method which works as an
opposite of the AMI encoding method. It represents
the no line signal with a 1 and the alternating
positive and negative pulses with 0's.

3. The Bi-Phase (RZ) Group:


Another scheme that uses Unipolar Signal to represent its
data. It performs each transition at middle of the clock
pulse. It can be represented as the following encoding
techniques:
a. Manchester: we have 0 represented by a low to
high transition and 1 by a high to low transition.
b. Differential Manchester: the transition in the
midbit is for self-clocking, and we represent our 1's
and 0's in the start of each bit. 1 is presented with a
no transition and 0 by a transition at bit start.
4. Scrambling Group :
These encoding techniques use the AMI method as a base
but with an advantage of having no dc component
without the need for additional data, and also a self
capability of error detection. Further, using such scheme
would make it much harder for Noise to act like the
original data.
a. B8ZS (Bipolar with 8-Zeros Substitution)
b. HDB3 (High Density Bipolar 3-Zeros)

General Look to The Programming Tool :


This program assignment prepared by MATLAB program.
It's a powerful program for mathematical representation
purposes. It is a tool for doing numerical computations with
matrices and vectors. The program contains three main
windows:
- The directory window,
- The command window,
- The command history window.
The program also contains an extra editor allows the user to
enter clean codes, similar to the JAVA editors. It has sufficient
amount of tools available on its library. The typical uses for
MATLAB are:
- Algorithm and development

Math and computation


Data acquisition
Modeling and simulating
Data analysis
Scientific and engineering graphics
Application development

Finally, the MATLAB stands for matrix laboratory. It was


originally written to provide easy access to matrix.

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 ..

Practical Lessons Learnt :


In MATLAB, we are now capable of using this software for
programming purposes. We learnt the general and basic idea of
the matrix ( which is the main concern of the program ), and
how to deal with it. The other codes capabilities like loops,
conditional statements, file IO operations and visualizing the
data.

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.

More ideas to work on :


- Handling the B8ZS and HDB3 :
These two encoding methods require more work in MATLAB
to represent the encoded data graphically or even as bits.
- Dealing with modulation the digital data :
the problem in MATLAB in manipulating the analog data that
it may impossible for the program to consider the graphics and
represent them as data or formulas. So that, the modulations
and the encodings techniques for analog data are ignored.
- Trying to detect errors :
detecting errors might be easy in term of comparing the
original data with the encoding one. It's just making a loop to
compare between to integers. Moreover, the program should
produce a correct encoding data so that no need for catching
errors. Otherwise, the program is useless.

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 :

In the beginning, we tried to figure out the most useful


program that will help us in a good assignment in the course.
After a day of asking our friends and instructors, we decided
to do it with the MATLAB. We started searching to find some
codes or programs already work and run in the program. We
tried to understand the logic and figure the codes used and in
which way they are used. Then we started the work by
making small programs and tested them to see the mistake
and correct them. After that, we entered the MATLAB gate to
design our assignment with our limited knowledge. The
design of NRZL, NRZI, AMI and PSEUDO was some how
easy. But we spend some time in MANCH codes. Before we
consider that the MATLAB can do graphing, we thought
about exporting the encoding bits in a text file, and then use
JAVA Frames to draw the bits. Lately, we surprised with the
ability of MATLAB to graph our encoded data, and we asked
for a late assignment submission, so that we could submit a
good assignment as COE students, and we think that we did it
finally.

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

opposite value and then draw the pulse. If it was zero, we


would continue drawing the last pulse as is.
AMI :
In this scheme we are assuming the input to be -1 at the
beginning of the code, then we check if the next input is +1 or
-1, then we reverse the last pulse value and draw in the
opposite direction. If it has a zero input, then we will stay at
the zero level.
PSEUDO:
Same as the AMI procedure but one represent no-signal mode
and zero is the one alternating the polarity of the signal.
MANCH :
In the case of Manchester encoding, the bit transmission is
made in the middle of the pulse. Moreover, we have to go in
the graph from high to low if the input is one and the opposite
if the input is zero. So, we have to divide each input entry into
to bits in order to represent it. Thus, what the code is doing is
that it is building a new file called "MANCH.txt" and forming
our new-to-be input there. Having "1" followed by a "0" is a
low to high transmission => input =1, and "0" then "1"
representing a zero input.
DIFMANCH :
In Differential Manchester we assume the input is -1 meaning
(lower volt) in the beginning. Taking the first input, if it is a
one, we enter the pulse with no change from the lower level
and then at the middle o the pulse we go up. If input is zero,
we change polarity and draw.

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 :

You might also like