Week 7 Hamming codes
Version 2023-11-04. To PDF of this week only Open the whole set of notes in PDF
Synopsis. Hamming codes are essentially the first non-trivial family of codes that we shall meet. We give a construction of a
Finding a check matrix
Before we can construct Hamming codes, we need to discuss check matrices further and prove a result (the Distance Theorem) which will allow us to find the minimum distance of a linear code from its check matrix.
The following result allows us to find a generator matrix of
Theorem 7.1: a check matrix construction
Assume that
-
Proof.
has rows which are linearly independent (due to present). It is enough to show that each row of is a codevector of indeed, we have linearly independent vectors in and is the dimension of by Theorem 5.1, so a linearly independent set of vectors must be a basis ofBy Theorem 5.1, it is enough to show that
We will show this at once for all rows of by proving that is the zero matrix. Indeed,(As claimed.) □
How can one find a check matrix of
Linearly equivalent codes
Definition: linearly equivalent codes
Two linear codes
-
(C1) choose indices
in every codeword, swap symbols and -
(C2) choose index
and non-zero in every codeword, multiply by
Fact: known from linear algebra
Every generator matrix can be brought into the standard form by using row operations (R1), (R2), (R3) considered above and column operations (C1).
Reason: any matrix can be brought to reduced row echelon form, RREF, by (R1)–(R3); a generator matrix has linearly independent rows so the RREF won’t have zero rows and will have a leading entry
Conclusion: we can always find a generator matrix in standard form for a linearly equivalent code.
The Distance Theorem
We already know how to read the length and the dimension of a linear code
-
• the number of columns of
is the length of -
• the number of columns minus the number of rows of
is the dimension of
The following theorem tells us how to determine the minimum distance of
Theorem 7.2: Distance Theorem for linear codes
Let
-
Proof. Let
be the size of a smallest linearly dependent subset of the set of columns of The theorem claims that Note that is the minimum positive number of non-zero coefficients in the linear combinationi.e., the minimum weight of non-zero
such that By Theorem 5.1, such vectors are exactly the codevectors of so as claimed. □
Example: calculate
Use the Distance Theorem to find the minimum distance of the ternary linear code with check matrix
Solution. Step 1.
Step 2. Any two columns of
Step 3. There are three linearly dependent columns in
Hamming codes: the construction
Definition: line, representative vector, projective space
A line is a
A representative vector of a line is a non-zero vector
The projective space
Remark: the terminology comes from euclidean geometry — in the euclidean plane, the set of all vectors proportional to a given non-zero vector is a straight line through the origin. Projective spaces over the field
For example,
Definition: Hamming codes
Let
Remark:
-
• multiply a column by non-zero
to get another representative of the same line; -
• put columns in any order.
This means that
Let us see how the construction works in historically the first example of a Hamming code.
Example:
Construct a parity check matrix for a binary Hamming code
Solution: we need to take one non-zero column from each line in
Start filling in the check matrix by putting the identity columns at the end (this is convenient for finding a generator matrix). In total, there are
From this
This is, up to linear equivalence, the generator matrix of the original code of R. Hamming.
Historical remark. Despite their name, the
We will see the Golay codes, and will learn about an answer to Golay’s question about perfect codes, later in the course.
Parameters of a Hamming code
We considered an example of a
We will now generalise this and show that all Hamming codes are perfect.
-
Proof. The length
of the code is equal to the number of columns in the check matrix, which is the number of lines inObserve that two lines intersect only at one point, namely
The set is therefore a disjoint union of lines. Each line contains non-zero points.So the number of lines in
can be found asWe have
since, by construction, the check matrix has rows.To find
we use the Distance Theorem for linear codes. Any two columns of are linearly independent because they are from different lines in (Two vectors are linearly dependent only if they are proportional to each other, i.e., belong to the same line.) Therefore,On the other hand,
has columns and from three different lines (where These columns are linearly dependent:So
by the Distance Theorem.It remains to show that
is perfect. We calculate The Hamming bound (in logarithmic form) then saysBy the already proved formulae for
and we have and Hence the bound is — attained. Thus, is perfect. □
Remark:
The proof shows that the fraction
Decoding a Hamming code
Algorithm 7.4: decoding algorithm for a Hamming code
Let a Hamming code be given by its check matrix
-
• Calculate
If -
•
Otherwise,
some column of Let this be the th column of -
• Subtract
from the th position in The result is the codevector
-
Proof of validity of the algorithm. We prove that the algorithm outputs the nearest neighbour of
in the code This is clear if by Proposition 5.2 is a codevector, and so its own nearest neighbour in Hence it is correct to decode to itself.If
the line in which contains has a representative column in — say, As lies on the line spanned by we must have for someNote that
equals where is the unit vector with symbol in position and zeros elsewhere. It follows thathence
is a codevector. Finally, since and no codevector can be at distance less than from we conclude that is the nearest neighbour of in □
Remark: properties of a Hamming decoder
The Algorithm and the proof above imply:
-
• Every coset leader of
is or i.e., a vector of weight or -
• The decoder changes at most one symbol in the received vector.
Note that the fact that every coset leader is of weight
For
Example: special check matrix for
Construct a decoder for the
Solution. If
-
• if
the decoder must subtract from the first bit in because is the first column of -
• if
the decoder must subtract from the second bit in because is the second column of
and so on. Subtracting
Thus, to decode the received vector