1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
int
decode_hamming(int encoded_lcw[])
{
int edata[10];
for (int index = 0; index < 24; index++)
{
// get 24 10-bit codewords out of 240 bit aencoded_lcw array
// and put the 10 bit arrays in edata[]
memcpy(edata, (encoded_lcw+10*index), 10);
int encoded[11],syndrome[4];
int hmatrix[4][10] = //parity matrix
{
1, 1, 1, 0, 0, 1, 1, 0, 0, 0,
1, 1, 0, 1, 0, 1, 0, 1, 0, 0,
1, 0, 1, 1, 1, 0, 0, 0, 1, 0,
0, 1, 1, 1, 1, 0, 0, 0, 0, 1
};
int i;
int j;
for(i=0;i<4;i++)
{
for(j=0;j<10;j++)
syndrome[i]+=(edata[j]*hmatrix[i][j]);
syndrome[i]=syndrome[i]%2;
}
for(j=0;j<10;j++)
if((syndrome[0]==hmatrix[0][j]) && (syndrome[1]==hmatrix[1][j])&& (syndrome[2]==hmatrix[2][j]) && (syndrome[3]==hmatrix[3][j]))
break;
if(j==10)
printf("\nError free\n");
else
{
//printf("\nError recieved at bit number %d of data\n",j+1);
edata[j]=!edata[j];
//printf("\nCorrect data should be : ");
for(i=0;i<10;i++)
printf("%d",edata[i]);
//edata[i] is the corrected ten bit codeword
//have to remove the last 4 parity bits to get the original 6 bit data or hex bits
//then put the 24 hex bits into an array for the reed-solomon decoder below
}
// put all 24 edata[] 6-bit arrays into one array
memcpy((rs_codewords+index*6), edata, 6);
}
return rs_codewords; //should be 144 bit array for the rs decode
}
|