Hamming Code: Matlab Tutorial
|In this post we are going to develop the Hamming Code error correction algorithm in Matlab, so the first thing you need to do is to download our free Hamming Matlab Code from Mathworks: https://uk.mathworks.com/matlabcentral/fileexchange/57312-hamming-code–matlab-tutorial
We now that the identity matrix dimensions are: r x r=4 x 4 and, the transposed parity matrix: r x k = 4 x 11. Therefore, the H matrix dimensions are 4 x 15, for example:
1 0 0 0 1 0 0 1 1 0 1 0 1 1 1
H= 0 1 0 0 1 1 0 1 0 1 1 1 1 0 0
0 0 1 0 0 1 1 0 1 0 1 1 1 1 0
0 0 0 1 0 0 1 1 0 1 0 1 1 1 1
In the same way, we can conclude that the G matrix dimensions are 11 x 15, for instance:
1 1 0 0 1 0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 1 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 1 0 0 0 0 0 0 0 0
1 1 0 1 0 0 0 1 0 0 0 0 0 0 0
1 0 1 0 0 0 0 0 1 0 0 0 0 0 0
G= 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0 1 0 0 0 0
0 1 1 1 0 0 0 0 0 0 0 1 0 0 0
1 1 1 1 0 0 0 0 0 0 0 0 1 0 0
1 0 1 1 0 0 0 0 0 0 0 0 0 1 0
1 0 0 1 0 0 0 0 0 0 0 0 0 0 1
The next step is to find the Hamming dual, (15,11); therefore, we need to work with the Hamming (15, 4). Now the size of the code word is still the same, but the size of the input message is going to be 4 (before it was 11) and theredundancy, 11 (before it was 4)
In addition, our new generator matrix, G, will be the Hamming matrix, H (15,11); in this way, we will form the following “input message-code word” table:
m (input) |
Code word |
0000 |
000000000000000 |
0001 |
000100110101111 |
0010 |
001001101011110 |
0011 |
001101011110001 |
0100 |
010011010111100 |
0101 |
010111100010011 |
0110 |
011010111100010 |
0111 |
011110001001101 |
1000 |
100010011010111 |
1001 |
100110101111000 |
1010 |
101011110001001 |
1011 |
101111000100110 |
1100 |
110001001101011 |
1101 |
110101111000100 |
1110 |
111000100110101 |
1111 |
111100010011010 |
We select a code word to transmit, for example, the corresponding with the input message [0101], which is [010111100010011].
Let’s suppose that after transmitting by a channel, there is a bit error in a random position; in this case, after computing the module, we obtain: (20809379,7)=3.
We use the property that allow us to obtain the syndrome vector from the error vector (size 1×15), by using H transposed (this is equivalent to do: received vector multiplied by H transposed) and, knowing that the H of the Dual Hamming (15,4) is the G obtained obtained for the (15,11).
Therefore, if our error vector is: e=[001000000000000] and GT is:
1 0 0 1 1 0 1 0 1 1 1
1 1 0 1 0 1 1 1 1 0 0
0 1 1 0 1 0 1 1 1 1 0
0 0 1 1 0 1 0 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0
GT= 0 0 1 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 1
Finally, the syndrome vector that we obtain and we need to check with the syndrome vector to error vector map is:
S=[01101011110]
*This vector is the third row of HT, as it has been places in the error position.
Now you are ready to fully understand the provided Matlab code (see link above)! We hope you found this post useful and don’t hesitate to ask questions or require further posts for any of the sections that we have!