Main Content

comm.BCHEncoder

Encode data using BCH encoder

Description

The comm.BCHEncoder System object™ creates a BCH code with message and codeword lengths that you specify. For more information, see Algorithms.

To encode data using a BCH-coding scheme:

  1. Create the comm.BCHEncoder 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

enc = comm.BCHEncoder creates a BCH encoder System object, enc, that applies BCH encoding.

example

enc = comm.BCHEncoder(N,K) sets CodewordLength to N and MessageLength to K. For example, comm.BCHEncoder(7,3) creates a (7,3) BCH encoder object.

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

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

example

enc = comm.BCHEncoder(___,Name=Value) specifies options using one or more name-value arguments in addition to the input arguments in previous syntaxes. For example, comm.BCHEncoder(7,3,PuncturePatternSource="Property",PuncturePattern=[ones(7,1); zeros(3,1)]) creates a (7, 3) BCH encoder object with the puncture pattern set to [1;1;1;1;1;1;1;0;0;0].

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 object shortens the BCH code.

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 'X^10 + X^8 + X^5 + X^4 + X^2 + X + 1' 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".

Usage

Description

Y = enc(X) encodes the input message using a (CodewordLength,MessageLength) BCH encoder with the corresponding narrow-sense generator polynomial. 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

Input Arguments

expand all

Message to encode, specified as numeric or logical column vector with length equal to an integer multiple of MessageLength. A group of MessageLength input elements represents one message word to be encoded.

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

Output Arguments

expand all

BCH-encoded codeword, returned as a binary-valued column vector. The length of the encoded data output vector is an integer multiple of (CodewordLengthNpunctures), where Npunctures is the number of punctures. You specify the number of punctures with the PuncturePatternSource and PuncturePattern properties.

Data Types: single | logical

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

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

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

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

Go to top of page