decoded = bchdec(code,n,k) attempts
to decode the received signal in
code using an
k] BCH decoder with the narrow-sense
code is a Galois array of
symbols over GF(2). Each
n-element row of
a corrupted systematic codeword, where the parity symbols are at the
end and the leftmost symbol is the most significant symbol.
In the Galois array
decoded, each row represents
the attempt at decoding the corresponding row in
A decoding failure occurs if
more than t errors in a row of
code, where t is
the number of correctable errors as reported by
In the case of a decoding failure,
the corresponding row of
decoded by merely removing
from the end of the row of
decoded = bchdec(...,paritypos) specifies
whether the parity symbols in
code were appended
or prepended to the message in the coding operation. The string
The default is
then a decoding failure causes
bchdec to remove
from the beginning rather than the end of the row.
[decoded,cnumerr] = bchdec(___) returns
a column vector
cnumerr, each element of which
is the number of corrected errors in the corresponding row of
A value of
a decoding failure in that row in
[decoded,cnumerr,ccode] = bchdec(___) returns
the corrected version of
code. The Galois array
the same format as
code. If a decoding failure
occurs in a certain row of
code, the corresponding
ccode contains that row unchanged.
BCH decoders correct up to a certain number of errors, specified by the user. If the input contains more errors than the decoder is meant to correct, the decoder will most likely not output the correct codeword.
The chance of a BCH decoder decoding a corrupted input to the correct codeword depends on the number of errors in the input and the number of errors the decoder is meant to correct.
For example, when a single-error-correcting BCH decoder is given input with two errors, it actually decodes it to a different codeword. When a double-error-correcting BCH decoder is given input with three errors, then it only sometimes decodes it to a valid codeword.
The following code illustrates this phenomenon for a single-error-correcting BCH decoder given input with two errors.
n = 63; k = 57; s = RandStream('swb2712', 'Seed', 9973); msg = gf(randi(s,[0 1],1,k)); code = bchenc(msg, n, k); % Add 2 errors cnumerr2 = zeros(nchoosek(n,2),1); nErrs = zeros(nchoosek(n,2),1); cnumerrIdx = 1; for idx1 = 1 : n-1 sprintf('idx1 for 2 errors = %d', idx1) for idx2 = idx1+1 : n errors = zeros(1,n); errors(idx1) = 1; errors(idx2) = 1; erroredCode = code + gf(errors); [decoded2, cnumerr2(cnumerrIdx)]... = bchdec(erroredCode, n, k); % If bchdec thinks it corrected only one error, % then encode the decoded message. Check that % the re-encoded message differs from the errored % message in only one coordinate. if cnumerr2(cnumerrIdx) == 1 code2 = bchenc(decoded2, n, k); nErrs(cnumerrIdx) = biterr(double(erroredCode.x),... double(code2.x)); end cnumerrIdx = cnumerrIdx + 1; end end % Plot the computed number of errors, based on the difference % between the double-errored codeword and the codeword that was % re-encoded from the initial decoding. plot(nErrs) title(['Number of Actual Errors between Errored Codeword and' ... 'Re-encoded Codeword'])
The resulting plot shows that all inputs with two errors are decoded to a codeword that differs in exactly one position.
Set the BCH parameters for GF(16).
m = 4; n = 2^m-1; % Codeword length k = 5; % Message length nwords = 10; % Number of words to encode
Create a message.
msgTx = gf(randi([0 1],nwords,k));
t, the error-correction capability.
[~,t] = bchgenpoly(n,k)
t = 3
Encode the message.
enc = bchenc(msgTx,n,k);
Corrupt up to
t bits in each codeword.
noisycode = enc + randerr(nwords,n,1:t);
Decode the noisy code.
msgRx = bchdec(noisycode,n,k);
Validate that the message was properly decoded.
ans = 1
Increase the number of possible errors, and generate another noisy codeword.
t2 = t + 1; noisycode2 = enc + randerr(nwords,n,1:t2);
Decode the new received codeword.
[msgRx2,numerr] = bchdec(noisycode2,n,k);
Determine if the message was property decoded by examining the number of corrected errors,
numerr. Entries of
-1 correspond to cases in which a decoding failure occured because there were more errors that could be corrected.
numerr = 1 2 -1 2 3 1 -1 4 2 3
Two of the ten transmitted codewords were not correctly received.
The maximum allowable value of
n is 65535.
 Wicker, Stephen B., Error Control Systems for Digital Communication and Storage, Upper Saddle River, NJ, Prentice Hall, 1995.
 Berlekamp, Elwyn R., Algebraic Coding Theory, New York, McGraw-Hill, 1968.