bchdec

BCH decoder

Syntax

decoded = bchdec(code,n,k)
decoded = bchdec(...,paritypos)
[decoded,cnumerr] = bchdec(...)
[decoded,cnumerr,ccode] = bchdec(...)

Description

decoded = bchdec(code,n,k) attempts to decode the received signal in code using an [n,k] BCH decoder with the narrow-sense generator polynomial. code is a Galois array of symbols over GF(2). Each n-element row of code represents 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 code. A decoding failure occurs if bchdec detects more than t errors in a row of code, where t is the number of correctable errors as reported by bchgenpoly. In the case of a decoding failure, bchdec forms the corresponding row of decoded by merely removing n-k symbols from the end of the row of code.

decoded = bchdec(...,paritypos) specifies whether the parity symbols in code were appended or prepended to the message in the coding operation. The string paritypos can be either 'end' or 'beginning'. The default is 'end'. If paritypos is 'beginning', then a decoding failure causes bchdec to remove n-k symbols 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 code. A value of -1 in cnumerr indicates a decoding failure in that row in code.

[decoded,cnumerr,ccode] = bchdec(...) returns ccode, the corrected version of code. The Galois array ccode has the same format as code. If a decoding failure occurs in a certain row of code, then the corresponding row in ccode contains that row unchanged.

Examples

The script below encodes a (random) message, simulates the addition of noise to the code, and then decodes the message.

m = 4; n = 2^m-1; % Codeword length
k = 5; % Message length
nwords = 10; % Number of words to encode
msg = gf(randint(nwords,k));
% Find t, the error-correction capability.
[genpoly,t] = bchgenpoly(n,k);
% Define t2, the number of errors to add in this example.
t2 = t;

% Encode the message.
code = bchenc(msg,n,k);
% Corrupt up to t2 bits in each codeword.
noisycode = code + randerr(nwords,n,1:t2);
% Decode the noisy code.
[newmsg,err,ccode] = bchdec(noisycode,n,k);
if ccode==code
   disp('All errors were corrected.')
end
if newmsg==msg
   disp('The message was recovered perfectly.')
end

In this case, all errors are corrected and the message is recovered perfectly. However, if you change the definition of t2 to

t2 = t+1;

then some codewords will contain more than t errors. This is too many errors, and some are not corrected.

Algorithm

bchdec uses the Berlekamp-Massey decoding algorithm. For information about this algorithm, see the works listed in References below.

Limitations

The maximum allowable value of n is 65535.

See Also

bchenc, bchgenpoly, Block Coding

References

[1] Wicker, Stephen B., Error Control Systems for Digital Communication and Storage, Upper Saddle River, N.J., Prentice Hall, 1995.

[2] Berlekamp, Elwyn R., Algebraic Coding Theory, New York, McGraw-Hill, 1968.


© 1994-2005 The MathWorks, Inc.