IT++
4.3.1
Toggle main menu visibility
itpp
comm
egolay.cpp
Go to the documentation of this file.
1
28
29
#include <
itpp/comm/egolay.h
>
30
#include <
itpp/comm/commfunc.h
>
31
#include <
itpp/base/specmat.h
>
32
#include <
itpp/base/converters.h
>
33
34
namespace
itpp
35
{
36
37
Extended_Golay::Extended_Golay
(
void
)
38
{
39
B =
"0 1 1 1 1 1 1 1 1 1 1 1;1 1 1 0 1 1 1 0 0 0 1 0;1 1 0 1 1 1 0 0 0 1 0 1;1 0 1 1 1 0 0 0 1 0 1 1;1 1 1 1 0 0 0 1 0 1 1 0;1 1 1 0 0 0 1 0 1 1 0 1;1 1 0 0 0 1 0 1 1 0 1 1;1 0 0 0 1 0 1 1 0 1 1 1;1 0 0 1 0 1 1 0 1 1 1 0;1 0 1 0 1 1 0 1 1 1 0 0;1 1 0 1 1 0 1 1 1 0 0 0;1 0 1 1 0 1 1 1 0 0 0 1"
;
40
41
G =
concat_horizontal
(
eye_b
(12), B);
42
}
43
44
void
Extended_Golay::encode
(
const
bvec &uncoded_bits, bvec &coded_bits)
45
{
46
int
no_bits = uncoded_bits.length();
47
int
no_blocks =
floor_i
(no_bits / 12.0);
48
49
coded_bits.set_size(24*no_blocks,
false
);
50
bmat
Gt = G.T();
51
int
i;
52
53
for
(i = 0; i < no_blocks; i++)
54
coded_bits.replace_mid(24*i, Gt * uncoded_bits.mid(i*12, 12));
55
}
56
57
bvec
Extended_Golay::encode
(
const
bvec &uncoded_bits)
58
{
59
bvec coded_bits;
60
encode
(uncoded_bits, coded_bits);
61
return
coded_bits;
62
}
63
64
void
Extended_Golay::decode
(
const
bvec &coded_bits, bvec &decoded_bits)
65
{
66
int
no_bits = coded_bits.length();
67
int
no_blocks =
floor_i
(no_bits / 24.0);
68
69
decoded_bits.set_size(12*no_blocks,
false
);
70
int
i, j;
71
bvec S(12), BS(12), r(12), temp(12), e(24), c(24);
72
bmat
eyetemp =
eye_b
(12);
73
74
for
(i = 0; i < no_blocks; i++) {
75
r = coded_bits.mid(i * 24, 24);
76
// Step 1. Compute S=G*r.
77
S = G * r;
78
// Step 2. w(S)<=3. e=(S,0). Goto 8.
79
if
(
weight
(S) <= 3) {
80
e =
concat
(S,
zeros_b
(12));
81
goto
Step8;
82
}
83
84
// Step 3. w(S+Ii)<=2. e=(S+Ii,yi). Goto 8.
85
for
(j = 0; j < 12; j++) {
86
87
temp = S + B.get_col(j);
88
if
(
weight
(temp) <= 2) {
89
e =
concat
(temp, eyetemp.get_row(j));
90
goto
Step8;
91
}
92
}
93
94
// STEP 4. Compute B*S
95
BS = B * S;
96
97
// Step 5. w(B*S)<=3. e=(0,BS). Goto8.
98
if
(
weight
(BS) <= 3) {
99
e =
concat
(
zeros_b
(12), BS);
100
goto
Step8;
101
}
102
103
// Step 6. w(BS+Ri)<=2. e=(xi,BS+Ri). Goto 8.
104
for
(j = 0; j < 12; j++) {
105
temp = BS + B.get_row(j);
106
if
(
weight
(temp) <= 2) {
107
e =
concat
(eyetemp.get_row(j), temp);
108
goto
Step8;
109
}
110
}
111
112
// Step 7. Uncorrectable erreor pattern. Choose the first 12 bits.
113
e =
zeros_b
(24);
114
goto
Step8;
115
116
Step8:
// Step 8. c=r+e. STOP
117
c = r + e;
118
decoded_bits.replace_mid(i*12, c.left(12));
119
}
120
}
121
122
bvec
Extended_Golay::decode
(
const
bvec &coded_bits)
123
{
124
bvec decoded_bits;
125
decode
(coded_bits, decoded_bits);
126
return
decoded_bits;
127
}
128
129
130
// -------------- Soft-decision decoding is not implemented ------------------
131
void
Extended_Golay::decode
(
const
vec &, bvec &)
132
{
133
it_error
(
"Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented"
);
134
}
135
136
bvec
Extended_Golay::decode
(
const
vec &)
137
{
138
it_error
(
"Extended_Golay::decode(vec, bvec); soft-decision decoding is not implemented"
);
139
return
bvec();
140
}
141
142
143
}
// namespace itpp
itpp::Extended_Golay::Extended_Golay
Extended_Golay()
Constructor.
Definition
egolay.cpp:37
itpp::Extended_Golay::decode
virtual void decode(const bvec &coded_bits, bvec &decoded_bits)
Decoder. Will truncate some bits if not length = integer * 24.
Definition
egolay.cpp:64
itpp::Extended_Golay::encode
virtual void encode(const bvec &uncoded_bits, bvec &coded_bits)
Encoder. Will truncate some bits if not length = integer * 12.
Definition
egolay.cpp:44
commfunc.h
Definitions of some specific functions useful in communications.
converters.h
Definitions of converters between different vector and matrix types.
egolay.h
Definition of the Extended Golay Code (24, 12, 8).
it_error
#define it_error(s)
Abort unconditionally.
Definition
itassert.h:126
itpp::weight
int weight(const bvec &a)
Calculate the Hamming weight of a.
Definition
commfunc.cpp:71
itpp::eye_b
ITPP_EXPORT bmat eye_b(int size)
A Binary (size,size) unit matrix.
itpp::zeros_b
ITPP_EXPORT bvec zeros_b(int size)
A Binary vector of zeros.
bmat
Mat< bin > bmat
bin matrix
Definition
mat.h:508
itpp
itpp namespace
Definition
itmex.h:37
itpp::concat_horizontal
Mat< Num_T > concat_horizontal(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Horizontal concatenation of two matrices.
Definition
mat.h:1194
itpp::concat
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
Definition
array.h:486
itpp::floor_i
int floor_i(double x)
The nearest smaller integer.
Definition
converters.h:350
specmat.h
Definitions of special vectors and matrices.
Generated by
1.17.0