Accelerating the pace of engineering and science

# 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 BCH Encoder block.

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

H = comm.BCHDecoder creates a BCH decoder System object™, H, that performs BCH decoding.

H = comm.BCHDecoder(Name,Value) creates a BCH decoder object, H, 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 the this property must take the form ${2}^{M}-1$.M is an integer, $3\le M\le 16$, that corresponds to the degree of the primitive polynomial that you specify with PrimitivePolynomialSource and PrimitivePolynomial. If the this property is less than ${2}^{M}-1$, the object assumes a shortened code. MessageLength Message length Specify the message length as a double-precision, positive, integer scalar. The default is 5. The values of the CodewordLength and MessageLength properties must produce a valid narrow-sense BCH code. PrimitivePolynomialSource Source of primitive polynomial Specify the source of the primitive polynomial as one of Auto | Property. The default is Auto. When you set this property to Auto, the object uses a primitive polynomial of degree M=ceil(log2(CodewordLength+1)). The result of fliplr(de2bi(primpoly(M))), sets the value for this polynomial. Set this property to Property to specify a polynomial using the PrimitivePolynomial property. PrimitivePolynomial Primitive polynomial Specify the primitive polynomial of order M, that defines the finite Galois field GF(2) as 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$. GeneratorPolynomialSource Source of generator polynomial Specify the source of the generator polynomial as one of Auto | Property. The default is Auto. When you set this property to Auto, the object chooses the generator polynomial automatically. The object calculates the generator polynomial based on the value of the PrimitivePolynomialSource property. When you set the PrimitivePolynomialSource property to Auto the object calculates the generator polynomial as bchgenpoly(CodewordLength+SL,MessageLength+SL). When you set the PrimitivePolynomialSource property to Property, the object computes generator polynomial as bchgenpoly(CodewordLength+SL,MessageLength+SL, PrimitivePolynomial). In both cases, SL = (${2}^{M}-1$)-CodewordLength is the shortened length. and M is the degree of the primitive polynomial that you specify with PrimitivePolynomialSource and PrimitivePolynomial. Set this property to Property to specify a generator polynomial using the GeneratorPolynomial property. GeneratorPolynomial Generator polynomial Specify the generator polynomial 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. You must use CodewordLength–MessageLength+1 as the length of the generator polynomial. This property applies when you set the GeneratorPolynomialSource property to Property. The default is the result of bchgenpoly((15,5,[],'double')), which corresponds to a 15,5 code. When you use this object to generate code, you must set the generator polynomial to a binary, double precision row vector. 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 xCodewordLength + 1 is divisible by the generator polynomial specified in the GeneratorPolynomial property. 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 the GeneratorPolynomialSource property to Property. PuncturePatternSource Source of puncture pattern Specify the source of the puncture pattern as one of None | Property. The default is None. Set this property to None to disable puncturing. Set this property to Property to decode punctured codewords based on a puncture pattern vector you specify in the PuncturePattern property. PuncturePattern Puncture pattern vector Specify the pattern that the object uses to puncture the encoded data as 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 the PuncturePatternSource property 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 default is false. The erasures vector is a double-precision or logical, binary, column vector that indicates which bits of the input codewords to erase or ignore. The length of the vector must equal the encoded data input, (that is, the length must be an integer multiple of (CodewordLength – number of punctures)). Values of 1 in the erasures vector correspond to erased bits in the same position of the (possibly punctured) input codewords. Set the this property to false to disable erasures. 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.

## 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

expand all

### Transmit and decode a BCH 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.

hEnc = comm.BCHEncoder;
hMod = comm.DPSKModulator('BitInput',true);
hChan = comm.AWGNChannel(...
'NoiseMethod','Signal to noise ratio (SNR)','SNR',10);
hDemod = comm.DPSKDemodulator('BitOutput',true);
hDec = comm.BCHDecoder;
hError = comm.ErrorRate('ComputationDelay',3);

for counter = 1:20
data = randi([0 1], 30, 1);
encodedData = step(hEnc, data);
modSignal = step(hMod, encodedData);
end

fprintf('Error rate = %f\nNumber of errors = %d\n', ...
errorStats(1), errorStats(2))
```
```Error rate = 0.015075
Number of errors = 9
```

## Algorithms

This object implements the algorithm, inputs, and outputs described on the BCH Decoder block reference. The object properties correspond to the block parameters.