# nrLDPCDecode

Low-density parity-check (LDPC) decoding

## Syntax

``[out,actNumIter,finalParityChecks] = nrLDPCDecode(in,bgn,maxNumIter)``
``[out,actNumIter,finalParityChecks] = nrLDPCDecode(___,Name,Value)``

## Description

````[out,actNumIter,finalParityChecks] = nrLDPCDecode(in,bgn,maxNumIter)` returns the LDPC-decoded output matrix `out` for the input data matrix `in`, base graph number `bgn`, and maximum number of decoding iterations `maxNumIter`. The function also returns the actual number of iterations `actNumIter` and the final parity checks per codeword `finalParityChecks`.The decoder uses the sum-product message-passing algorithm. The data bits must be LDPC-encoded as defined in TS 38.212 Section 5.3.2 [1].```

example

````[out,actNumIter,finalParityChecks] = nrLDPCDecode(___,Name,Value)` specifies optional name-value pair arguments, in addition to the input arguments in the previous syntax.```

## Examples

collapse all

Create transmit data consisting of two code block segments of length 2560 and 36 filler bits at the end.

```C = 2; K = 2560; F = 36; txcbs = ones(K-F,C); fillers = -1*ones(F,C); txcbs = [txcbs;fillers]; ```

Generate LDPC codeword for the transmit data. Use base graph number two.

```bgn = 2; txcodedcbs = nrLDPCEncode(txcbs,bgn); ```

Convert transmit data to soft bits. Fillers in the transmit data do not have log likelihood ratio (LLR) soft bits.

```rxcodedcbs = double(1-2*txcodedcbs); FillerIndices = find(txcodedcbs(:,1) == -1); rxcodedcbs(FillerIndices,:) = 0; ```

Decode the encoded codeword with a maximum of 25 iterations.

`[rxcbs,actualniters] = nrLDPCDecode(rxcodedcbs,bgn,25); `

Replace filler bits with zero in transmit data and compare the results of encoding and decoding.

```txcbs(end-F+1:end,:) = 0; isequal(rxcbs,txcbs) ```
```ans = logical 1 ```
`actualniters`
```actualniters = 1×2 1 1 ```

## Input Arguments

collapse all

Rate recovered soft bits for input code block segments, specified as a real matrix. The number of columns in `in` is equal to the number of scheduled code block segments. The number of rows in `in` is equal to the length of the codeword, with some systematic bits punctured.

Data Types: `double` | `single`

Base graph number, specified as `1` or `2`. The value selects one of the two base graphs defined in TS 38.212 Section 5.3.2 [1].

Data Types: `double`

Maximum number of decoding iterations, specified as a positive integer scalar. The decoding is terminated when all parity checks are satisfied, or after `maxNumIter` number of iterations.

Data Types: `double`

### Name-Value Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: ```[out,actNumIter,finalParityChecks] = nrLDPCDecode(in,bgn,maxNumIter,'DecisionType','hard')```

Output format, specified as the comma-separated pair consisting of `'OutputFormat'` and one of these values:

• `'info'` — The number of rows in `out` is equal to the length of the information bits.

• `'whole'` — The number of rows in `out` is equal to the length of the codeword.

Data Types: `char` | `string`

Decision method used for decoding, specified as the comma-separated pair consisting of `'DecisionType'` and one of these values:

• `'hard'` — The data type of `out` is `int8`.

• `'soft'` — The output `out` contains log-likelihood ratios of the same data type as `in`.

Data Types: `char` | `string`

LDPC decoding algorithm, specified as the comma-separated pair consisting of `'Algorithm'` and one of these values:

• `'Belief propagation'` — Use this option to specify the belief-passing or message-passing algorithm. For more information, see Belief Propagation Decoding.

• `'Layered belief propagation'` — Use this option to specify the layered belief-passing algorithm, which is suitable for quasi-cyclic parity-check matrices (PCMs). For more information, see Layered Belief Propagation Decoding.

• `'Normalized min-sum'` — Use this option to specify the layered belief propagation algorithm with normalized min-sum approximation. For more information, see Normalized Min-Sum Decoding.

• `'Offset min-sum'` — Use this option to specify the layered belief propagation algorithm with offset min-sum approximation. For more information, see Offset Min-Sum Decoding.

Note

When you specify the value of this name-value pair argument as `'Normalized min-sum'` or `'Offset min-sum'`, the function clips the input (log-likelihood ratio) LLR values to the [-1e10 1e10] range before decoding.

Data Types: `char` | `string`

Scaling factor for normalized min-sum decoding, specified as the comma-separated pair consisting of `'ScalingFactor'` and a real scalar in the range (0, 1].

#### Dependencies

To enable this name-value pair argument, set the `'Algorithm'` name-value pair argument to `'Normalized min-sum'`.

Data Types: `double`

Offset for offset min-sum decoding, specified as the comma-separated pair consisting of `'Offset'` and a nonnegative finite real scalar.

#### Dependencies

To enable this name-value pair argument, set the `'Algorithm'` name-value pair argument to `'Offset min-sum'`.

Data Types: `double`

Decoding termination criteria, specified as the comma-separated pair consisting of `'Termination'` and one of these values:

• `'early'` — The decoding terminates when all parity checks are satisfied or after `maxNumIter` number of iterations.

• `'max'` — The decoding terminates after `maxNumIter` number of iterations.

Data Types: `char` | `string`

## Output Arguments

collapse all

Decoded LDPC codeword or information bits, returned as a real matrix. The number of columns in `out` is equal to the number of scheduled code block segments. The number of rows in `out` depends on the name-value pair argument `'OutputFormat'`. The data type of `out` depends on the name-value pair argument `'DecisionType'`.

Data Types: `single` | `double` | `int8`

Actual number of iterations, returned as a row vector of positive integers. The length of `actNumIter` is equal to the number of columns in `in`. The `i`th element in `actNumIter` corresponds to the actual number of iterations executed for the `i`th column of `in`.

Data Types: `double`

Final parity checks, returned as a matrix. The number of rows in `finalParityChecks` is equal to the number of parity-check bits in an LDPC codeword. The `i`th column in `finalParityChecks` corresponds to the final parity checks for the `i`th codeword.

Data Types: `double`

## Algorithms

collapse all

The `nrLDPCDecode` function supports these four LDPC decoding algorithms.

### Belief Propagation Decoding

The implementation of the belief propagation algorithm is based on the decoding algorithm presented in [2]. For transmitted LDPC-encoded codeword, c, where $c=\left({c}_{0},{c}_{1},...,{c}_{n-1}\right)$, 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\left({Q}_{i}\right)$ is an updated estimate of the LLR value for the transmitted bit ${c}_{i}$. The value $L\left({Q}_{i}\right)$ is the soft-decision output for ${c}_{i}$. If $L\left({Q}_{i}\right)<0$, the hard-decision output for ${c}_{i}$ is 1. Otherwise, the output is 0.

Index sets ${C}_{i}\j$ and ${V}_{j}\i$ are based on the parity-check matrix (PCM). Index sets ${C}_{i}$ and ${V}_{j}$ correspond to all nonzero elements in column i and row j of the PCM, respectively.

This figure highlights 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).

When the name-value pair argument `'Termination'` is set to `'max'`, the decoding terminates after `maxNumIter` number of iterations. When `'Termination'` is set to `'early'`, the decoding terminates when all parity checks are satisfied ($H{c}^{\text{T}}=0$) or after `maxNumIter` number of iterations.

### Layered Belief Propagation Decoding

The implementation of the layered belief propagation algorithm is based on the decoding algorithm presented in [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 using 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 `ScalingFactor`. This equation is an adaptation of equation (4) presented in [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 `Offset`. This equation is an adaptation of equation (5) presented in [4].

## References

[1] 3GPP TS 38.212. “NR; Multiplexing and channel coding.” 3rd Generation Partnership Project; Technical Specification Group Radio Access Network.

[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

Introduced in R2018b