# LDPCCode LDPCCode offers an interface for LDPC communication codes and implementations of such codes which employ different possible decoding schemes. To learn more about the terminology used here, the reader is advised to read an introduction to Hamming codes to get acquainted with the subject. In this text, the term generator matrix is slightly different from the usual description. We only consider only the P part to be the generator matrix and assume that the identity part I is implicit. The matrix I should thus be left out of any generator matrix used here. ## Code
    template <std::size_t N, std::size_t K>
    class Code;
     std::size_t N
| The number of bits in a codeword. N should always be greater than or equal to K.
     std::size_t K
| The number of bits in a message.
From the given parameters N and K, it follows that the rate of the code is K / N. Additionally, we can deduce the number of parity bits to be N - K. It is adviced, and in some cases required, to select K as a power of two and N as a multiple of K. Any code offers the following interface:
     std::size_t M
| The number of parity checks of the code, defined as N-K.
     typename G
| The type of the generator matrix, short for std::tr1::array<std::bitset<K>, N-K>. A Generator matrix only needs to contain entries for parity checks, the K-by-K Identity matrix can be left out, it will be added automatically. Hence, G contains only N-K vectors in stead of N.
     typename H
| The type of the parity-check matrix, short for std::tr1::array<std::bitset<N>, M>. The parity-check matrix of the code will be automatically derived from the Generator matrix of the code.
     bool encode(const std::bitset<K> &message,
    	    std::bitset<N> &codeword) const
| Produces a codeword for a given a message, returns true when successful.
     bool decode(const std::tr1::array<T, N> &channelOutput,
    	    std::bitset<K> &message)
| Attempts to decode the output of the channel, which should be given in floating point values in the range [0...1]: for each bit, it should represent the probability of that bit to be 1. Depending on the particular subclass of Code that is instanciated, a different decoding algorithm will be employed. If a valid codeword is deduced, the corresponding the message is written and decode returns true. If no valid codeword is found, false is returned and the contents of message are undefined.
     void print() const
| Prints the code's generator and check matrices.
## BPLDPCCode The most commonly used decoding scheme, belief propagation, is implemented in the BPLDPCCode, defined as:
    template <typename T, unsigned N, unsigned K>
    class BPLDPCCode;
Belief propagation is a sub-optimal and numerically unstable but computationally feasible algorithm, and is hence the recommended choice for decoding. BPLDPCCode offers the following constructors:
    BPLDPCCode(const unsigned maxIterations = 1024u)
| This constructor will automatically create a generator matrix and requires K to be a power of two and N to be a multiple of K. The belief propagation algorithm will stop on convergeance, or after maxIterations iterations.
    BPLDPCCode(const G &generator,
    	   const unsigned maxIterations = 1024u)
| The code will be defined by the user-supplied generator matrix generator. The belief propagation algorithm will stop on convergeance, or after maxIterations iterations.
## MLLDPCCode For reference, a maximum-likelihood decoder is implemented in the MLLDPCCode:
    template <typename T, unsigned N, unsigned K>
    class MLLDPCCode;
Although a maximum-likelyhood decoder is stable and will lead to optimal results, the required computation time is likely to exceed any reasonable limits unless N and K are very small. MLLDPCCode offers the following constructors:
    MLLDPCCode()
| This constructor will automatically create a generator matrix and requires K to be a power of two and N to be a multiple of K.
    MLLDPCCode(const G &generator)
| The code will be defined by the user-supplied generator matrix generator.