Main Content

comm.BCHDecoder

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.

Note

Starting in R2016b, instead of using the step method to perform the operation defined by the System object, you can call the object with arguments, as if it were a function. For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

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 2M1, where M is an integer such that 3M16. 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 as a binary double-precision row vector, a binary Galois field row vector that represents the coefficients of the generator polynomial in order of descending powers, or as a polynomial character vector. The length of the generator polynomial requires a value of CodewordLengthMessageLength+1. This property applies when you set GeneratorPolynomialSource to Property. The default is 'X^10 + X^8 + X^5 + X^4 + X^2 + X + 1', which is the result of bchgenpoly(15,5,[],'double') and 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 or a polynomial character vector. This property applies when you set the PrimitivePolynomialSource property to Property. The default is 'X^4 + X + 1', which is the result of int2bit(primpoly(4),5)'.

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

stepDecode data using a BCH decoder
Common to All System Objects
release

Allow System object property value changes

Examples

collapse all

Transmit a BCH-encoded, 8-DPSK-modulated bit stream through an AWGN channel, and then demodulate, decode, and count errors in the received signal.

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 = enc(data);
  modSignal = mod(encodedData);
  receivedSignal = chan(modSignal);
  demodSignal = demod(receivedSignal);
  receivedBits = dec(demodSignal);
  errorStats = 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 encoded with a shortened BCH code, then count errors.

Specify the codeword, message, and shortened message lengths.

N = 255;
K = 239;
S = 63;

Create a BCH (255,239) generator polynomial. Use the generator polynomial to create a BCH encoder and decoder pair. The BCH code is based on the AMR standard.

gp = bchgenpoly(255,239);
bchEncoder = comm.BCHEncoder(N,K,gp,S);
bchDecoder = comm.BCHDecoder(N,K,gp,S);

Create an error rate counter.

errorRate = comm.ErrorRate('ComputationDelay',3);

Main processing loop.

for counter = 1:20
  data = randi([0 1],630,1);                 % Generate binary data
  encodedData = bchEncoder(data);            % BCH encode data
  modSignal = pskmod(encodedData,2);         % BPSK modulate
  receivedSignal = awgn(modSignal,5);        % Pass through AWGN channel
  demodSignal = pskdemod(receivedSignal,2);  % BSPK demodulate
  receivedBits = bchDecoder(demodSignal);    % BCH decode data
  errorStats = errorRate(data,receivedBits); % Compute error statistics
end

Display the error statistics.

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

Shorten a (31,26) BCH code to an (11,6) BCH code and use it to encode and decode random binary data.

Create a BCH encoder and decoder pair for a (31,26) code. Specify the generator polynomial, x5+x2+1, and a shortened message length of 6.

enc = comm.BCHEncoder(31,26,'x5+x2+1',6);
dec = comm.BCHDecoder(31,26,'x5+x2+1',6);

Encode and decode random binary data and verify that the decoded bit stream matches the original data.

x = randi([0 1],60,1);
y = step(enc,x);
z = step(dec,y);
isequal(x,z)
ans = logical
   1

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.

Algorithms

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

Extended Capabilities