ldpcDecode

Decode binary LDPC code

Since R2021b

Syntax

``[Y,actualnumiter,finalparitychecks] = ldpcDecode(llr,decodercfg,maxnumiter)``
``[Y,actualnumiter,finalparitychecks] = ldpcDecode(llr,decodercfg,maxnumiter,Name=Value)``

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 additional 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 = [3 6 20]; numframes = 10; ber = comm.ErrorRate; ber2 = comm.ErrorRate; for ii = 1:length(snr) for counter = 1:numframes data = randi([0 1],cfgLDPCEnc.NumInformationBits,1,'int8'); % Transmit and receive with LDPC coding encodedData = ldpcEncode(data,cfgLDPCEnc); modSignal = pskmod(encodedData,M,InputType='bit'); [rxsig, noisevar] = awgn(modSignal,snr(ii)); demodSignal = pskdemod(rxsig,M, ... OutputType='approxllr', ... NoiseVariance=noisevar); rxbits = ldpcDecode(demodSignal,cfgLDPCDec,maxnumiter); errStats = ber(data,rxbits); % Transmit and receive with no LDPC coding noCoding = pskmod(data,M,InputType='bit'); rxNoCoding = awgn(noCoding,snr(ii)); rxBitsNoCoding = pskdemod(rxNoCoding,M,OutputType='bit'); 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)) reset(ber); reset(ber2); end```
```SNR = 3 Coded: Error rate = 0.07, Number of errors = 355 ```
```Noncoded: Error rate = 0.08, Number of errors = 384 ```
```SNR = 6 Coded: Error rate = 0.00, Number of errors = 0 ```
```Noncoded: Error rate = 0.02, Number of errors = 98 ```
```SNR = 20 Coded: Error rate = 0.00, Number of errors = 0 ```
```Noncoded: Error rate = 0.00, Number of errors = 0 ```

Transmit an LDPC-encoded, QPSK-modulated bit stream through an AWGN channel. After adding AWGN, demodulate the received signal and use the `ldpcDecode` function to decode a `gpuArray` input signal. Compute the error statistics for the belief propagation decoding algorithm and the normalized min-sum decoding algorithm. For more information about GPU processing, see Accelerate Simulation Using GPUs.

Create an LDPC encoder configuration object and an LDPC decoder configuration object. Define simulation variables.

```% Use ldpcQuasiCyclicMatrix to create a parity-check matrix load("LDPCExamplePrototypeMatrix.mat","P"); % A prototype matrix from the 5G standard blockSize = 384; H = ldpcQuasiCyclicMatrix(blockSize, P); encoderCfg = ldpcEncoderConfig(H); decoderCfg1 = ldpcDecoderConfig(encoderCfg); % The default algorithm is "bp" decoderCfg2 = ldpcDecoderConfig(encoderCfg,"norm-min-sum"); M = 4; % Modulation order (QPSK) snr = [-2 -1.5 -1]; numFramesPerCall = 50; numCalls = 40; maxNumIter = 20; s = rng(1235); % Fix random seed errRate = zeros(length(snr),2);```

For each SNR setting, compute the error statistics for the belief propagation decoding algorithm and the normalized min-sum decoding algorithm.

```for ii = 1:length(snr) ttlErr = [0 0]; noiseVariance = 1/10^(snr(ii)/10); for counter = 1:numCalls data = logical(randi([0 1],encoderCfg.NumInformationBits,numFramesPerCall)); % Transmit and receive LDPC coded signal data encData = ldpcEncode(data,encoderCfg); modSig = pskmod(encData,M,pi/4,'InputType','bit'); rxSig = awgn(modSig,snr(ii),'measured'); demodSig = gpuArray(pskdemod(rxSig,M,pi/4,... 'OutputType','approxllr','NoiseVariance',noiseVariance)); % Decode and update number of bit errors % Using bp rxBits1 = ldpcDecode(demodSig,decoderCfg1,maxNumIter); numErr1 = biterr(data,rxBits1); % Using norm-min-sum rxBits2 = ldpcDecode(demodSig,decoderCfg2,maxNumIter); numErr2 = biterr(data,rxBits2); ttlErr = ttlErr + [numErr1 numErr2]; end ttlBits = numCalls*numel(rxBits1); errRate(ii,:) = ttlErr/ttlBits; end```

Bit Error Rate Comparison

Plot the error statistics. The belief propagation algorithm is expected to achieve a slightly lower bit error rate than the normalized min-sum algorithm.

```plot(snr,errRate,'-x') grid on legend('bp','norm-min-sum') xlabel('SNR (dB)') ylabel('BER')```

Speed Comparison

Compare the execution speeds of four cases. By default, `ldpcDecode` terminates decoding when all parity checks are satisfied.

```% Use belief propagation algorithm on CPU, without multithreading demodSigCPU = gather(demodSig); tic [rxBitsCPU1,actualNumIterCPU1,finalParityChecksCPU1] = ... ldpcDecode(demodSigCPU,decoderCfg1,maxNumIter,'Multithreaded',false); toc```
```Elapsed time is 5.517192 seconds. ```
```% Use belief propagation algorithm on CPU, with multithreading tic [rxBitsCPU2,actualNumIterCPU2,finalParityChecksCPU2] = ... ldpcDecode(demodSigCPU,decoderCfg1,maxNumIter); toc```
```Elapsed time is 1.020460 seconds. ```
```% Use belief propagation algorithm on GPU tic [rxBits1,actualNumIter1,finalParityChecks1] = ... ldpcDecode(demodSig,decoderCfg1,maxNumIter); toc```
```Elapsed time is 0.451658 seconds. ```
```% Use normalized min-sum algorithm on GPU tic [rxBits2,actualNumIter2,finalParityChecks2] = ... ldpcDecode(demodSig,decoderCfg2,maxNumIter); toc```
```Elapsed time is 0.074360 seconds. ```

Examine Optional Decoder Outputs

Check that the normalized min-sum algorithm often needs fewer iterations than the belief propagation algorithm when the SNR is sufficiently high.

`length(find(actualNumIter2 < actualNumIter1))`
```ans = 50 ```
`length(find(actualNumIter2 == actualNumIter1))`
```ans = 0 ```

Check that the final parity checks are all zeros when the actual number of iterations executed is less than the maximum number of iterations specified.

`nnz(finalParityChecks1(:,actualNumIter1<maxNumIter))`
```ans = 0 ```
`nnz(finalParityChecks2(:,actualNumIter2<maxNumIter))`
```ans = 0 ```

Restore the state for random number generation.

`rng(s);`

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: `double` | `single`

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 `NumInformationBits`property 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`.

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.

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'`.

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'`.

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.

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. If in MATLAB interpreted mode with `Multithreaded=true`, the decoding algorithm is executed with multiple threads on the CPU. This name-value argument is ignored if input `llr` is a `gpuArray` (Parallel Computing Toolbox) object.

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.

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].

For transmitted LDPC-encoded codeword c = c0, c1, …, cn-1, the input to the LDPC decoder is the log-likelihood ratio (LLR) value .

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

$L\left({r}_{ji}\right)=2\text{\hspace{0.17em}}\text{atanh}\text{\hspace{0.17em}}\left(\prod _{{i}^{\prime }\in {V}_{j}\i}\mathrm{tanh}\left(\frac{1}{2}L\left({q}_{{i}^{\prime }j}\right)\right)\right)$,

$L\left({q}_{ij}\right)=L\left({c}_{i}\right)+\sum _{{j}^{\prime }\in {C}_{i}\j}L\left({r}_{{j}^{\prime }i}\right)$, initialized as $L\left({q}_{ij}\right)=L\left({c}_{i}\right)$ before the first iteration, and

$L\left({Q}_{i}\right)=L\left({c}_{i}\right)+\sum _{{j}^{\prime }\in {C}_{i}}L\left({r}_{{j}^{\prime }i}\right)$.

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 ${C}_{i}\j$ and ${V}_{j}\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.

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\left({q}_{mj}\right)=L\left({q}_{j}\right)-{R}_{mj}$,

(2) ,

(3) ,

(4) ${R}_{mj}=-{s}_{mj}\text{ψ}\left({A}_{mj}\right)$, and

(5) $L\left({q}_{j}\right)=L\left({q}_{mj}\right)+{R}_{mj}$.

For each layer, the decoding equation (5) works on the combined input obtained from the current LLR inputs $L\left({q}_{mj}\right)$ and the previous layer updates ${R}_{mj}$.

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

,

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

,

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™-2020 (Revision of IEEE Std 802.11-2016). "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

Version History

Introduced in R2021b

expand all