egolay.cpp
Go to the documentation of this file.
#include <itpp/comm/egolay.h>
#include <itpp/comm/commfunc.h>
#include <itpp/base/specmat.h>
#include <itpp/base/converters.h>
namespace itpp
{
Extended_Golay::Extended_Golay(void)
{
B = "0 1 1 1 1 1 1 1 1 1 1 1;1 1 1 0 1 1 1 0 0 0 1 0;1 1 0 1 1 1 0 0 0 1 0 1;1 0 1 1 1 0 0 0 1 0 1 1;1 1 1 1 0 0 0 1 0 1 1 0;1 1 1 0 0 0 1 0 1 1 0 1;1 1 0 0 0 1 0 1 1 0 1 1;1 0 0 0 1 0 1 1 0 1 1 1;1 0 0 1 0 1 1 0 1 1 1 0;1 0 1 0 1 1 0 1 1 1 0 0;1 1 0 1 1 0 1 1 1 0 0 0;1 0 1 1 0 1 1 1 0 0 0 1";
G = concat_horizontal(eye_b(12), B);
}
void Extended_Golay::encode(const bvec &uncoded_bits, bvec &coded_bits)
{
int no_bits = uncoded_bits.length();
int no_blocks = floor_i(no_bits / 12.0);
coded_bits.set_size(24*no_blocks, false);
bmat Gt = G.T();
int i;
for (i = 0; i < no_blocks; i++)
coded_bits.replace_mid(24*i, Gt * uncoded_bits.mid(i*12, 12));
}
bvec Extended_Golay::encode(const bvec &uncoded_bits)
{
bvec coded_bits;
encode(uncoded_bits, coded_bits);
return coded_bits;
}
void Extended_Golay::decode(const bvec &coded_bits, bvec &decoded_bits)
{
int no_bits = coded_bits.length();
int no_blocks = floor_i(no_bits / 24.0);
decoded_bits.set_size(12*no_blocks, false);
int i, j;
bvec S(12), BS(12), r(12), temp(12), e(24), c(24);
bmat eyetemp = eye_b(12);
for (i = 0; i < no_blocks; i++) {
r = coded_bits.mid(i * 24, 24);
// Step 1. Compute S=G*r.
S = G * r;
// Step 2. w(S)<=3. e=(S,0). Goto 8.
if (weight(S) <= 3) {
e = concat(S, zeros_b(12));
goto Step8;
}
// Step 3. w(S+Ii)<=2. e=(S+Ii,yi). Goto 8.
for (j = 0; j < 12; j++) {
temp = S + B.get_col(j);
if (weight(temp) <= 2) {
e = concat(temp, eyetemp.get_row(j));
goto Step8;
}
}
// STEP 4. Compute B*S
BS = B * S;
// Step 5. w(B*S)<=3. e=(0,BS). Goto8.
if (weight(BS) <= 3) {
e = concat(zeros_b(12), BS);
goto Step8;
}
// Step 6. w(BS+Ri)<=2. e=(xi,BS+Ri). Goto 8.
for (j = 0; j < 12; j++) {
temp = BS + B.get_row(j);
if (weight(temp) <= 2) {
e = concat(eyetemp.get_row(j), temp);
goto Step8;
}
}
// Step 7. Uncorrectable erreor pattern. Choose the first 12 bits.
e = zeros_b(24);
goto Step8;
Step8: // Step 8. c=r+e. STOP
c = r + e;
decoded_bits.replace_mid(i*12, c.left(12));
}
}
bvec Extended_Golay::decode(const bvec &coded_bits)
{
bvec decoded_bits;
decode(coded_bits, decoded_bits);
return decoded_bits;
}
// -------------- Soft-decision decoding is not implemented ------------------
void Extended_Golay::decode(const vec &, bvec &)
{
it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented");
}
bvec Extended_Golay::decode(const vec &)
{
it_error("Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented");
return bvec();
}
} // namespace itpp
itpp::Array
General array class.
Definition array.h:105
itpp::Array::mid
Array< T > mid(int pos, int n) const
Get n elements of the array starting from pos.
Definition array.h:377
itpp::Array::left
Array< T > left(int n) const
Get n left elements of the array.
Definition array.h:357
itpp::Array::set_size
void set_size(int n, bool copy=false)
Resizing an Array<T>.
Definition array.h:257
itpp::Array::length
int length() const
Returns the number of data elements in the array object.
Definition array.h:157
itpp::Extended_Golay::Extended_Golay
Extended_Golay()
Constructor.
Definition egolay.cpp:37
itpp::Extended_Golay::decode
virtual void decode(const bvec &coded_bits, bvec &decoded_bits)
Decoder. Will truncate some bits if not length = integer * 24.
Definition egolay.cpp:64
itpp::Extended_Golay::encode
virtual void encode(const bvec &uncoded_bits, bvec &coded_bits)
Encoder. Will truncate some bits if not length = integer * 12.
Definition egolay.cpp:44
commfunc.h
Definitions of some specific functions useful in communications.
converters.h
Definitions of converters between different vector and matrix types.
egolay.h
Definition of the Extended Golay Code (24, 12, 8)
it_error
#define it_error(s)
Abort unconditionally.
Definition itassert.h:126
itpp::weight
int weight(const bvec &a)
Calculate the Hamming weight of a.
Definition commfunc.cpp:71
itpp::eye_b
ITPP_EXPORT bmat eye_b(int size)
A Binary (size,size) unit matrix.
itpp::zeros_b
ITPP_EXPORT bvec zeros_b(int size)
A Binary vector of zeros.
bmat
Mat< bin > bmat
bin matrix
Definition mat.h:508
itpp
itpp namespace
Definition itmex.h:37
itpp::concat_horizontal
Mat< Num_T > concat_horizontal(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Horizontal concatenation of two matrices.
Definition mat.h:1194
itpp::concat
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
Definition array.h:486
itpp::floor_i
int floor_i(double x)
The nearest smaller integer.
Definition converters.h:350
specmat.h
Definitions of special vectors and matrices.

Generated on Mon Jun 10 2024 11:49:20 for IT++ by Doxygen 1.9.8