Golay Code Implementation – Encoding » History » Version 3

ABDALLAH, Hussein, 03/13/2016 12:14 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 3 ABDALLAH, Hussein
                                               
12 3 ABDALLAH, Hussein
      Golay polynomial    info bits   zero fill                        
13 1 ABDALLAH, Hussein
     |----------|  |----------||---------|                       
14 2 ABDALLAH, Hussein
      AE3h            _555h(reversed)                      
15 1 ABDALLAH, Hussein
     101011100011 )10101010101000000000000   (11 zeros)                    
16 1 ABDALLAH, Hussein
                   101011100011  (AE3h)                                
17 1 ABDALLAH, Hussein
                   ------------ <---------- Exclusive-OR         
18 1 ABDALLAH, Hussein
                        100100100000                             
19 1 ABDALLAH, Hussein
                        101011100011                             
20 1 ABDALLAH, Hussein
                        ------------                             
21 1 ABDALLAH, Hussein
                          111100001100                           
22 1 ABDALLAH, Hussein
                          101011100011                           
23 1 ABDALLAH, Hussein
                          ------------                           
24 1 ABDALLAH, Hussein
                           101111011110                          
25 1 ABDALLAH, Hussein
                           101011100011                          
26 1 ABDALLAH, Hussein
                           ------------                          
27 1 ABDALLAH, Hussein
                              100111101000                       
28 1 ABDALLAH, Hussein
                              101011100011                       
29 1 ABDALLAH, Hussein
                              ------------                       
30 1 ABDALLAH, Hussein
                               01100001011 <-- checkbits   
31 1 ABDALLAH, Hussein
      
32 1 ABDALLAH, Hussein
So we have the 11-checkbits 01100001011, and then the bit-reversed remainder from the division 11010000110=686h. 
33 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).
34 1 ABDALLAH, Hussein
The encoding algorithm is shown below. Long integers are used to conveniently store one codeword.
35 1 ABDALLAH, Hussein
#define POLY  0xAE3  /* or use the other polynomial, 0xC75 */
36 1 ABDALLAH, Hussein
37 1 ABDALLAH, Hussein
unsigned long golay(unsigned long cw) 
38 1 ABDALLAH, Hussein
39 1 ABDALLAH, Hussein
/* This function calculates [23,12] Golay codewords. 
40 1 ABDALLAH, Hussein
   The format of the returned longint is 
41 1 ABDALLAH, Hussein
   [checkbits(11),data(12)]. */ 
42 1 ABDALLAH, Hussein
43 1 ABDALLAH, Hussein
{ 
44 1 ABDALLAH, Hussein
  int i; 
45 1 ABDALLAH, Hussein
  unsigned long c; 
46 1 ABDALLAH, Hussein
  cw&=0xfffl; 
47 1 ABDALLAH, Hussein
  c=cw; /* save original codeword */ 
48 1 ABDALLAH, Hussein
  for (i=1; i<=12; i++)  /* examine each data bit */ 
49 1 ABDALLAH, Hussein
    { 
50 1 ABDALLAH, Hussein
      if (cw & 1)        /* test data bit */ 
51 1 ABDALLAH, Hussein
        cw^=POLY;        /* XOR polynomial */ 
52 1 ABDALLAH, Hussein
      cw>>=1;            /* shift intermediate result */
53 1 ABDALLAH, Hussein
    } 
54 1 ABDALLAH, Hussein
  return((cw<<12)|c);    /* assemble codeword */ 
55 1 ABDALLAH, Hussein
} 
56 1 ABDALLAH, Hussein
The routine parity() adds the parity bit to complete the extended codeword. It is shown below.
57 1 ABDALLAH, Hussein
int parity(unsigned long cw) 
58 1 ABDALLAH, Hussein
/* This function checks the overall parity of codeword cw.
59 1 ABDALLAH, Hussein
   If parity is even, 0 is returned, else 1. */ 
60 1 ABDALLAH, Hussein
{ 
61 1 ABDALLAH, Hussein
  unsigned char p; 
62 1 ABDALLAH, Hussein
63 1 ABDALLAH, Hussein
  /* XOR the bytes of the codeword */ 
64 1 ABDALLAH, Hussein
  p=*(unsigned char*)&cw; 
65 1 ABDALLAH, Hussein
  p^=*((unsigned char*)&cw+1); 
66 1 ABDALLAH, Hussein
  p^=*((unsigned char*)&cw+2); 
67 1 ABDALLAH, Hussein
68 1 ABDALLAH, Hussein
  /* XOR the halves of the intermediate result */ 
69 1 ABDALLAH, Hussein
  p=p ^ (p>>4); 
70 1 ABDALLAH, Hussein
  p=p ^ (p>>2); 
71 1 ABDALLAH, Hussein
  p=p ^ (p>>1); 
72 1 ABDALLAH, Hussein
73 1 ABDALLAH, Hussein
  /* return the parity result */ 
74 1 ABDALLAH, Hussein
  return(p & 1); 
75 1 ABDALLAH, Hussein
}