/*---------------------------------------------------------------------------* * IT++ * *---------------------------------------------------------------------------* * Copyright (c) 1995-2004 by Tony Ottosson, Thomas Eriksson, Pål Frenger, * * Tobias Ringström, and Jonas Samuelsson. * * * * Permission to use, copy, modify, and distribute this software and its * * documentation under the terms of the GNU General Public License is hereby * * granted. No representations are made about the suitability of this * * software for any purpose. It is provided "as is" without expressed or * * implied warranty. See the GNU General Public License for more details. * *---------------------------------------------------------------------------*/ /*! \file \brief Implementation of a BCH encoder/decoder class. \author Pål frenger 1.5 2004/08/17 09:04:10 */ #include "comm/bch.h" #include "base/binary.h" namespace itpp { //---------------------- BCH ----------------------------------- BCH::BCH(int in_n, int in_k, int in_t, ivec genpolynom) { n = in_n; k = in_k; t = in_t; //fix the generator polynomial g(x). ivec exponents(n-k+1); bvec temp = oct2bin(genpolynom); for (int i=0; i= 1) { //Errors in the received word //Itterate to find Lambda(x). kk = 0; Lambda = GFX(n+1,(char*)"0"); T = GFX(n+1,(char*)"0"); while (kk kk)) { T = GFX(n+1,(char*)"-1 -1 0") * T; } else { T = ( GFX(n+1,(char*)"-1 0") * OldLambda ) / delta; } kk = kk + 1; } //Find the zeros to Lambda(x). errorpos.set_size(Lambda.get_true_degree(), true); foundzeros = 0; for (j=0; j<=n-1; j++) { temp = Lambda( GF(n+1,j) ); if (Lambda( GF(n+1,j) ) == GF(n+1,-1) ) { errorpos( foundzeros ) = (n-j) % n; foundzeros +=1; if (foundzeros >= Lambda.get_true_degree()) { break; } } } //Correct the codeword. for (j=0; j 1) { m = divgfx(c,g); mbin.clear(); for (j=0; j<=m.get_true_degree(); j++) { if ( m[j] == GF(n+1,0) ) { mbin(j) = 1; } } } else { //The zero word was transmitted mbin = zeros_b(k); m = GFX(n+1,(char*)"-1"); } } else { //Decoder failure. mbin = zeros_b(k); m = GFX(n+1,(char*)"-1"); } decodedbits.replace_mid(i*k,mbin); } } bvec BCH::decode(const bvec &codedbits) { bvec decodedbits; decode(codedbits, decodedbits); return decodedbits; } } //namespace itpp