Main Content

comm.BCHDecoder

Decode data using BCH decoder

Description

The comm.BCHDecoder System object™ recovers a binary message vector from a binary BCH codeword vector. For proper decoding, the property values for this object must match the property values properties in the corresponding comm.BCHEncoder object. For more information, see Algorithms.

To decode a binary message from a BCH codeword:

  1. Create the comm.BCHDecoder object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

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

example

dec = comm.BCHDecoder(N,K) sets CodewordLength to N and MessageLength to K. For example, comm.BCHDecoder(7,3) creates a (7,3) BCH decoder object.

dec = comm.BCHDecoder(N,K,GP) additionally sets GeneratorPolynomial to GP and GeneratorPolynomialSource to 'Property'.

dec = comm.BCHDecoder(N,K,GP,S) additionally sets ShortMessageLength to S and ShortMessageLengthSource to 'Property'.

example

dec = comm.BCHDecoder(___,Name=Value) specifies options using one or more name-value arguments in addition to the input arguments in previous syntaxes. For example, comm.BCHDecoder(7,3,NumCorrectedErrorsOutputPort=0) creates a (7,3) BCH decoder object that does not output the number of corrected errors.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Codeword length of the BCH code in symbols, specified as a positive integer. 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 (2M – 1), where M is an integer in the range [3, 16].

Message length in symbols, specified as a positive integer. The values of the CodewordLength and MessageLength properties must produce a valid narrow-sense BCH code.

Source of the short message length, specified as "Auto" or "Property".

Shortened message length in symbols, specified as a positive integer whose value must be less than or equal to MessageLength. When ShortMessageLength < MessageLength, the BCH code is shortened.

Dependencies

This property applies when you set ShortMessageLengthSource to "Property".

Source of the generator polynomial, specified as Auto or "Property".

  • When you set this property to "Auto", the object calculates the generator polynomial based on the value of PrimitivePolynomial.

  • When you set this property to "Property", the object uses GeneratorPolynomial to define the generator polynomial.

Generator polynomial, specified as a polynomial string, integer row vector, or Galois field row vector. The specified row vector defines the finite field gf(2M) in descending order of powers corresponding to the integers that form messages and codewords. The length of the generator polynomial must be (NK + 1), where N is CodewordLength and K is MessageLength.

Express the polynomial as one of these options:

  • Character vector or string scalar of a polynomial whose constant term is 1. For more information, see Representation of Polynomials in Communications Toolbox.

  • Binary-valued row vector that represents the coefficients of the polynomial in order of descending powers. The length of this vector must be (M + 1), where M is the degree of the polynomial. The first and last entries must be 1, indicating the leading term with degree M and a constant term of 1.

  • Integer-valued row vector of elements that represent the exponents for the nonzero terms of the polynomial in order of descending powers. The last entry must be 0, indicating a constant term of 1.

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.

Dependencies

This property applies when you set GeneratorPolynomialSource to Property.

Data Types: double | string | char

Option to check the generator polynomial, specified as a logical 1 (true) or 0 (false). Set this property to true to verify the specified generator polynomial is valid.

Tips

For codes with generator polynomials of high degree, disabling the check speeds up processing. As a best practice, perform the check at least once before setting this property to false.

Dependencies

This property applies when GeneratorPolynomialSource is set to "Property".

Data Types: logical

Source of the primitive polynomial, specified as "Auto" or "Property".

  • When you set this property to "Auto", the object uses a primitive polynomial of degree M = ceil(log2(CodewordLength + 1)).

  • When you set this property to "Property", the object uses PrimitivePolynomial to define the primitive polynomial.

Primitive polynomial, specified as a binary row vector that defines the finite field gf(2M) in descending order of powers corresponding to the integers that form messages and codewords.

Express the polynomial as one of these options:

  • Character vector or string scalar of a polynomial whose constant term is 1. For more information, see Representation of Polynomials in Communications Toolbox.

  • Binary-valued row vector that represents the coefficients of the polynomial in order of descending powers. The length of this vector must be M + 1, where M is the degree of the polynomial. The first and last entries must be 1, indicating the leading term with degree M and a constant term of 1.

  • Integer-valued row vector of elements that represent the exponents for the nonzero terms of the polynomial in order of descending powers. The last entry must be 0, indicating a constant term of 1.

The default 'X^4 + X + 1' is the result of int2bit(primpoly(4),5)'.

Dependencies

This property applies when you set PrimitivePolynomialSource to "Property".

Source of the puncture pattern, specified as "None" or "Property".

  • When you set this property to "None", the object does not apply puncturing to the code.

  • When you set this property to "Property", the object punctures the code using the puncture pattern vector defined by PuncturePattern.

Puncture pattern, specified as a binary column vector with a length of (NK), where N is CodewordLength and K is MessageLength. Zeros in the puncture pattern vector indicate the position of the parity symbols that are punctured or excluded from each codeword.

Dependencies

This property applies when you set PuncturePatternSource to "Property".

Option to enable erasures input, specified as a logical 0 (false) or 1 (true).

When you set this property to true, you must specify the erasures vector an input when running the object. The length of the erasures vector is explained in Input and Output Signal Lengths in BCH and RS System Objects.

When you set this property to false, the object assumes no erasures.

Data Types: logical

Option to output number of corrected errors, specified as logical 1 (true) or 0 (false).

Set this property to true to obtain the number of corrected errors as an output when running the object. A nonnegative value in the ith element of the error output vector, denotes the number of corrected errors in the ith input codeword. A value of -1 in the ith element of the error output vector indicates that a decoding error occurred for that codeword. A decoding error occurs when an input codeword has more errors than the error correction capability of the BCH code.

Data Types: logical

Usage

Description

Y = dec(X) decodes the encoded input data using a (CodewordLength,MessageLength) BCH decoder with the corresponding narrow-sense generator polynomial. This syntax applies when you set NumCorrectedErrorsOutputPort to false. For information about the input and output lengths when you run the object, see Input and Output Signal Lengths in BCH and RS System Objects.

example

Y = dec(X,erasures) uses the erasures input vector to erase symbols of the input codewords in X. This syntax applies when you set ErasuresInputPort to true.

[Y,err] = dec(___) decodes using inputs from either of the previous syntaxes, and returns the BCH-decoded output vector Y and the number of corrected symbols in output vector err. A value of -1 in the ith element of the error output vector indicates that a decoding error occurred for that codeword. This syntax applies when you set NumCorrectedErrorsOutputPort to true.

Input Arguments

expand all

Input codeword, specified as a column vector. For information about the input and output lengths when you run the object, see Input and Output Signal Lengths in BCH and RS System Objects.

Data Types: double | single | logical | int8 | int16 | int32 | uint8 | uint16 | uint32

Symbols to erase from the input codewords, specified as a binary column input vector. Values of 1 in the erasures vector correspond to erased symbols, and values of 0 correspond to nonerased symbols.

Data Types: double | logical

Output Arguments

expand all

BCH-decoded message, returned as a column vector.

Number of corrected symbols when decoding the input codeword, returned as an integer.

  • A nonnegative value indicates the number of corrected errors in the current input codeword.

  • A value of -1 indicates that a decoding error occurred for that codeword. A decoding error occurs when an input codeword has more errors than the error correction capability of the BCH code.

Data Types: double

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

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);
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 = awgn(modSignal,snr);
  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.008375
Number of errors = 5

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

Define variables for coding configuration based on the AMR standard.

N = 255;              % Codeword length
K = 239;              % Message length
S = 63;               % Shortened message length
gp = bchgenpoly(N,K); % BCH (255,239) generator polynomial

Create a BCH encoder and decoder pair.

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

Create an error rate counter.

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

Run the main processing loop.

snr = 5;
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,snr);      % 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.000238
Number of errors = 3

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.

N = 31;        % Codeqword length
K = 26;        % Message length
S = 6;         % Shortened message length
gp = 'x5+x2+1' % Generator polynomial
gp = 
'x5+x2+1'
enc = comm.BCHEncoder(N,K,gp,S);
dec = comm.BCHDecoder(N,K,gp,S);

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

X = randi([0 1],60,1);
Y = enc(X);
Z = dec(Y);
isequal(X,Z)
ans = logical
   1

Algorithms

expand all

This object implements Bose-Chaudhuri-Hocquenghem (BCH) coding as described in [1] and Algorithms for BCH and RS Errors-only Decoding.

References

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

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

Extended Capabilities

Version History

Introduced in R2012a

See Also

Objects

Functions