# comm.BCHDecoder System object

Package: comm

Decode data using BCH decoder

## Description

The `BCHDecoder` object recovers a binary message vector from a binary BCH codeword vector. For proper decoding, the codeword and message length values in this object must match the properties in the corresponding `comm.BCHEncoder` System object™.

To decode a binary message from a BCH codeword:

1. Define and set up your BCH decoder object. See Construction.

2. Call `step` to recover a binary message vector from a binary BCH codeword vector according to the properties of `comm.BCHDecoder`. The behavior of `step` is specific to each object in the toolbox.

## Construction

`dec = comm.BCHDecoder` creates a BCH decoder System object, `dec`, that performs BCH decoding.

`dec = comm.BCHDecoder(N,K)` creates a BCH decoder object, `dec`, with the `CodewordLength` property set to `N` and the `MessageLength` property set to `K`.

`dec = comm.BCHDecoder(N,K,GP)` creates a BCH decoder object, `dec`, with the `CodewordLength` property set to `N`, the `MessageLength` property set to `K`, and the `GeneratorPolynomial` property set to `GP`.

`dec = comm.BCHDecoder(N,K,GP,S)` creates a BCH decoder object, `dec`, with the `CodewordLength` property set to `N`, the `MessageLength` property set to `K`, the `GeneratorPolynomial` property set to `GP`, and the `ShortMessageLength` property set to `S`.

`dec = comm.BCHDecoder(N,K,GP,S,Name,Value)` creates a BCH decoder object, `dec`, with the `CodewordLength` property set to `N`, the `MessageLength` property set to `K`, the `GeneratorPolynomial` property set to `GP`, the `ShortMessageLength` property set to `S`, and each specified property `Name` set to the specified `Value`.

`dec = comm.BCHDecoder(Name,Value)` creates a BCH decoder object, `dec`, with each specified property set to the specified value. You can specify additional name-value pair arguments in any order as (`Name1`,`Value1`,...,`NameN`,`ValueN`).

## Properties

 `CodewordLength` Codeword length Specify the codeword length of the BCH code as a double-precision positive integer scalar. The default is `15`. The values of the `CodewordLength` and `MessageLength` properties must produce a valid narrow-sense BCH code. For a full-length BCH code, the value of this property must take the form ${2}^{M}-1$, where M is an integer such that $3\le M\le 16$. The default is `15`. `MessageLength` Message length Specify the message length as a double-precision positive integer scalar. The values of the `CodewordLength` and `MessageLength` properties must produce a valid narrow-sense BCH code. The default is `5`. `ShortMessageLengthSource` Short message length source Specify the source of the shortened message as either `Auto` or `Property`. When this property is set to `Auto`, the BCH code is defined by the `CodewordLength`, `MessageLength`, `GeneratorPolynomial`, and `PrimitivePolynomial` properties. When `ShortMessageLengthSource` is set to `Property`, you must specify the `ShortMessageLength` property, which is used with the other properties to define the BCH code. The default is `Auto`. `ShortMessageLength` Shortened message length Specify the length of the shortened message as a double-precision positive integer scalar whose value must be less than or equal to `MessageLength`. When `ShortMessageLength` < `MessageLength`, the BCH code is shortened. The default is `5`. `GeneratorPolynomialSource` Source of generator polynomial Specify the source of the generator polynomial as either `Auto` or `Property`. Set this property to `Auto` to create the generator polynomial automatically. Set `GeneratorPolynomialSource` to `Property` to specify a generator polynomial using the `GeneratorPolynomial`  property. The default is `Auto`. `GeneratorPolynomial` Generator polynomial Specify the generator polynomial for encoding as a binary, double-precision, row vector or as a binary Galois field row vector that represents the coefficients of the generator polynomial in order of descending powers. The length of the generator polynomial requires a value of `CodewordLength`–`MessageLength`+`1`. This property applies when you set `GeneratorPolynomialSource` to `Property`. The default is the result of `bchgenpoly`(`(15,5,[],'double')`), which corresponds to a `15,5` code. `CheckGeneratorPolynomial` Enable generator polynomial checking Set this property to `true` to perform a generator polynomial check the first time you call the `step` method. The default is `true`. This check verifies that the specified generator polynomial is valid. For larger codes, disabling the check reduces processing time. As a best practice, perform the check at least once before setting this property to `false`. This property applies when you set `GeneratorPolynomialSource` to `Property`. The default is `true`. `PrimitivePolynomialSource` Source of primitive polynomial Specify the source of the primitive polynomial as `Auto` or `Property`. Set this property to `Auto` to create a primitive polynomial of degree M=`ceil(log2(CodewordLength+1))`. Set `PrimitivePolynomialSource` to `Property` to specify a polynomial using the `PrimitivePolynomial` property. The default is `Auto`. `PrimitivePolynomial` Primitive polynomial Specify the primitive polynomial of order M, that defines the finite Galois field GF(2). Use a double-precision, binary row vector with the coefficients of the polynomial in order of descending powers. This property applies when you set the `PrimitivePolynomialSource` property to `Property`. The default is `fliplr(de2bi(primpoly(4))) = [1 0 0 1 1]`, which corresponds to the polynomial ${x}^{4}+x+1$. `PuncturePatternSource` Source of puncture pattern Specify the source of the puncture pattern as `None` or `Property`. Set this property to `None` to disable puncturing. Set it to `Property` to decode punctured codewords. This decoding is based on a puncture pattern vector you specify in the `PuncturePattern` property. The default is `None`. `PuncturePattern` Puncture pattern vector Specify the pattern that the object uses to puncture the encoded data. Use a double-precision binary column vector of length `CodewordLength`–`MessageLength`. Zeros in the puncture pattern vector indicate the position of the parity bits that the object punctures or excludes from each codeword. This property applies when you set `PuncturePatternSource` to `Property`. The default is `[ones(8,1); zeros(2,1)]`. `ErasuresInputPort` Enable erasures input Set this property to `true` to specify a vector of erasures as a `step` method input. The erasures vector is a double-precision or logical binary column vector that indicates which bits of the input codewords to erase or ignore. Values of `1` in the erasures vector correspond to erased bits in the same position of the (possibly punctured) input codewords. Set this property to `false` to disable erasures. The default is `false`. `NumCorrectedErrorsOutputPort` Output number of corrected errors Set this property to `true` so that the `step` method outputs the number of corrected errors. The default is `true`.

## Input and Output Signal Lengths in BCH and RS System Objects

The notation `y = c * x` denotes that `y` is an integer multiple of `x`.

The number of punctures equals the number of zeros in the puncture vector.

M is the degree of the primitive polynomial. Each group of M bits represents an integer between `0` and `2M–1` that belongs to the finite Galois field `GF(2M)`.

ShortMessageLengthSource

`comm.BCHEncoder`

```comm.RSEncoder (BitInput = false)```

`comm.BCHDecoder`

```comm.RSDecoder (BitInput = false)```

```comm.RSEncoder (BitInput = true)```

```comm.RSDecoder (BitInput = true)```

Auto

`Input Length:`

```c * MessageLength```

```Output Length:```

```c * ( CodewordLength – number of punctures) ```

`Input Length: `

```c * (CodewordLength – number of punctures) ```

`Output Length: `

```c * MessageLength```

```Erasures Length: ```

```c * ( CodewordLength – number of punctures)```

`Input Length:`

```c * (MessageLength * M)```

```Output Length:```

```c * (( CodewordLength – number of punctures) * M)```

`Input Length: `

```c * ( (CodewordLength – number of punctures) * M)```

`Output Length:`

```c * (MessageLength * M)```

```Erasures Length: ```

c * (CodewordLength – number of punctures)

Property

`Input Length: `

```c * ShortMessageLength```

```Output Length:```

```c * (CodewordLength - MessageLength + ShortMessageLength - number of punctures)```

`Input Length: `

```c * (CodewordLength - MessageLength + ShortMessageLength - number of punctures)```

```Output Length:```

`c * ShortMessageLength`

`Erasures Length:`

```c * (CodewordLength - MessageLength + ShortMessageLength - number of punctures)```

`Input Length: `

```c * (ShortMessageLength * M)```

```Output Length:```

```c * ( (CodewordLength - MessageLength + ShortMessageLength - number of punctures) * M)```

`Input Length: `

```c * ((CodewordLength - MessageLength + ShortMessageLength - number of punctures) * M)```

```Output Length:```

```c * (ShortMessageLength * M)```

```Erasures Length:```

```c * (CodewordLength - MessageLength + ShortMessageLength - number of punctures) ```

## Methods

 clone Create BCH decoder object with same property values getNumInputs Number of expected inputs to step method getNumOutputs Number of outputs from step method isLocked Locked status for input attributes and nontunable properties release Allow property value and input characteristics changes step Decode data using a BCH decoder

## Examples

collapse all

### Transmit and decode an 8-DPSK-modulated signal, then count errors

```% The following code transmits a BCH-encoded, 8-DPSK-modulated bit stream % through an AWGN channel. Then, the example demodulates, decodes, and counts errors. enc = comm.BCHEncoder; mod = comm.DPSKModulator('BitInput',true); chan = comm.AWGNChannel(... 'NoiseMethod','Signal to noise ratio (SNR)','SNR',10); demod = comm.DPSKDemodulator('BitOutput',true); dec = comm.BCHDecoder; errorRate = comm.ErrorRate('ComputationDelay',3); for counter = 1:20 data = randi([0 1], 30, 1); encodedData = step(enc, data); modSignal = step(mod, encodedData); receivedSignal = step(chan, modSignal); demodSignal = step(demod, receivedSignal); receivedBits = step(dec, demodSignal); errorStats = step(errorRate, data, receivedBits); end fprintf('Error rate = %f\nNumber of errors = %d\n', ... errorStats(1), errorStats(2)) ```
```Error rate = 0.015075 Number of errors = 9 ```

### Transmit and receive a BPSK-modulated signal

Transmit and receive a BPSK-modulated signal encoded with a shortened BCH code, then count errors.

```N = 255; K = 239; S = 63; gp = bchgenpoly(255,239); enc = comm.BCHEncoder(N, K, gp, S); % BCH code in AMR standard mod = comm.BPSKModulator; chan = comm.AWGNChannel(... 'NoiseMethod','Signal to noise ratio (SNR)','SNR', 5); demod = comm.BPSKDemodulator; dec = comm.BCHDecoder(N, K, gp, S); errorRate = comm.ErrorRate('ComputationDelay',3); for counter = 1:20 data = randi([0 1], 630, 1); encodedData = step(enc, data); modSignal = step(mod, encodedData); receivedSignal = step(chan, modSignal); demodSignal = step(demod, receivedSignal); receivedBits = step(dec, demodSignal); errorStats = step(errorRate, data, receivedBits); end fprintf('Error rate = %f\nNumber of errors = %d\n', ... errorStats(1), errorStats(2)) ```
```Error rate = 0.000318 Number of errors = 4 ```

## Algorithms

This object implements the algorithm, inputs, and outputs described in Algorithms for BCH and RS Errors-only Decoding.

## Selected Bibliography

[1] Clark, George C. Jr., and J. Bibb Cain, Error-Correction Coding for Digital Communications. New York, Plenum Press, 1981.

[2] Wicker, Stephen B., Error Control Systems for Digital Communication and Storage Upper Saddle River, NJ, Prentice Hall, 1995.