Error Detection and Correction#
Concept#
Improve the reliability of a memory unit.
Error Detection#
A parity bit.
A single bit error can be detected, but cannot be corrected.
Error Correction code#
Generates multiple parity check bits.
The check bits generate a unique pattern, called a syndrome.
The specific bit in error can be identified.
Hamming Code#
Construction#
k k k parity bits are added to an n n n -bit data word with properties :
2 k − 1 ≥ n + k 2^k-1\ge n+k 2 k − 1 ≥ n + k .
The bit positions are numbered in sequence from 1 1 1 to n + k n+k n + k .
Those positions numbered as a power of 2 2 2 are reserved for the parity bits.
The remaining bits are the data bits.
Each parity bit should be determine by :
P i = ⨁ t ∈ S i D t P_i = \bigoplus\limits_{t\space \in \space S_i}D_t P i = t ∈ S i ⨁ D t
where P i P_i P i is the i i i -th parity bit and D t D_t D t is the t t t -th data bit, and the set S i = { x ∣ x ∈ [ 1 , n + k ] , x & 2 i = 1 , x ≠ 2 i , x ∈ Z } S_i = \{\enspace x\enspace|\enspace x\in[1, n+k],\enspace x \enspace \& \enspace2^i = 1, \enspace x \neq2^i , \enspace x \in \mathbb{Z} \enspace\} S i = { x ∣ x ∈ [ 1 , n + k ] , x & 2 i = 1 , x = 2 i , x ∈ Z } .
Here is an example :
Example (Construction)#
Success:
Consider a 8 8 8 -bit data word 11000100 11000100 11000100 , find out its hamming code.
Since we have the equation 2 k − 1 ≥ 8 + k 2^k-1\ge 8+k 2 k − 1 ≥ 8 + k , so the minimum k k k should be 4 4 4 .
That means we will have four parity bits { P 1 , P 2 , P 3 , P 4 } \{P_1, P_2, P_3, P_4\} { P 1 , P 2 , P 3 , P 4 } .
So the total bit number should be n + k = 8 + 4 = 12 n+k = 8+4 = 12 n + k = 8 + 4 = 12 bits.
At first, the total hamming code should look like this:
Bit position 1 2 3 4 5 6 7 8 9 10 11 12 Data P 1 P_1 P 1 P 2 P_2 P 2 1 P 3 P_3 P 3 1 0 0 P 4 P_4 P 4 0 1 0 0
Now, we need to calculate those parity bits using the rule above, so lets first look at the table of the binary representation of each non 2 i 2^i 2 i number :
1 2 4 8 3 1 1 5 1 1 6 1 1 7 1 1 1 9 1 1 10 1 1 11 1 1 1 12 1 1
Thus, we can get :
{ P 1 = ⨁ { D 3 , D 5 , D 7 , D 9 , D 11 } = 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 0 P 2 = ⨁ { D 3 , D 6 , D 7 , D 10 , D 11 } = 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 0 = 0 P 4 = ⨁ { D 5 , D 6 , D 7 , D 12 } = 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1 P 8 = ⨁ { D 9 , D 10 , D 11 , D 12 } = 0 ⊕ 1 ⊕ 0 ⊕ 0 = 1 \begin{cases}
P_1 &= \bigoplus \{D_3, D_5, D_7, D_9, D_{11}\} &= \space1 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space0 \space&=0 \\
P_2 &= \bigoplus \{D_3, D_6, D_7, D_{10}, D_{11}\}&=\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space1 \space\oplus\space0 \space&=0 \\
P_4 &= \bigoplus \{D_5, D_6, D_7, D_{12}\} &=\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space0 &=1\\
P_8 &= \bigoplus \{D_9, D_{10}, D_{11}, D_{12}\} &=\space0 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0&=1\\
\end{cases} ⎩ ⎨ ⎧ P 1 P 2 P 4 P 8 = ⨁ { D 3 , D 5 , D 7 , D 9 , D 11 } = ⨁ { D 3 , D 6 , D 7 , D 10 , D 11 } = ⨁ { D 5 , D 6 , D 7 , D 12 } = ⨁ { D 9 , D 10 , D 11 , D 12 } = 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 0 = 1 ⊕ 0 ⊕ 0 ⊕ 0 = 0 ⊕ 1 ⊕ 0 ⊕ 0 = 0 = 0 = 1 = 1
Finally, we can get the hamming code :
Bit position 1 2 3 4 5 6 7 8 9 10 11 12 Data 0 0 1 1 1 0 0 1 0 1 0 0
Error Detection#
When we want to check the hamming code, we will evaluate like this :
C i = P i ⊕ P i ′ = P i ⊕ ( ⨁ t ∈ S i D t ) C_i =P_i\oplus P'_i = P_i\oplus (\bigoplus\limits_{t\space \in \space S_i}D_t) C i = P i ⊕ P i ′ = P i ⊕ ( t ∈ S i ⨁ D t )
Notice that the data D i D_i D i now might be wrong, so the value of P i ′ P_i' P i ′ might be different from P i P_i P i .
Hence, if there is no error, ⋀ i = 1 k C i = 0 \bigwedge\limits_{i=1}^k C_i = 0 i = 1 ⋀ k C i = 0 .
Otherwise, there might be errors, we need to correct it.
Example (Error Detection)#
Success:
Following by the above example :
Checking is there any error in the data.
Bit position 1 2 3 4 5 6 7 8 9 10 11 12 Data 0 0 1 1 1 0 0 1 0 1 0 0
So by the definition of C i C_i C i , we can have :
{ C 1 = ⨁ { P 1 , D 3 , D 5 , D 7 , D 9 , D 11 } = 0 ⊕ 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 0 C 2 = ⨁ { P 2 , D 3 , D 6 , D 7 , D 10 , D 11 } = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 0 = 0 C 4 = ⨁ { P 4 , D 5 , D 6 , D 7 , D 12 } = 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 0 C 8 = ⨁ { P 8 , D 9 , D 10 , D 11 , D 12 } = 1 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 0 = 0 \begin{cases}
C_1 &= \bigoplus \{P_1, D_3, D_5, D_7, D_9, D_{11}\} &= \space0 \space\oplus\space1 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space0 \space&=0 \\
C_2 &= \bigoplus \{P_2, D_3, D_6, D_7, D_{10}, D_{11}\}&=\space0 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space1 \space\oplus\space0 \space&=0 \\
C_4 &= \bigoplus \{P_4, D_5, D_6, D_7, D_{12}\} &=\space1 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space0 &=0\\
C_8 &= \bigoplus \{P_8, D_9, D_{10}, D_{11}, D_{12}\} &=\space1 \space\oplus\space0 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0&=0\\
\end{cases} ⎩ ⎨ ⎧ C 1 C 2 C 4 C 8 = ⨁ { P 1 , D 3 , D 5 , D 7 , D 9 , D 11 } = ⨁ { P 2 , D 3 , D 6 , D 7 , D 10 , D 11 } = ⨁ { P 4 , D 5 , D 6 , D 7 , D 12 } = ⨁ { P 8 , D 9 , D 10 , D 11 , D 12 } = 0 ⊕ 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 0 = 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 0 = 0 = 0 = 0 = 0
Then we can have :
C = C 8 C 4 C 2 C 1 = 0000 = 0 C = C_8C_4C_2C_1 = 0000 = 0 C = C 8 C 4 C 2 C 1 = 0000 = 0
Thus the hamming code is correct! No error in this data.
Error Correction#
Danger:
! I m p o r t a n t ! ! Important ! ! I m p or t an t !
H a m m i n g c o d e c a n o n l y c o r r e c t o n e e r r o r . Hamming code can only correct one error. H ammin g co d ec an o n l y cor r ec t o n eer r or .
So lets simply assme that there is only one error in the code .
Now, we need to specify the error position.
By the error detection above, we have a lots of C i C_i C i indicating the checking out come, we want to use this data to find what data is wrong (Causing C i C_i C i to be 1 1 1 ), here are two cases :
Case 1 : Only one checking bit is 1.
This may be caused by error in the specific parity bit .
Case 2 : Multiple checking bits are 1.
Then turn the sequence C C C into decimal then we can get the wrong data bit .
Look at the following example :
Example_01 (Error Correction)#
Success:
Following by the above example :
Checking is there any error in the data, if so, fix the wrong data.
Bit position 1 2 3 4 5 6 7 8 9 10 11 12 Data 0 0 1 1 1 0 0 1 0 1 1 0
First, lets calculate the checking bits :
{ C 1 = ⨁ { P 1 , D 3 , D 5 , D 7 , D 9 , D 11 } = 0 ⊕ 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 = 1 C 2 = ⨁ { P 2 , D 3 , D 6 , D 7 , D 10 , D 11 } = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 1 = 1 C 4 = ⨁ { P 4 , D 5 , D 6 , D 7 , D 12 } = 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 0 C 8 = ⨁ { P 8 , D 9 , D 10 , D 11 , D 12 } = 1 ⊕ 0 ⊕ 1 ⊕ 1 ⊕ 0 = 1 \begin{cases}
C_1 &= \bigoplus \{P_1, D_3, D_5, D_7, D_9, D_{11}\} &= \space0 \space\oplus\space1 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space \color{red}{1} \space&=\color{red}{1} \\
C_2 &= \bigoplus \{P_2, D_3, D_6, D_7, D_{10}, D_{11}\}&=\space0 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space1 \space\oplus\space\color{red}{1} \space&=\color{red}{1} \\
C_4 &= \bigoplus \{P_4, D_5, D_6, D_7, D_{12}\} &=\space1 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space0 &=0\\
C_8 &= \bigoplus \{P_8, D_9, D_{10}, D_{11}, D_{12}\} &=\space1 \space\oplus\space0 \space\oplus\space1 \space\oplus\space\color{red}{1} \space\oplus\space0&=\color{red}{1}\\
\end{cases} ⎩ ⎨ ⎧ C 1 C 2 C 4 C 8 = ⨁ { P 1 , D 3 , D 5 , D 7 , D 9 , D 11 } = ⨁ { P 2 , D 3 , D 6 , D 7 , D 10 , D 11 } = ⨁ { P 4 , D 5 , D 6 , D 7 , D 12 } = ⨁ { P 8 , D 9 , D 10 , D 11 , D 12 } = 0 ⊕ 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 1 = 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1 ⊕ 0 ⊕ 1 ⊕ 1 ⊕ 0 = 1 = 1 = 0 = 1
Then we can have :
C = C 8 C 4 C 2 C 1 = 1101 = 11 10 C = C_8C_4C_2C_1 = 1101 = 11_{10} C = C 8 C 4 C 2 C 1 = 1101 = 1 1 10
So not only we can know C is not zero (so there is an error), and we can also know that the error is not in the parity bit (multiple 1s), then we can correct the wrong bit in D 11 D_{11} D 11 and get :
Bit position 1 2 3 4 5 6 7 8 9 10 11 12 Data 0 0 1 1 1 0 0 1 0 1 0 0
Lets look at another example :
Example_02 (Error Correction)#
Success:
Following by the above example :
Checking is there any error in the data, if so, fix the wrong data.
Bit position 1 2 3 4 5 6 7 8 9 10 11 12 Data 0 0 1 0 1 0 0 1 0 1 0 0
First, lets calculate the checking bits :
{ C 1 = ⨁ { P 1 , D 3 , D 5 , D 7 , D 9 , D 11 } = 0 ⊕ 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 0 C 2 = ⨁ { P 2 , D 3 , D 6 , D 7 , D 10 , D 11 } = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 0 = 0 C 4 = ⨁ { P 4 , D 5 , D 6 , D 7 , D 12 } = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1 C 8 = ⨁ { P 8 , D 9 , D 10 , D 11 , D 12 } = 1 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 0 = 0 \begin{cases}
C_1 &= \bigoplus \{P_1, D_3, D_5, D_7, D_9, D_{11}\} &= \space0 \space\oplus\space1 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space 0 \space&=0 \\
C_2 &= \bigoplus \{P_2, D_3, D_6, D_7, D_{10}, D_{11}\}&=\space0 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space1 \space\oplus\space0 \space&=0 \\
C_4 &= \bigoplus \{P_4, D_5, D_6, D_7, D_{12}\} &=\space\color{red}{0} \space\oplus\space1 \space\oplus\space0 \space\oplus\space0 \space\oplus\space0 &=\color{red}{1}\\
C_8 &= \bigoplus \{P_8, D_9, D_{10}, D_{11}, D_{12}\} &=\space1 \space\oplus\space0 \space\oplus\space1 \space\oplus\space0 \space\oplus\space0&=0\\
\end{cases} ⎩ ⎨ ⎧ C 1 C 2 C 4 C 8 = ⨁ { P 1 , D 3 , D 5 , D 7 , D 9 , D 11 } = ⨁ { P 2 , D 3 , D 6 , D 7 , D 10 , D 11 } = ⨁ { P 4 , D 5 , D 6 , D 7 , D 12 } = ⨁ { P 8 , D 9 , D 10 , D 11 , D 12 } = 0 ⊕ 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 0 = 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 0 = 0 = 0 = 1 = 0
Then we can have :
C = C 8 C 4 C 2 C 1 = 0100 = 4 10 C = C_8C_4C_2C_1 = 0100 = 4_{10} C = C 8 C 4 C 2 C 1 = 0100 = 4 10
So not only we can know C is not zero (so there is an error), and we can also know that the error is in the parity bit (only one 1), then we can correct the wrong bit in P 4 P_{4} P 4 and get :
Bit position 1 2 3 4 5 6 7 8 9 10 11 12 Data 0 0 1 1 1 0 0 1 0 1 0 0