# nrCRCEncode

Calculate and append cyclic redundancy check (CRC)

## Syntax

``blkcrc = nrCRCEncode(blk,poly)``
``blkcrc = nrCRCEncode(blk,poly,mask)``

## Description

example

````blkcrc = nrCRCEncode(blk,poly)` calculates the CRC defined by the polynomial `poly` for the input data `blk`. The function returns the CRC encoded data, which is a copy of the input data with the CRC parity bits appended. For details on the associated polynomials, see TS 38.212 Section 5.1 [1].```

example

````blkcrc = nrCRCEncode(blk,poly,mask)` applies a logical difference (XOR) mask on the appended CRC bits with the integral value of `mask`. The appended CRC bits in `blkcrc` are XOR-masked with the most significant bit (MSB) first to the least significant bit (LSB) last. The masked CRC is of the form (`p0` xor `m0`), (`p1` xor `m1`),…, (`pL-1` xor `mL-1`), where `L` is the number of parity bits, and `p0` and `m0` are the MSBs in the binary representation of CRC and `mask`, respectively. If the mask value is greater than 2`L` - 1, the `L` LSBs are considered for the mask. ```

## Examples

collapse all

Calculate and append CRC parity bits to an all-zeros matrix of two data blocks. The result is an all-zeros matrix of size 124-by-2.

```blkcrc = nrCRCEncode(zeros(100,2),'24C'); any(blkcrc(:,1:2));```

Calculate and append masked CRC parity bits to an all-zeros matrix of two data blocks. The appended CRC bits are XOR-masked with the specified `mask`, from the MSB first to the LSB last. The result is an all-zeros matrix apart from the elements in the last position.

```mask = 1; blkcrc = nrCRCEncode(zeros(100,2),'24C',mask); blkcrc(end-5:end,1:2)```
```ans = 6×2 0 0 0 0 0 0 0 0 0 0 1 1 ```

## Input Arguments

collapse all

Input data, specified as a matrix of real numbers. Each column of the matrix is treated as a separate data block.

Data Types: `double` | `int8` | `logical`

CRC polynomial, specified as `'6'`, `'11'`, `'16'`, `'24A'`, `'24B'`, or `'24C'`. For details on the associated polynomials, see TS 38.212 Section 5.1.

Data Types: `char` | `string`

XOR mask, specified as a nonnegative integer. The mask is typically a radio network temporary identifier (RNTI).

Data Types: `double`

## Output Arguments

collapse all

CRC encoded data, returned as a matrix of real numbers. `blkcrc` is a copy of the input `blk` with the CRC parity bits appended. Each column corresponds to a separate CRC encoded code block. `blkcrc` inherits its data type from the input `blk`.

Data Types: `double` | `int8` | `logical`

## References

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

## Extended Capabilities

### C/C++ Code GenerationGenerate C and C++ code using MATLAB® Coder™.

Introduced in R2018b