In my previous post, I talked about the coding used by the S-NET cubesats and the implementation of my decoder included in gr-satellites. The decoder was still missing a BCH decoder. I have now implemented a BCH decoder and included it in gr-satellites. Here I describe the details of this decoder.

Although I already had a BCH decoder in C that Walter Frese kindly sent me, I have decided to implement my own in Python. The problem with several FEC decoders is that their licensing is not very clear. They originally come from textbook examples that get passed on and modified. For instance, several of the decoders available online for BCH and other codes are based on Robert Morelos-Zaragoza's implementations, whose licence prohibits commercial use. Thus, to keep licensing clean, I implemented my own decoder. In doing so, I have also learned the details of the decoding algorithm.

My BCH decoder has been made with simplicity in mind. The code is brief and simple to understand. Its performance (in terms of decoding speed) could be optimized, but performance is not very important for low bitrate telemetry decoding. The decoder implementation can be found here.

S-NET uses three related BCH codes: BCH(15,11,3), BCH(15,7,5) and BCH(15,5,7). These are cyclic codes over that are constructed with the help of the finite field . The only difference between the three codes is the choice of the generator polynomial.

BCH decoding is very well explained in the Wikipedia BCH page, so I've followed that closely. The decoding procedure uses arithmetic in . I have implemented multiplication and inversion by using exponential and logarithm tables, which have been calculated in Sage.

The received word is represented as the polynomial . Note that here the first element of the codeword represents the independent term of the polynomial. This is the convention used in S-NET, but the mapping between codewords and polynomials can also be done in the opposite order.

Syndrome calculation is easy to do by using the exponential table. Since the syndromes are , they can be computed by summing up some powers of . Here is the primitive element of that we have used to construct our exponential and logarithm tables. Note that, from the point of view of the decoder, the only difference between the three codes BCH(15,11,3), BCH(15,7,5) and BCH(15,5,7) is the number of syndromes that are calculated (2, 4 and 6 respectively).

The next step in the decoding algorithm is to calculate the coefficients of the error locator polynomial. I have used the Peterson–Gorenstein–Zierler algorithm, as described in Wikipedia. This involves solving a linear system with coefficients in . The matrix of this system is a square matrix of size 1, 2 or 3, depending on the number of syndromes.

To solve this system, I use Cramer's rule. The determinants are computed by Sarrus' rule. Since the matrix is small, it is not difficult to write all the calculations explicitly by hand. This step could be optimized, but is is easy and clear to do it in this way.

After having computed the coefficients of the error locator polynomial , I calculate its roots by brute-force search, by computing for . This is done again by using the exponential table. This step can be optimized by using Chien search, but this is not so important, because we only have to try 15 possible roots and has degree at most 3, so even the naïve computation is fast.

Since the roots of indicate the positions of the errors, the final decoding step is to flip the erroneous bits.