-
Notifications
You must be signed in to change notification settings - Fork 24
/
encoder2.hh
78 lines (72 loc) · 1.29 KB
/
encoder2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
LDPC SISO encoder v2
Copyright 2018 Ahmet Inan <[email protected]>
*/
#ifndef ENCODER_HH
#define ENCODER_HH
#include "ldpc.hh"
template <typename TYPE>
class LDPCEncoder
{
uint16_t *pos;
uint8_t *cnc;
int R, CNL;
bool initialized;
TYPE one()
{
return 1;
}
TYPE sign(TYPE a, TYPE b)
{
return b < TYPE(0) ? -a : b > TYPE(0) ? a : TYPE(0);
}
public:
LDPCEncoder() : initialized(false)
{
}
void init(LDPCInterface *it)
{
if (initialized) {
delete[] pos;
delete[] cnc;
}
initialized = true;
LDPCInterface *ldpc = it->clone();
int N = ldpc->code_len();
int K = ldpc->data_len();
R = N - K;
CNL = ldpc->links_max_cn() - 2;
pos = new uint16_t[R * CNL];
cnc = new uint8_t[R];
for (int i = 0; i < R; ++i)
cnc[i] = 0;
ldpc->first_bit();
for (int j = 0; j < K; ++j) {
int *acc_pos = ldpc->acc_pos();
int bit_deg = ldpc->bit_deg();
for (int n = 0; n < bit_deg; ++n) {
int i = acc_pos[n];
pos[CNL*i+cnc[i]++] = j;
}
ldpc->next_bit();
}
delete ldpc;
}
void operator()(TYPE *data, TYPE *parity)
{
TYPE tmp = one();
for (int i = 0; i < R; ++i) {
for (int j = 0; j < cnc[i]; ++j)
tmp = sign(tmp, data[pos[CNL*i+j]]);
parity[i] = tmp;
}
}
~LDPCEncoder()
{
if (initialized) {
delete[] pos;
delete[] cnc;
}
}
};
#endif