Creating and Decoding BCH Codes

The bchenc and bchdec functions create and decode BCH codes, using the data described in Representing Words for BCH Codes and Parameters for BCH Codes. This section illustrates how to use bchenc and bchdec.

The topics are

Example: BCH Coding Syntaxes

The example below illustrates how to encode and decode data using a [15, 5] Reed-Solomon code. The example shows that

The output is below.

chk =

     1

Example: Detecting and Correcting Errors in a BCH Code

The example below illustrates the decoding results for a corrupted code. The example encodes some data, introduces errors in each codeword, and invokes bchdec to attempt to decode the noisy code. It uses additional output arguments in bchdec to gain information about the success of the decoding process.

n = 15; k = 5; % Codeword length and message length
[gp,t] = bchgenpoly(n,k); % t is error-correction capability.
nw = 4; % Number of words to process
msgw = gf(randint(nw,k)); % Random k-symbol messages
c = bchenc(msgw,n,k); % Encode the data.
noise = randerr(nw,n,t); % t errors/row
cnoisy = c + noise; % Add noise to the code.
[dc,nerrs,corrcode] = bchdec(cnoisy,n,k); % Decode cnoisy.

% Check that the decoding worked correctly.
chk2 = isequal(dc,msgw) & isequal(corrcode,c)
nerrs % Find out how many errors bchdec corrected.

Notice that the array of noise values contains binary values, and that the addition operation c + noise takes place in the Galois field GF(2) because c is a Galois array in GF(2).

The output from the example is below. The nonzero value of ans indicates that the decoder was able to correct the corrupted codewords and recover the original message. The values in the vector nerrs indicate that the decoder corrected t errors in each codeword.

chk2 =

     1


nerrs =

     3     3     3     3

Excessive Noise in BCH Codewords.   In the previous example, bchdec corrected all the errors. However, each BCH code has a finite error-correction capability. To learn more about how bchdec behaves when the noise is excessive, see the analogous discussion for Reed-Solomon codes in Excessive Noise in Reed-Solomon Codewords.


© 1994-2005 The MathWorks, Inc.