| Communications Toolbox | ![]() |
Syntax
msg = bchdeco(code,k,t); msg = bchdeco(code,k,t,primpoly); [msg,err] = bchdeco(...); [msg,err,ccode] = bchdeco(...);
Description
msg = bchdeco(code,k,t)
decodes code using the BCH method. k is the message length. The codeword length n must have the form 2m-1 for some integer m greater than or equal to 3. code is a binary matrix with n columns, each row of which represents one codeword. msg is a binary matrix with k columns, each row of which represents one message. t is the error-correction capability. BCH decoding requires a primitive polynomial for GF(2m); this syntax uses MATLAB's default primitive polynomial, gfprimdf(m).
msg = bchdeco(code,k,t,primpoly)
is the same as the first syntax, except that primpoly is a row vector that gives the coefficients, in order of ascending powers, of the primitive polynomial for GF(2m) that will be used during processing.
[msg,err] = bchdeco(...)
returns a column vector err that gives information about error correction. A nonnegative integer in err(r) indicates the number of errors corrected in the rth codeword; a negative integer indicates that there are more errors in the rth codeword than can be corrected.
[msg,err,ccode] = bchdeco(...)
returns the corrected code in ccode.
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
params = bchpoly(n);
% Arbitrarily focus on 3rd row of params.
k = params(3,2); % Codeword length
t = params(3,3); % Error-correction capability
msg = randint(100,k);
code = bchenco(msg,n,k); % Encode the message.
% Corrupt up to t bits in each codeword.
noisycode = rem(code + randerr(100,n,1:t),2);
% Decode the noisy code.
[newmsg,err,ccode] = bchdeco(noisycode,k,t);
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 the ninth line is changed to
noisycode = rem(code + randerr(100,n,1:(t+1)),2);
then some codewords will contain more than t errors. This is too many errors, and some will go uncorrected.
See Also
bchenco, encode, decode
| awgn | bchenco | ![]() |