mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 22:35:44 +00:00
encoder and soft decoder for augmented Hadamard codes
This commit is contained in:
parent
619d8bd3b4
commit
43c5d6a91a
4 changed files with 242 additions and 0 deletions
41
hadamard_encoder.hh
Normal file
41
hadamard_encoder.hh
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
Encoder for augmented Hadamard codes
|
||||
|
||||
Copyright 2020 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CODE {
|
||||
|
||||
template <int K>
|
||||
class HadamardEncoder
|
||||
{
|
||||
static const int W = 1 << K;
|
||||
static const int N = 1 << (K - 1);
|
||||
int8_t mod[W];
|
||||
|
||||
static bool parity(unsigned x)
|
||||
{
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
x ^= x >> 4;
|
||||
x ^= x >> 2;
|
||||
x ^= x >> 1;
|
||||
return x & 1;
|
||||
}
|
||||
public:
|
||||
HadamardEncoder()
|
||||
{
|
||||
for (int i = 0; i < W; ++i)
|
||||
mod[i] = 1 - 2 * parity(i);
|
||||
}
|
||||
void operator()(int8_t *code, int msg)
|
||||
{
|
||||
for (int i = 0; i < N; ++i)
|
||||
code[i] = mod[msg&(i|N)];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue