mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 22:35:44 +00:00
use in-place fast Walsh–Hadamard transform
This commit is contained in:
parent
759ca4b896
commit
3596f2943b
1 changed files with 23 additions and 26 deletions
|
|
@ -13,37 +13,34 @@ class HadamardDecoder
|
||||||
{
|
{
|
||||||
static const int W = 1 << K;
|
static const int W = 1 << K;
|
||||||
static const int N = 1 << (K - 1);
|
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:
|
public:
|
||||||
HadamardDecoder()
|
int operator()(const int8_t *c)
|
||||||
{
|
|
||||||
for (int msg = 0; msg < W; ++msg)
|
|
||||||
for (int i = 0; i < N; ++i)
|
|
||||||
mod[msg*N+i] = 1 - 2 * parity(msg&(i|N));
|
|
||||||
}
|
|
||||||
int operator()(const int8_t *code)
|
|
||||||
{
|
{
|
||||||
|
int sum[N];
|
||||||
|
for (int i = 0; i < N; i += 2) {
|
||||||
|
sum[i] = c[i] + c[i+1];
|
||||||
|
sum[i+1] = c[i] - c[i+1];
|
||||||
|
}
|
||||||
|
for (int h = 2; h < N; h *= 2) {
|
||||||
|
for (int i = 0; i < N; i += 2 * h) {
|
||||||
|
for (int j = i; j < i + h; ++j) {
|
||||||
|
int x = sum[j] + sum[j+h];
|
||||||
|
int y = sum[j] - sum[j+h];
|
||||||
|
sum[j] = x;
|
||||||
|
sum[j+h] = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
int word = 0, best = 0, next = 0;
|
int word = 0, best = 0, next = 0;
|
||||||
for (int msg = 0; msg < W; ++msg) {
|
for (int i = 0; i < N; ++i) {
|
||||||
int sum = 0;
|
int mag = std::abs(sum[i]);
|
||||||
for (int i = 0; i < N; ++i)
|
int msg = i + N * (sum[i] < 0);
|
||||||
sum += mod[msg*N+i] * code[i];
|
if (mag > best) {
|
||||||
if (sum > best) {
|
|
||||||
next = best;
|
next = best;
|
||||||
best = sum;
|
best = mag;
|
||||||
word = msg;
|
word = msg;
|
||||||
} else if (sum > next) {
|
} else if (mag > next) {
|
||||||
next = sum;
|
next = mag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (best == next)
|
if (best == next)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue