1
votes

I have been trying to understand Hamming Codes and wrote a program that correctly encodes and decodes given inputs for Hamming 7,4. When trying to do this for 15,11 I cannot get the right output when trying to encode.

I inputted the byte and added three leading zeros then multiplied it by the generator matrix below. After taking mod2 of the matrix I still am not getting the correct answer and am not sure if I am doing something wrong or if my matrix is incorrect.

int [][] byte = {{0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1}};

int [][] matrixG = { { 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},
                     { 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, 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, 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, 0, 0, 0, 1, 1, 0, 0, 1, 0},
                     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1} }; 

Hamming codes are a very new concept to me so I may be missing something very obvious! I really appreciate any help you can give me!

1
The generator polynomial for Hamming(15,11) is x^4 + x + 1, which corresponds to 1 0 0 1 1 cyclic code, instead of 1 1 0 0 1 in your matrixsw0rdf1sh

1 Answers

0
votes

Your G matrix is wrong.

int [][] matrixG = { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
                     { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0},
                     { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0},
                     { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0},
                     { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1},
                     { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1},
                     { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1},
                     { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 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, 0, 1, 1, 1},
                     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1} }; 

As you can see here, the G Matrix keeps the original data bits untouched, and appends additional parity bits to the end of your string.