-
Notifications
You must be signed in to change notification settings - Fork 2
/
polar_encoder.hh
60 lines (55 loc) · 1.62 KB
/
polar_encoder.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Polar encoder for non-systematic and systematic codes
Copyright 2020 Ahmet Inan <xdsopl@gmail.com>
*/
#pragma once
template <typename TYPE, int M>
class PolarEncoder
{
static const int N = 1 << M;
typedef PolarHelper<TYPE> PH;
public:
void operator()(TYPE *codeword, const TYPE *message, const uint8_t *frozen)
{
for (int i = 0; i < N; i += 2) {
TYPE msg0 = frozen[i] ? PH::one() : *message++;
TYPE msg1 = frozen[i+1] ? PH::one() : *message++;
codeword[i] = PH::qmul(msg0, msg1);
codeword[i+1] = msg1;
}
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)
codeword[j] = PH::qmul(codeword[j], codeword[j+h]);
}
};
template <typename TYPE, int M>
class PolarSysEnc
{
static const int N = 1 << M;
typedef PolarHelper<TYPE> PH;
public:
void operator()(TYPE *codeword, const TYPE *message, const uint8_t *frozen)
{
for (int i = 0; i < N; i += 2) {
TYPE msg0 = frozen[i] ? PH::one() : *message++;
TYPE msg1 = frozen[i+1] ? PH::one() : *message++;
codeword[i] = PH::qmul(msg0, msg1);
codeword[i+1] = msg1;
}
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)
codeword[j] = PH::qmul(codeword[j], codeword[j+h]);
for (int i = 0; i < N; i += 2) {
TYPE msg0 = frozen[i] ? PH::one() : codeword[i];
TYPE msg1 = frozen[i+1] ? PH::one() : codeword[i+1];
codeword[i] = PH::qmul(msg0, msg1);
codeword[i+1] = msg1;
}
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)
codeword[j] = PH::qmul(codeword[j], codeword[j+h]);
}
};