mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
added encoder and soft decoder for simplex codes
This commit is contained in:
parent
e2b46aed76
commit
620466021b
3 changed files with 236 additions and 0 deletions
56
simplex_decoder.hh
Normal file
56
simplex_decoder.hh
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
Soft decoder for Simplex codes
|
||||
|
||||
Copyright 2020 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CODE {
|
||||
|
||||
template <int K>
|
||||
class SimplexDecoder
|
||||
{
|
||||
static const int W = 1 << K;
|
||||
static const int N = (1 << K) - 1;
|
||||
int8_t mod[W*N];
|
||||
|
||||
static bool parity(unsigned x)
|
||||
{
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
x ^= x >> 4;
|
||||
x ^= x >> 2;
|
||||
x ^= x >> 1;
|
||||
return x & 1;
|
||||
}
|
||||
public:
|
||||
SimplexDecoder()
|
||||
{
|
||||
for (int msg = 0; msg < W; ++msg)
|
||||
for (int i = 0; i < N; ++i)
|
||||
mod[msg*N+i] = 1 - 2 * parity(msg&(i+1));
|
||||
}
|
||||
int operator()(const int8_t *code)
|
||||
{
|
||||
int word = 0, best = 0, next = 0;
|
||||
for (int msg = 0; msg < W; ++msg) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < N; ++i)
|
||||
sum += mod[msg*N+i] * code[i];
|
||||
if (sum > best) {
|
||||
next = best;
|
||||
best = sum;
|
||||
word = msg;
|
||||
} else if (sum > next) {
|
||||
next = sum;
|
||||
}
|
||||
}
|
||||
if (best == next)
|
||||
return -1;
|
||||
return word;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue