heat1q / libldpc

Fast C++17 Simulation Tool for LDPC Codes with Multithreading Support
MIT License
3 stars 2 forks source link

Example to use python encoder/decoder #2

Open FranzForstmayr opened 3 years ago

FranzForstmayr commented 3 years ago

Hi,

I expected to use the encoder/decoder as followed

ldpc = LDPC(...)
x = np.random.randint(0,2, 128) # generate some random bits
enc = ldpc.encode(x)
x_r = ldpc.decode(enc)[0]

The decode method delivers float values, however it's not obvious how to get the decoded bits out of the stream.

Could you please clarify if this is possible?

Thanks! Franz

heat1q commented 3 years ago

Hi, the decode method operates on the actual log-likelihood-ratios (LLRs). In other words, you have to first calculate the LLRs for the input (usually a codeword + some noise). The decoder then outputs the decode LLRs which you can then use for decision making (depending on your channel).

See also:

    def decode(self, llr_in: np.array, early_term=True, iters=50, dec_type="BP") -> np.array:
        """Decode array of input LLRs.
        Args:
            llr_in (np.array): Input LLR, length n (transmitted)
            early_term (bool, optional): Terminate decoding if codeword 
            is valid. Defaults to True.
            iters (int, optional): Number of iterations. Defaults to 50.
            dec_type (str, optional): Type of decoding. See libldpc documentation
            Defaults to "BP".
        Returns:
            np.array: Output LLR, length n (transmitted)
        """
...