You are on page 1of 4

2011 International Conference on Instrumentation, Measurement, Computer, Communication and Control

Design of (15, 11) Hamming Code Encoding and Decoding System Based on FPGA
Tongsheng Zhang, Qun Ding
Heilongjiang University
Key Laboratory of Electronic Engineering, College of Heilongjiang Province
Harbin, China
qunding@yahoo.cn zhangtongsheng2006@163.com

Abstract—In the digital communication systems, due to the one bit error capacity, so it has a very widely range of
random interference from the outside, digital code may be applications in the communication systems. In this thesis,
distorted during the transmission, so the receiver can’t judge we take (15, 11) linear block codes for example to expound
correctly, it makes the communication systems’ BER increases the principle of Hamming code encoding and decoding by
greatly and affects the quality of communication. The target of
FPGA in detail. Generally, linear block codes use (n,k). k
this thesis is to design the encoding and decoding of Hamming
code by VHDL language to elaborate how hamming code to stands for information code, the length of n is encoded code
error detection and correction. So it will enhance the reliability words, and n-k=r. Linear block codes is to encoding k-bits
of communication systems. information accordance with the linear equation to
Key words-Hamming code;FPGA;error-detection-correction determine the r-bits redundancies [3]. We suppose the input
code is M=(M0,M1,…,Mk) and output code words is
I. INTRODUCTION A=(A1,A2,…,An), then we have the following
High-speed information transmission and high reliability relationship[4]:
becomes the two most important measures in modern A = M •G (1)
communication systems, high-speed means that the G is linear block codes’ generator matrix, H is check
information transforms as soon as possible from the sender matrix. Before encoding when we choose a fixed generator
to the receiver, that is source coding; high reliability matrix G. and then the relationship between information
requires information should be as correctly as possible code and check code is fixed. If we want to change the
accepted by the receiver, that is channel coding. Obviously, encoding of linear block codes, as long as we change the
the two sides are contradictory. This requires us to be generator matrix G can we change the encoding. For linear
dialectical and unity the two sides so that making block codes (n,k). If we want to indicate one bit error code,
information transfer faster and more accurately [1]. So we we should use r-bits check matrix, then the following
relationship is fixed [5]:
propose a kind of error detection and correction method by
FPGA-Hamming code, a kind of linear block codes. 2r − 1 ≥ n Or 2 r ≥ k + r + 1 (2)
Compared with other encoding methods, hamming code Besides, encoding efficiency of (n,k) is k , so
owns a higher encoding effect, encoding and decoding n
uncomplicated. Besides, vhdl is conform to ieee standards k k 1 , we may find, when r is fixed, then
= =
language, it realizes easy, and hardware owns a relatively n k + r 1+ r
faster processing speed, so data processing speed will be k
improved. encoding efficiency is growing with n increases.
II. CHANNEL CODING THEORY IV. HAMMING CODE ENCODING PRINCIPLE
Channel coding is to encoding the information according Suppose (n,k) Hamming code, k=11, n=15, r=n-k=4. We
to the certain rules and produce a fixed length of
use a14ǃa13ǃ…ǃa5ǃa4 stands for information code; S4ǃ
redundancies bits and attach it as a suffix after the
information code, and then transmitted in the channel, the S3ǃS2ǃS1 is corrector [6]. We have the following table I.
TABLE I. THE RELATIONSHIPS BETWEEN CORRECTOR AND
receiver uses the same algorithm to calculate redundancies ERROR MAP
bits and compare the both, if the two equals to each other wrong wrong
means that the information received accurately, if not, it S1 S2 S3 S4 S1 S2 S3 S4
code code
means the error happened [2]. The basic model of channel 0 0 0 1 a0 1 0 0 1 a8
coding as shown Figure 1 0 0 1 0 a1 1 0 1 0 a9
0 1 0 0 a2 1 0 1 1 a10
Figure 1. Basic model of channel coding 1 0 0 0 a3 1 1 0 0 a11
0 0 1 1 a4 1 1 0 1 a12
III. HAMMING CODE 0 1 0 1 a5 1 1 1 0 a13
Hamming code was first proposed in 1950, it is a kind of 0 1 1 0 a6 1 1 1 1 a14
linear block codes that can error detection and correction 0 1 1 1 a7 0 0 0 0 no-error

978-0-7695-4519-6/11 $26.00 © 2011 IEEE 704


DOI 10.1109/IMCCC.2011.179
From the table, if and only if an error code happened, When the receiver decoding, we take the formula 12 into
that is a3ǃa8ǃa9ǃa10ǃa11ǃa12ǃa13 or a14, corrector S1 is formula 11, we can get:
1, or S1 is 0, that is to say, these eight codes constitute even B • H T = ( A + C)H T (13)
monitor. If Ci=0, then B • H = ( A + C ) H = A • H T = 0 , that is
T T

S1 = a14 ⊕ a13 ⊕ a12 ⊕ a11 ⊕ a10 ⊕ a9 ⊕ a8 ⊕ a3 (3)


B • H T = 0 , it means that the received code words without
Similarly conclusions can be drawn: error; If CL Į 0, then B • H T = ( A + C ) H T = AH T + CH T ≠ 0 ,
S 2 = a14 ⊕ a13 ⊕ a12 ⊕ a11 ⊕ a7 ⊕ a6 ⊕ a5 ⊕ a2 (4) that is B • H T ≠ 0 , it means error happened, since C Į,
S3 = a14 ⊕ a13 ⊕ a10 ⊕ a9 ⊕ a7 ⊕ a6 ⊕ a4 ⊕ a1 (5) suppose B • H T = S , we have the follow formula:
S 4 = a14 ⊕ a12 ⊕ a10 ⊕ a8 ⊕ a7 ⊕ a5 ⊕ a4 ⊕ a0 (6) S = B • H T = ( A + C ) H T = AH T + CH T (14)
To the receiver, if no error happens, we have the following Because AH T = 0 , so S = CH T , and s is called for the
formula: corrector. And we can judge the received code whether
­ a14 ⊕ a13 ⊕ a12 ⊕ a11 ⊕ a10 ⊕ a9 ⊕ a8 ⊕ a3 = 0 there is wrong.
°a ⊕ a ⊕ a ⊕ a ⊕ a ⊕ a ⊕ a ⊕ a = 0 (7)
° 14 13 12 11 7 6 5 2
® VI. DESIGN OF HAMMING CODE ENCODING AND
° a ⊕ a ⊕ a ⊕ a ⊕ a ⊕ a ⊕ a ⊕ a =0
14 13 10 9 7 6 4 1 DECODING BY VHDL LANGUAGE
°¯ a14 ⊕ a12 ⊕ a10 ⊕ a8 ⊕ a7 ⊕ a5 ⊕ a4 ⊕ a0 = 0
VHDL (Very High Speed Integrated Circuit Hardware
We transform the formula: Description Language) is consistent with IEEE standard
­a3 = a14 ⊕ a13 ⊕ a12 ⊕ a11 ⊕ a10 ⊕ a9 ⊕ a8 high speed integrated circuit hardware description language
°a = a ⊕ a ⊕ a ⊕ a ⊕ a ⊕ a ⊕ a (8)
° 2 14 13 12 11 7 6 5 which can be used to describe a formal method for design of
®
°a1 = a14 ⊕ a13 ⊕ a10 ⊕ a9 ⊕ a7 ⊕ a6 ⊕ a4 digital circuits and digital logic systems [9]. By virtue of (15,
°¯a0 = a14 ⊕ a12 ⊕ a10 ⊕ a8 ⊕ a7 ⊕ a5 ⊕ a4 11) has a relatively higher encoding efficiency of 73.3%.
A. Encoding. The encoding flow chart shown as Figure
Information codes depend on a14 ǃa13…a5 ǃa4, check
2
codes a3 ǃa2 ǃa1 ǃa0 rely on the input information and
encoding rules, that is algebra formula (8), we can have
another expression form:
­1•a ⊕1•a ⊕1•a ⊕1•a ⊕1•a ⊕1•a ⊕1•a ⊕0•a ⊕0•a ⊕0•a ⊕0•a ⊕1•a ⊕0•a ⊕0•a ⊕0•a =0 (9)
14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
°1•a ⊕1•a ⊕1•a ⊕1•a ⊕0•a ⊕0•a ⊕0•a ⊕1•a ⊕1•a ⊕1•a ⊕0•a ⊕0•a ⊕1•a ⊕0•a ⊕0•a =0
° 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
®
°1•a14 ⊕1•a13 ⊕0•a12 ⊕0•a11 ⊕1•a10 ⊕1•a9 ⊕0•a8 ⊕1•a7 ⊕1•a6 ⊕0•a5 ⊕1•a4 ⊕0•a3 ⊕0•a2 ⊕1•a1 ⊕0•a0 =0
¯°1•a14 ⊕0•a13 ⊕1•a12 ⊕0•a11 ⊕1•a10 ⊕0•a9 ⊕1•a8 ⊕1•a7 ⊕0•a6 ⊕1•a5 ⊕1•a4 ⊕0•a3 ⊕0•a2 ⊕0•a1 ⊕1•a0 =0
Formula (9) can be denoted as:
H • AT = OT Or A • H T = 0 (10)
This is the expression of linear block codes of matrix.
V. DECODING OF LINEAR BOLCK CODES
Principle of linear block codes decoding [7]: The receiver
decoding received code words in accordance with the
decoding rules and to calculate the corrector. If the corrector
is 0, it means that the received code words without error; if Figure 2. Hamming code encoding flow chart
not, indicating accepted code words error. And then we need According to the flow chart above, we programming
to determine the wrong location code by erroneous map and encoding by VHDL, compiled and simulated it, we can find
correct it. it well done Hamming code encoding. Hamming code
Suppose the received code word is B, and not equal to simulation chart as Figure 3
A, and B is an n columns matrix [8]. We may
have B=[bn−1bn−2...bb
1 0]
, and the difference between the sender
and receiver is:
B− A=C (11)
C is the error matrix generated after the Figure 3. (15, 11) Hamming encoding simulation chart
transmission’s C = [ cn−1cn−2...c1c0 ] , and ­0,ᒰ bi = ai ,that is In the simulation, a stands for input information,
Ci = ® aa_buffer is r-bits redundancies which rely on the encoding
¯1,ᒰ bi ≠ ai
rules, s is the encoded code words with 15-bits, from the
to say: If Ci=0, it stands for the acceptance the code was no
simulation chart, we may find, if input is 01001000000,
error, otherwise, errors happened. We change the formula
according to the encoding rules, encoding programmer
(11):
calculate the redundancies 0101, the output encoded code
B = A+C (12)

705
words s is 010010000000101. Similarly, if input is In the figure, the left is hamming encoding module, the
10001000100, then r-bits redundancies is 0010, and the right is Hamming code decoding module, the middle
code words is 100010001000010. simulate channel, the simulation result shown as Figure 7
B. design of Hamming code decoding
Hamming code decoding process is based on the
received signal and decoding rules to calculate the error
corrector and judge the received code words whether there
is error, the programming flow chart shown as Figure 4 Figure 7. Hamming code simulation results
a_data is the input information, a_r is the corrector after
encoded, s is the encoded words, s_s is wrong maps, y is
decoded information. The input information is
10000000000, according to the coding rules, we have 4 bits
redundancies 1111 and attach it after the information, so s is
100000000001111, on the other side, s_s is 0000, it means
the transmission is correct, and then y is 100000000001111,
equal to s.
B. based on the above, we change the design into
another system as Figure 8

Figure 4. Hamming code decoding program flow chart


We do the similar task to write the decoding VHDL
language, compile and simulate it, and the simulation chart
shown as Figure 5
Figure 8. One bit error hamming code simulation system
The function is similar to the above; it can simulate one
bit error for example s13 that we make s13 negate artificially.
The simulation shown as Figure 9
Figure 5. Hamming code decoding simulation results
From the chart above, we can draw the conclusions as
the following:
a is 15-bits received code words, s is the corrector which
calculated by the decoding rules. If a is 101000001010010,
Figure 9. One bit error hamming code simulation results
the corrector is 1010, so we may find the error code is the From the Figure 9, we find the input information is
fifth and we change 0 to 1. Error has been checked. 100000000000000, and the error code happened at the 13th.
VII. HAMMING CODE ENCODING AND DECODING We may find that corrector s_s is not ever 0000, but for
SIMULATION 0111, according to the programmer, we judge error is 13th,
and change it to negate, so y is restored to the initial
A. We design a simple encoding and decoding information.
simulation system as Figure 6 C. Now we see another simulation system, that is during
the transmission, there may be more than one bit error
happened, we take 2 bits error happened, showing as the
Figure 10

Figure 6. Hamming code encoding and decoding simulation system

706
In conclusion, hamming code improves the reliability of
data transmission and provides a new solution for data
transmission.

ACKNOWLEDGMENT
This work is supported by the National Natural Science
Foundation of China (No.61072072).

Figure 10. Two bits error Hamming code simulation system


The simulation result shown as the following:
a_data is the input information, a_r is the corrector after REFERENCES
encoded, s is the encoded words, s_s is wrong maps, y is [1] LEI Bin, WANG Ning, QI Ping, “A Transmission
decoded information. System of Data with Hamming Code Based on FPGA,”
Journal of Xi’an Technological University. Xi’an,Vol.
29, Dec 2009.
[2] BernardSklar, “Digital Communications-Fundamentals
and Applications,” 2th Ed, publishing house of
electronics industry. Beijing, 2010, pp. 282-284.
Figure 11. Two bits error hamming code simulation results [3] YANG Hao yu, ZHANG Er zheng, “Design of
Hamming encoder based on cyclone EP1C6Q240C8, ”
From the simulation, we suppose two bits happened in Hebei Journal of Industrial Science and Technology.
the transmission that is a13 ǃa12, we may find that when Vol. 27, Nov 2010.
input is 10000000000, according to the coding rules, we [4] TANG Bing hua, SHUI Qi jun, “Design of Linear
have 4 bits redundancies 1111, so s is 100000000001111, Block Codes Based on VHDL,” signal processing, Vol.
9, Beijing, Dec 2009.
on the other side, s_s is 1100, not 0000, and there’s two bits
[5] FAN Chang xing, Zhang Pu jun, WU Cheng ke,
error, and it can not correct the error, so the encoded words “Communication Principle,” publishing house of
is not equal to the y. electronics industry. Beijing. Feb 2005, pp. 280-292.
[6] Alain Glavieux, “Channel Coding in Communication
VIII. CONCLUSION Networks-From Theory to Turbocodes,” Antony Rowe
Design shows (15, 11) Hamming code encoding and Ltd, Chippenham, Wiltshire. London, 2006,pp.68-69.
decoding by FPGA works well and complete the data error [7] GAO Chuan shan, “Data Communications and
Computer Networks,” 2th Ed publishing house of high
detection and correction. From the simulation above we find education. Beijing, 1999, pp.75-82.
these essentials: [8] WYNER A.D, “Another look at the coding theorem of
A. hamming code owns a higher encoding efficiency, so information theory-A tutorial”, Proc.IEEE, Vol. 58, No.
we can use it in data communication systems to data error- 6, pp. 894–913, June 1970.
detection-correction. [9] ZHU Zheng wei, “EDA technology,” publishinghouse
of tinghua university,Beijing.2002, pp. 4-80.
B. the simulation tells us when one bit error happens; it
[10] WANG Wen jian, XIONG Yong zhong, TANG Liang
can correct the error, so it enhances the reliability of the yi, “Design of Hamming Code Based on ISE and
communication. Modelsim,” Communication and Information
C. from the simulation c, we find if more than one bit Processing. Vol. 29, No. 3 Chengdu, Mar 2010.
error happened, hamming code will be incapable. So we
may improve the encoding method to resolve the problem.

707

You might also like