Main Content

ldpcDecode

Decode binary LDPC code

Description

The ldpcDecode function decodes the input codeword using one of four algorithms. For more information, see Algorithms. LDPC codes are linear error control codes with sparse parity-check matrices and long block lengths that can attain performance near the Shannon limit.

example

[y,actualnumiter,finalparitychecks] = ldpcDecode(llr,decodercfg,maxnumiter) decodes the input log-likelihood ratio (LLR), llr, using the LDPC matrix specified by the input ldpcDecoderConfig configuration object, decodercfg. A positive LLR indicates that the corresponding bit is more likely a zero. Decoding terminates when all of the parity checks are satisfied, up to a maximum number of iterations specified by the input maxnumiter. LDPC codes are linear error control codes with sparse parity-check matrices and long block lengths that can attain performance near the Shannon limit.

[y,actualnumiter,finalparitychecks] = ldpcDecode(llr,decodercfg,maxnumiter,Name,Value) specifies options using one or more name-value arguments. For example, DecisionType='soft' specifies soft-decision decoding and outputs LLRs.

Examples

collapse all

Initialize parameters for the prototype matrix and block size to configure a rate 3/4 LDPC code specified in IEEE 802.11. Create the parity-check matrix by using the ldpcQuasiCyclicMatrix function.

P = [
    16 17 22 24  9  3 14 -1  4  2  7 -1 26 -1  2 -1 21 -1  1  0 -1 -1 -1 -1
    25 12 12  3  3 26  6 21 -1 15 22 -1 15 -1  4 -1 -1 16 -1  0  0 -1 -1 -1
    25 18 26 16 22 23  9 -1  0 -1  4 -1  4 -1  8 23 11 -1 -1 -1  0  0 -1 -1
     9  7  0  1 17 -1 -1  7  3 -1  3 23 -1 16 -1 -1 21 -1  0 -1 -1  0  0 -1
    24  5 26  7  1 -1 -1 15 24 15 -1  8 -1 13 -1 13 -1 11 -1 -1 -1 -1  0  0
     2  2 19 14 24  1 15 19 -1 21 -1  2 -1 24 -1  3 -1  2  1 -1 -1 -1 -1  0
    ];
blockSize = 27;
pcmatrix = ldpcQuasiCyclicMatrix(blockSize,P);

Create LDPC encoder and decoder configuration objects, displaying their properties.

cfgLDPCEnc = ldpcEncoderConfig(pcmatrix)
cfgLDPCEnc = 
  ldpcEncoderConfig with properties:

     ParityCheckMatrix: [162x648 logical]

   Read-only properties:
           BlockLength: 648
    NumInformationBits: 486
    NumParityCheckBits: 162
              CodeRate: 0.7500

cfgLDPCDec = ldpcDecoderConfig(pcmatrix)
cfgLDPCDec = 
  ldpcDecoderConfig with properties:

     ParityCheckMatrix: [162x648 logical]
             Algorithm: 'bp'

   Read-only properties:
           BlockLength: 648
    NumInformationBits: 486
    NumParityCheckBits: 162
              CodeRate: 0.7500

Transmit an LDPC-encoded, QPSK-modulated bit stream through an AWGN channel. Demodulate the signal, decode the received codewords, and then count bit errors. Use nested for loops to process multiple SNR settings and frames with and without LDPC forward error correction (FEC) coding of the transmitted data.

M = 4;
maxnumiter = 10;
snr = [20 6 3];
numframes = 10;
qpskmod = comm.PSKModulator(M,'BitInput',true);
qpskmod2 = comm.PSKModulator(M);

ber = comm.ErrorRate;
ber2 = comm.ErrorRate;

for ii = 1:length(snr)
    qpskdemod = comm.PSKDemodulator(M,'BitOutput',true, ...
        'DecisionMethod','Approximate log-likelihood ratio', ...
        'Variance',1/10^(snr(ii)/10));
    qpskdemod2 = comm.PSKDemodulator(M);
    for counter = 1:numframes
        data = randi([0 1],cfgLDPCEnc.NumInformationBits,1,'int8');
        % Transmit and receive with LDPC coding
        encodedData = ldpcEncode(data,cfgLDPCEnc);
        modSignal = qpskmod(encodedData);
        receivedSignal = awgn(modSignal,snr(ii));
        demodSignal = qpskdemod(receivedSignal);
        receivedBits = ldpcDecode(demodSignal,cfgLDPCDec,maxnumiter);
        errStats = ber(data,receivedBits);
        % Transmit and receive with no LDPC coding
        noCoding = qpskmod2(data);
        rxNoCoding = awgn(noCoding,snr(ii));
        rxBitsNoCoding = qpskdemod2(rxNoCoding);
        errStatsNoCoding = ber2(data,int8(rxBitsNoCoding));
    end
    fprintf(['SNR = %2d\n   Coded: Error rate = %1.2f, ' ...
        'Number of errors = %d\n'], ...
        snr(ii),errStats(1),errStats(2))
    fprintf(['Noncoded: Error rate = %1.2f, ' ...
        'Number of errors = %d\n'], ...
        errStatsNoCoding(1),errStatsNoCoding(2))
end
SNR = 20
   Coded: Error rate = 0.00, Number of errors = 0
Noncoded: Error rate = 0.00, Number of errors = 0
SNR =  6
   Coded: Error rate = 0.00, Number of errors = 0
Noncoded: Error rate = 0.02, Number of errors = 196
SNR =  3
   Coded: Error rate = 0.02, Number of errors = 353
Noncoded: Error rate = 0.07, Number of errors = 976

Input Arguments

collapse all

Log-likelihood ratios, specified as a matrix with the number of rows equal to the BlockLength property of the input decodercfg. Each column of llr corresponds to a codeword. The function decodes each column independently. A positive LLR indicates that the corresponding bit is more likely a zero.

Data Types: single | double

LDPC decoder configuration, specified as an ldpcDecoderConfig object.

Maximum number of decoding iterations, specified as a positive scalar.

Data Types: double

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: Termination='max'

Output format, specified as one of these values:

  • 'info' — Output only the decoded information bits. The number of rows that the function outputs equals the NumInformationBitsproperty for the input decodercfg.

  • 'whole' — Output all of the decoded LDPC codeword bits, including information bits and parity-check bits. The number of rows that the function outputs equals the BlockLength property for the input decodercfg.

Data Types: char | string

Decision type for LDPC decoding, specified as one of these values:

  • 'hard' — Perform hard-decision decoding and output decoded bits as values of int8 data type.

  • 'soft' — Perform soft-decision decoding and output LLRs with the same data type as the input.

Data Types: char | string

Scaling factor for the normalized min-sum decoding algorithm, specified as a scalar in the range (0, 1]. For more information, see Normalized Min-Sum Decoding.

Dependencies

To enable this property, set the Algorithm property of the input decodercfg to 'norm-min-sum'.

Data Types: double

Offset for the min-sum decoding algorithm, specified as a scalar. For more information, see Offset Min-Sum Decoding.

Dependencies

To enable this property, set the Algorithm property of the input decodercfg to 'offset-min-sum'.

Data Types: double

Decoding termination criteria, specified as one of these values:

  • 'early' — Terminate decoding iterations when all of the parity checks are satisfied, up to a maximum number of iterations specified by input maxnumiter.

  • 'max' — Terminate decoding when the maximum number of iterations, maxnumiter, are complete.

Data Types: char | string

Enable multithreaded execution, specified as a logical 1 (true) or 0 (false). When you run MATLAB® in interpreted mode and set this argument to true, the function executes the decoding algorithm with multiple threads.

Tip

For large parity-check matrices, multithreaded execution significantly reduces the processing time for LDPC decoding.

Dependencies

To enable this property, run MATLAB in interpreted mode.

Output Arguments

collapse all

Decoded codewords, returned as a matrix with K rows that represent the decoded bits for llr(1:K,:). K equals the NumInformationBits property of the input decodercfg. For the decoding operation, each column of llr corresponds to a codeword. The function decodes each column independently. The 'OutputFormat' name-value argument specifies whether the output contains decoded information bits (default) or whole LDPC codeword bits. The 'DecisionType' name-value argument specifies and determines the decoding decision type and the data type of this output.

For more information, see Algorithms.

Data Types: int8 | double | single

Actual number of decoding iterations, returned as a row vector. If all of the parity checks for a codeword are satisfied, decoding can stop before the maximum number of iterations, maxnumiter, is reached. This output is a row vector of the actual number of iterations that the function executes for the codewords.

Data Types: double

Final parity checks for each codeword, returned as a matrix with the number of rows equal to the ParityCheckBits property of input decodercfg. For the decoding operation, each column of this output is the final parity checks for the corresponding codeword.

Data Types: double

Algorithms

collapse all

LDPC decoding using one of these message-passing algorithms.

Belief Propagation Decoding

The implementation of the belief propagation algorithm is based on the decoding algorithm presented by Gallager [2].

Block diagram of the belief propagation algorithm.

For transmitted LDPC-encoded codeword c = c0, c1, …, cn-1, the input to the LDPC decoder is the log-likelihood ratio (LLR) value L(ci)=log(Pr(ci=0|channel output for ci)Pr(ci=1|channel output for ci)).

In each iteration, the key components of the algorithm are updated based on these equations:

L(rji)=2atanh(iVj\itanh(12L(qij))),

L(qij)=L(ci)+jCi\jL(rji), initialized as L(qij)=L(ci) before the first iteration, and

L(Qi)=L(ci)+jCiL(rji).

At the end of each iteration, L(Qi) contains the updated estimate of the LLR value for transmitted bit ci. The value L(Qi) is the soft-decision output for ci. If L(Qi) < 0, the hard-decision output for ci is 1. Otherwise, the hard-decision output for ci is 0.

If decoding is configured to stop when all of the parity checks are satisfied, the algorithm verifies the parity-check equation (H c' = 0) at the end of each iteration. When all of the parity checks are satisfied, or if the maximum number of iterations is reached, decoding stops.

Index sets Ci\j and Vj\i are based on the parity-check matrix (PCM). Index sets Ci and Vj correspond to all nonzero elements in column i and row j of the PCM, respectively.

This figure shows the computation of these index sets in a given PCM for i = 5 and j = 3.

Computation of C and V index sets for a given parity-check matrix.

To avoid infinite numbers in the algorithm equations, atanh(1) and atanh(–1) are set to 19.07 and –19.07, respectively. Due to finite precision, MATLAB returns 1 for tanh(19.07) and –1 for tanh(-19.07).

Layered Belief Propagation Decoding

The implementation of the layered belief propagation algorithm is based on the decoding algorithm presented in Hocevar [3], Section II.A. The decoding loop iterates over subsets of rows (layers) of the PCM. For each row, m, in a layer and each bit index, j, the implementation updates the key components of the algorithm based on these equations:

(1) L(qmj)=L(qj)Rmj,

(2) Amj=n  N(m)njψ(L(qmn)),

(3) smj=n  N(m)njsign(L(qmn)),

(4) Rmj=smjψ(Amj), and

(5) L(qj)=L(qmj)+Rmj.

For each layer, the decoding equation (5) works on the combined input obtained from the current LLR inputs L(qmj) and the previous layer updates Rmj.

Because only a subset of the nodes is updated in a layer, the layered belief propagation algorithm is faster compared to the belief propagation algorithm. To achieve the same error rate as attained with belief propagation decoding, use half the number of decoding iterations when you use the layered belief propagation algorithm.

Normalized Min-Sum Decoding

The implementation of the normalized min-sum decoding algorithm follows the layered belief propagation algorithm with equation (2) replaced by

Amj=minn  N(m)nj(|L(qmn) |α),

where α is in the range (0, 1] and is the scaling factor specified by the MinSumScalingFactor input argument to the ldpcDecode function. This equation is an adaptation of equation (4) presented in Chen [4].

Offset Min-Sum Decoding

The implementation of the offset min-sum decoding algorithm follows the layered belief propagation algorithm with equation (2) replaced by

Amj =  max(minn  N(m)nj (|L(qmn)| β), 0),

where β ≥ 0 and is the offset specified by the MinSumOffset input argument to the ldpcDecode function. This equation is an adaptation of equation (5) presented in Chen [4].

References

[1] IEEE Std 802.11™-2016 (Revision of IEEE Std 802.11-2012). "Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications." IEEE Standard for Information technology — Telecommunications and information exchange between systems. Local and metropolitan area networks — Specific requirements.

[2] Gallager, Robert G. Low-Density Parity-Check Codes. Cambridge, MA: MIT Press, 1963.

[3] Hocevar, D.E. "A reduced complexity decoder architecture via layered decoding of LDPC codes." In IEEE Workshop on Signal Processing Systems, 2004. SIPS 2004. doi: 10.1109/SIPS.2004.1363033

[4] Chen, Jinghu, R.M. Tanner, C. Jones, and Yan Li. "Improved min-sum decoding algorithms for irregular LDPC codes." In Proceedings. International Symposium on Information Theory, 2005. ISIT 2005. doi: 10.1109/ISIT.2005.1523374

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2021b