Hamming Code
Hamming Code
UNIVERSITY OF TECHNOLOGY
HAMMING CODE
Civil Engineering
2 Nguyễn Hà Phong 2452959
Civil Engineering
3 Nguyễn Minh Quân 2453073
Transportation
4 Mai Tường Bách 2452115 Engineering
Contents:
I Acknowledgement.................................................................................................4
II Abstract................................................................................................................................... 4
III Introduction................................................................................................................5
IV Theory........................................................................................................................6
1 Principles of Hamming code..................................................................................6
1.1 Parity bits...................................................................................................... 6
1.2 Even or odd parity and parity check for error detection............................... 6
1.3 Position of parity bits....................................................................................6
1.4 Error correction.............................................................................................7
2 Encoding process................................................................................................... 7
3 Decoding and error correction............................................................................... 9
3.1 Reception...................................................................................................... 9
3.2 Syndrome Calculation...................................................................................9
3.3 Syndrome Bits...............................................................................................9
3.4 Error Location...............................................................................................9
3.5 Error Correction............................................................................................9
4 Error Detection and Correction Capabilities....................................................... 10
4.1 Error Detection........................................................................................... 10
4.2 Error Correction..........................................................................................10
4.3 Single-Bit Error Correction.........................................................................11
4.4 Limitations.................................................................................................. 11
5 Hamming distance and properties........................................................................11
5.1 Definition 1................................................................................................. 11
5.2 Definition 2................................................................................................. 11
5.3 Definition 3................................................................................................. 12
5.4 Properties.................................................................................................... 12
V Applications.............................................................................................................. 13
VI Discuss & Extensions.............................................................................................. 14
1 Discuss................................................................................................................. 14
2 Extensions............................................................................................................14
2.1 Extended Hamming Code (SEC/DED).......................................................14
2.2 Triple-Error-Correcting Hamming Code (TECH)...................................... 14
2.3 Quadruple-Error-Correcting Hamming Code (QECH).............................. 14
2.4 Hamming Codes for Non-Binary Alphabets.............................................. 15
VII Matlab Code Implementation & Explanation........................................................ 16
1 Code implementation...........................................................................................16
2 Code Explanation.................................................................................................17
3 Result................................................................................................................... 19
VIII Conclusion............................................................................................................ 19
II. Abstract
With the increased data transmission and exchange between multiple network devices
for information purposes, the probability of an error or damage occurring to the original
data bit is highly possible.
The Hamming code is a method of error detection and correction used in digital
communication and data storage systems. It adds extra bits to a block of data to create a
code word that facilitates the identification and correction of errors that may occur during
transmission or storage. Developed by Richard Hamming in the 1950s, these codes are
designed to detect and correct single-bit errors within a code word.
This abstract delves into the core principles of Hamming codes, emphasizing their role
in enhancing data accuracy, detecting errors, and correcting transmission flaws. By adding
redundancy through carefully positioned parity bits, Hamming codes ensure reliability in
various digital applications, from computer memory systems to data transmission,
fortifying the foundation of error-free communication in modern technological landscapes.
III. Introduction
Hamming code is an error correction system that can detect and correct errors
when data is stored or transmitted. Richard Hamming developed them in the early
1950s and are particularly useful in systems where data accuracy is crucial, such as in
computer memory systems or data transmission.
The main purpose of Hamming codes is to add extra bits to a block of data to create
a code word that can be easily checked for errors. Hamming code uses the connection
between data and redundant bits and may be applied to data units of any length.
When the data is transmitted, these extra parity bits allow the receiver to identify if
any errors have occurred and, in some cases, correct them. If an error is detected, the
receiver can use the information from the parity bits to determine which bit is incorrect
and fix it.
IV. Theory
1 Principles of Hamming code
The basic idea behind Hamming code involves adding redundant bits to the
original data to create a codeword. These redundant bits are carefully chosen to allow
for the detection and correction of errors. The key principle of Hamming code is based
on the use of parity bits and their specific placement within the codeword. Using
multiple parity checks to binary search for the error.
The second parity bit checks every bit whose binary representation includes a 1 in
the second least significant bit (21), and so on.
The reason why the parity bits sit in positions that are power of 2 is because each
of those parity bits sits inside one and only one of the parity groups. No matter how
large the information may be, each bit conveniently touches one of the group only.
Therefore, it should be able to correct data of one chunk of bits, keeping it from
interfering with the other chunks.
By examining the block of bits, it is possible to identify the position of the
erroneous bit.
For example:
1 0 1 0
0 1 2 3
0 1 0 1
4 5 6 7
1 0 0 1
8 9 10 11
0 0 1 0
12 13 14 15
2 Encoding process
Encoding process includes 5 steps:
The non-zero syndrome in position 2 indicates an error. Flipping bit 2 corrects the
error, resulting in the original data: 1111011.
It is important to note that Hamming code can correct only one error at a time. If
more than one error occurs, Hamming code can still detect the errors but cannot
correct them.
For example: If P1, P2, and P4 indicate errors, the position of the error can be
determined by finding the intersection of the sets of positions covered by these parity
bits. If, for instance, it is determined that the error is in position 5, then the bit at
position 5 is flipped to correct the error.
4.4 Limitations
While Hamming codes are effective for correcting single-bit errors, they have
limitations. They can detect and correct only one error per code word. If there are
multiple errors, or if errors occur in both the data and parity bits, Hamming codes may
not be able to correct the data accurately.
In summary, Hamming codes use carefully positioned parity bits to both detect and
correct errors in transmitted data. They are particularly useful in scenarios where the
emphasis is on correcting occasional single-bit errors, as is common in digital
communication and data storage system.
5 Hamming distance and properties
5.1 Definition 1
The Hamming distance between two strings is the number of positions at which the
corresponding bits are different at equal length. In simpler terms, it’s the number of
substitutions needed to change one string into the other. Typically, hamming distance
is denoted by the function d(x, y) where x and y are codewords.
5.2 Definition 2
The minimum Hamming distance is the smallest Hamming distance between all
possible pairs of strings in a set of strings of equal lengths.
5.3 Definition 3
The Hamming weight of a string is the number of symbols that are different from
the zero symbols of the alphabet used. It is thus equivalent to the Hamming distance
from the all-zero string of the same length.
5.4 Properties
Non-negativity: The hamming distance between two strings is always greater
than or equal to zero, and it is zero if and only if the strings are identical.
Symmetry: The hamming distance between two strings is the same regardless
of the order in which they are compared.
Triangle inequality: The hamming distance between two strings is never greater
than the sum of the hamming distances between them and a third string.
Metric: The hamming distance satisfies the four conditions of a metric, which
means it can be used to measure the distance or similarity between strings in a
mathematical way.
Code distance: The hamming distance can be used to define the distance of a code,
which is the minimum hamming distance between any two distinct codewords. This
determines the error detection and correction capabilities of the code.
V. Applications
Common applications of using Hamming code are Satellites, Modems, or Wireless
communication.
Basically, Hamming code applies to circumstances where a piece of information is
transferred between sender, receiver and during the transmission there are potential
noises that cause the error in the chunks of bits.
For example:
Suppose you are sending data over a wireless channel, such as Wi-Fi, and you want
to ensure that the received data is not corrupted during transmission. One method of
ensuring data integrity is to use Hamming Code to detect and correct bit errors during
transmission.
2 Extensions
2.1 Extended Hamming Code (SEC/DED)
Purpose: This extension is designed to detect and correct single errors and
detect double errors (SEC/DED).
Mechanism: It adds extra parity bits to the original Hamming code, enabling the
detection and correction of additional errors.
Mechanism: It increases the number of parity bits to provide the ability to correct
up to three errors.
Mechanism: It continues the trend of adding more parity bits to enhance error
correction capabilities.
2.4 Hamming Codes for Non-Binary Alphabets
Purpose: Hamming codes can be extended to work with non-binary alphabets
(symbols with more than two values).
1. Code implementation
parity_bits = 0;
while 2^parity_bits < data_size + parity_bits + 1
parity_bits = parity_bits + 1;
end
% Create matrix P
PT = H(:, [3, 5, 6, 7]);
% Initialize matrix G
G = zeros(total_bits, data_size);
% Assign rows of G
G([1, 2, 4], :) = P'; %Rows 1, 2, 4 of G are rows 1, 2, 3 of P
G([3, 5, 6, 7], :) = I_k; % Rows 3, 5, 6, 7 of G are the identity matrix.
% Display G matrix
disp('Generator matrix G:');
disp(G);
syndrome = H * received_code';
syndrome_decimal = 0;
n = length(syndrome_binary);
for i = 1:n
syndrome_decimal = syndrome_decimal + syndrome_binary(i) * 2^(n-i);
end
2 disp(syndrome_decimal);
2. Code Explanation
3. Result
VIII. Conclusion
Hamming code has emerged as a cornerstone of reliable communication in the
digital age. Its ability to detect and correct single-bit errors has made it a crucial
component in various applications, from computer memory and satellites to modems
and embedded systems.Hamming code offers a powerful solution for data integrity in
the face of errors. While it has limitations, such as increasing data size, can not detect
and correct multiple errors,its simplicity, efficiency, and reliability make it a valuable
tool for ensuring reliable communication in numerous applications.
IX. References
Big Assignment for Linear Algebra Page 18/20
HO CHI MINH UNIVERSITY OF TECHNOLOGY (HCMUT)
[1] Wright, G. (2022, July). What is Hamming code and how does it work?
WhatIs.com.
[2] Kapoor, A. (2023, October 30). What Is Hamming Code? The Network Technique
to Detect Errors and Correct Data|Simplilearn. Simplilearn.com.