/*---------------------------------------------------------------------------* * 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 Hamming code class \author Tony Ottosson 1.7 2004/08/17 09:27:24 */ #include "base/binary.h" #include "base/scalfunc.h" #include "base/converters.h" #include "base/matfunc.h" #include "comm/hammcode.h" namespace itpp { Hamming_Code::Hamming_Code(short m) { n = round_i(pow(2,m)) - 1; k = round_i(pow(2,m)) - m - 1; H.set_size(n-k,n,0); G.set_size(k,n,0); generate_H(); // generate_H must be run before generate_G generate_G(); } void Hamming_Code::generate_H(void) { short i, j, NextPos; char NotUsed; bvec temp; svec indexes(n); indexes.zeros(); for (i=1; i<=n-k; i++) { indexes(i-1) = round_i(pow(2,n-k-i)); } NextPos = n-k; for (i=1; i<=n; i++) { NotUsed = 1; for (j=0; j