Golay Code Implementation – Encoding » History » Version 2

ABDALLAH, Hussein, 03/13/2016 12:13 PM

1 1 ABDALLAH, Hussein
h1. Golay Code Implementation – Encoding
2 1 ABDALLAH, Hussein
3 1 ABDALLAH, Hussein
The Golay code is encoded using modulo-2 division. Taking into account that the information bits are 12 per codeword, we must encode each 12-bit as one codeword.
4 1 ABDALLAH, Hussein
 The characteristic polynomials for the Golay code are:
5 1 ABDALLAH, Hussein
6 1 ABDALLAH, Hussein
•	X11 + X9 + X7 + X6 + X5 + X + 1, coefficients AE3h.
7 1 ABDALLAH, Hussein
•	X11 + X10 + X6 + X5 + X4 + X2 + 1, coefficients C75h.
8 1 ABDALLAH, Hussein
9 1 ABDALLAH, Hussein
These polynomials generate different checkbits. For our encoding algorithm we will use the first polynomial AE3h.
10 1 ABDALLAH, Hussein
Below, there is an example illustrating by hand the module-2 division process using exclusive-OR (XOR). The data is 555h. To generate 11 check-bit, we append 11 zero onto the bit-reversed data (LSB first). 
11 1 ABDALLAH, Hussein
12 1 ABDALLAH, Hussein
13 2 ABDALLAH, Hussein
           Golay                                                    
14 1 ABDALLAH, Hussein
      polynomial    info bits   zero fill                        
15 1 ABDALLAH, Hussein
     |----------|  |----------||---------|                       
16 2 ABDALLAH, Hussein
      AE3h            _555h(reversed)                      
17 1 ABDALLAH, Hussein
     101011100011 )10101010101000000000000   (11 zeros)                    
18 1 ABDALLAH, Hussein
                   101011100011  (AE3h)                                
19 1 ABDALLAH, Hussein
                   ------------ <---------- Exclusive-OR         
20 1 ABDALLAH, Hussein
                        100100100000                             
21 1 ABDALLAH, Hussein
                        101011100011                             
22 1 ABDALLAH, Hussein
                        ------------                             
23 1 ABDALLAH, Hussein
                          111100001100                           
24 1 ABDALLAH, Hussein
                          101011100011                           
25 1 ABDALLAH, Hussein
                          ------------                           
26 1 ABDALLAH, Hussein
                           101111011110                          
27 1 ABDALLAH, Hussein
                           101011100011                          
28 1 ABDALLAH, Hussein
                           ------------                          
29 1 ABDALLAH, Hussein
                              100111101000                       
30 1 ABDALLAH, Hussein
                              101011100011                       
31 1 ABDALLAH, Hussein
                              ------------                       
32 1 ABDALLAH, Hussein
                               01100001011 <-- checkbits   
33 1 ABDALLAH, Hussein
      
34 1 ABDALLAH, Hussein
So we have the 11-checkbits 01100001011, and then the bit-reversed remainder from the division 11010000110=686h. 
35 1 ABDALLAH, Hussein
After that, we put the codeword together for the transmission and we get 686555h which is called Systematic encodein (we can add a parity bit to the codeword to obtain an extended Golay).
36 1 ABDALLAH, Hussein
The encoding algorithm is shown below. Long integers are used to conveniently store one codeword.
37 1 ABDALLAH, Hussein
#define POLY  0xAE3  /* or use the other polynomial, 0xC75 */
38 1 ABDALLAH, Hussein
39 1 ABDALLAH, Hussein
unsigned long golay(unsigned long cw) 
40 1 ABDALLAH, Hussein
41 1 ABDALLAH, Hussein
/* This function calculates [23,12] Golay codewords. 
42 1 ABDALLAH, Hussein
   The format of the returned longint is 
43 1 ABDALLAH, Hussein
   [checkbits(11),data(12)]. */ 
44 1 ABDALLAH, Hussein
45 1 ABDALLAH, Hussein
{ 
46 1 ABDALLAH, Hussein
  int i; 
47 1 ABDALLAH, Hussein
  unsigned long c; 
48 1 ABDALLAH, Hussein
  cw&=0xfffl; 
49 1 ABDALLAH, Hussein
  c=cw; /* save original codeword */ 
50 1 ABDALLAH, Hussein
  for (i=1; i<=12; i++)  /* examine each data bit */ 
51 1 ABDALLAH, Hussein
    { 
52 1 ABDALLAH, Hussein
      if (cw & 1)        /* test data bit */ 
53 1 ABDALLAH, Hussein
        cw^=POLY;        /* XOR polynomial */ 
54 1 ABDALLAH, Hussein
      cw>>=1;            /* shift intermediate result */
55 1 ABDALLAH, Hussein
    } 
56 1 ABDALLAH, Hussein
  return((cw<<12)|c);    /* assemble codeword */ 
57 1 ABDALLAH, Hussein
} 
58 1 ABDALLAH, Hussein
The routine parity() adds the parity bit to complete the extended codeword. It is shown below.
59 1 ABDALLAH, Hussein
int parity(unsigned long cw) 
60 1 ABDALLAH, Hussein
/* This function checks the overall parity of codeword cw.
61 1 ABDALLAH, Hussein
   If parity is even, 0 is returned, else 1. */ 
62 1 ABDALLAH, Hussein
{ 
63 1 ABDALLAH, Hussein
  unsigned char p; 
64 1 ABDALLAH, Hussein
65 1 ABDALLAH, Hussein
  /* XOR the bytes of the codeword */ 
66 1 ABDALLAH, Hussein
  p=*(unsigned char*)&cw; 
67 1 ABDALLAH, Hussein
  p^=*((unsigned char*)&cw+1); 
68 1 ABDALLAH, Hussein
  p^=*((unsigned char*)&cw+2); 
69 1 ABDALLAH, Hussein
70 1 ABDALLAH, Hussein
  /* XOR the halves of the intermediate result */ 
71 1 ABDALLAH, Hussein
  p=p ^ (p>>4); 
72 1 ABDALLAH, Hussein
  p=p ^ (p>>2); 
73 1 ABDALLAH, Hussein
  p=p ^ (p>>1); 
74 1 ABDALLAH, Hussein
75 1 ABDALLAH, Hussein
  /* return the parity result */ 
76 1 ABDALLAH, Hussein
  return(p & 1); 
77 1 ABDALLAH, Hussein
}