IT++
4.3.1
Toggle main menu visibility
itpp
comm
llr.cpp
Go to the documentation of this file.
1
28
29
30
#include <
itpp/comm/llr.h
>
31
32
33
namespace
itpp
34
{
35
36
LLR_calc_unit::LLR_calc_unit
()
37
{
38
init_llr_tables
();
39
}
40
41
LLR_calc_unit::LLR_calc_unit
(
short
int
d1,
short
int
d2,
short
int
d3)
42
{
43
init_llr_tables
(d1, d2, d3);
44
}
45
46
ivec
LLR_calc_unit::get_Dint
()
47
{
48
ivec r(3);
49
r(0) = Dint1;
50
r(1) = Dint2;
51
r(2) = Dint3;
52
return
r;
53
}
54
55
void
LLR_calc_unit::init_llr_tables
(
short
int
d1,
short
int
d2,
short
int
d3)
56
{
57
Dint1 = d1;
// 1<<Dint1 determines how integral LLRs relate to real LLRs (to_double=(1<<Dint)*int_llr)
58
Dint2 = d2;
// number of entries in table for LLR operations
59
Dint3 = d3;
// table resolution is 2^(-(Dint1-Dint3))
60
logexp_table = construct_logexp_table();
61
}
62
63
ivec LLR_calc_unit::construct_logexp_table()
64
{
65
ivec result(Dint2);
66
for
(
int
i = 0; i < Dint2; i++) {
67
double
x =
pow2
(
static_cast<
double
>
(Dint3 - Dint1)) * i;
68
result(i) =
to_qllr
(std::log(1 + std::exp(-x)));
69
}
70
it_assert
(
length
(result) == Dint2,
"Ldpc_codec::construct_logexp_table()"
);
71
72
return
result;
73
}
74
75
QLLRvec
LLR_calc_unit::to_qllr
(
const
vec &l)
const
76
{
77
int
n =
length
(l);
78
ivec result(n);
79
for
(
int
i = 0; i < n; i++) {
80
result.set(i,
to_qllr
(l(i)));
81
}
82
return
result;
83
}
84
85
vec
LLR_calc_unit::to_double
(
const
QLLRvec
&l)
const
86
{
87
int
n =
length
(l);
88
vec result(n);
89
for
(
int
i = 0; i < n; i++) {
90
result.set(i,
to_double
(l(i)));
91
}
92
return
result;
93
}
94
95
QLLRmat
LLR_calc_unit::to_qllr
(
const
mat &l)
const
96
{
97
int
m = l.rows();
98
int
n = l.cols();
99
imat result(m, n);
100
for
(
int
i = 0; i < m; i++) {
101
for
(
int
j = 0; j < n; j++) {
102
result.set(i, j,
to_qllr
(l(i, j)));
103
}
104
}
105
return
result;
106
}
107
108
mat
LLR_calc_unit::to_double
(
const
QLLRmat
&l)
const
109
{
110
int
m = l.
rows
();
111
int
n = l.
cols
();
112
mat result(m, n);
113
for
(
int
i = 0; i < m; i++) {
114
for
(
int
j = 0; j < n; j++) {
115
result.set(i, j,
to_double
(l(i, j)));
116
}
117
}
118
return
result;
119
}
120
121
// This function used to be inline, but in my experiments,
122
// the non-inlined version was actually faster /Martin Senst
123
QLLR
LLR_calc_unit::Boxplus
(
QLLR
a,
QLLR
b)
const
124
{
125
QLLR
a_abs = (a > 0 ? a : -a);
126
QLLR
b_abs = (b > 0 ? b : -b);
127
QLLR
minabs = (a_abs > b_abs ? b_abs : a_abs);
128
QLLR
term1 = (a > 0 ? (b > 0 ? minabs : -minabs)
129
: (b > 0 ? -minabs : minabs));
130
131
if
(Dint2 == 0) {
// logmax approximation - avoid looking into empty table
132
// Don't abort when overflowing, just saturate the QLLR
133
if
(term1 >
QLLR_MAX
) {
134
it_info_debug
(
"LLR_calc_unit::Boxplus(): LLR overflow"
);
135
return
QLLR_MAX
;
136
}
137
if
(term1 < -
QLLR_MAX
) {
138
it_info_debug
(
"LLR_calc_unit::Boxplus(): LLR overflow"
);
139
return
-
QLLR_MAX
;
140
}
141
return
term1;
142
}
143
144
QLLR
apb = a + b;
145
QLLR
term2 =
logexp
((apb > 0 ? apb : -apb));
146
QLLR
amb = a - b;
147
QLLR
term3 =
logexp
((amb > 0 ? amb : -amb));
148
QLLR
result = term1 + term2 - term3;
149
150
// Don't abort when overflowing, just saturate the QLLR
151
if
(result >
QLLR_MAX
) {
152
it_info_debug
(
"LLR_calc_unit::Boxplus() LLR overflow"
);
153
return
QLLR_MAX
;
154
}
155
if
(result < -
QLLR_MAX
) {
156
it_info_debug
(
"LLR_calc_unit::Boxplus() LLR overflow"
);
157
return
-
QLLR_MAX
;
158
}
159
return
result;
160
}
161
162
std::ostream &
operator<<
(std::ostream &os,
const
LLR_calc_unit
&lcu)
163
{
164
os <<
"---------- LLR calculation unit -----------------"
<< std::endl;
165
os <<
"LLR_calc_unit table properties:"
<< std::endl;
166
os <<
"The granularity in the LLR representation is "
167
<<
pow2
(
static_cast<
double
>
(-lcu.Dint1)) << std::endl;
168
os <<
"The LLR scale factor is "
<< (1 << lcu.Dint1) << std::endl;
169
os <<
"The largest LLR that can be represented is "
170
<< lcu.
to_double
(
QLLR_MAX
) << std::endl;
171
os <<
"The table resolution is "
172
<<
pow2
(
static_cast<
double
>
(lcu.Dint3 - lcu.Dint1)) << std::endl;
173
os <<
"The number of entries in the table is "
<< lcu.Dint2 << std::endl;
174
os <<
"The tables truncates at the LLR value "
175
<<
pow2
(
static_cast<
double
>
(lcu.Dint3 - lcu.Dint1)) * lcu.Dint2
176
<< std::endl;
177
os <<
"-------------------------------------------------"
<< std::endl;
178
return
os;
179
}
180
181
}
itpp::LLR_calc_unit::QLLR
signed int QLLR
Definition
llr.h:46
itpp::LLR_calc_unit::Boxplus
QLLR Boxplus(QLLR a, QLLR b) const
Hagenauer's "Boxplus" operator.
Definition
llr.cpp:123
itpp::LLR_calc_unit::init_llr_tables
void init_llr_tables(short int Dint1=12, short int Dint2=300, short int Dint3=7)
Set the quantization and table parameters.
Definition
llr.cpp:55
itpp::LLR_calc_unit::get_Dint
ivec get_Dint()
Retrieve the table resolution values.
Definition
llr.cpp:46
itpp::LLR_calc_unit::to_qllr
QLLR to_qllr(double l) const
Convert a "real" LLR value to an LLR type.
Definition
llr.h:245
itpp::LLR_calc_unit::QLLRmat
Mat< QLLR > QLLRmat
Definition
llr.h:56
itpp::LLR_calc_unit::logexp
QLLR logexp(QLLR x) const
Logexp operator.
Definition
llr.h:261
itpp::LLR_calc_unit::to_double
double to_double(QLLR l) const
Convert an LLR type to a "real" LLR.
Definition
llr.h:240
itpp::LLR_calc_unit::LLR_calc_unit
LLR_calc_unit()
Constructor, using the default table resolution.
Definition
llr.cpp:36
itpp::LLR_calc_unit::QLLR_MAX
const QLLR QLLR_MAX
Definition
llr.h:61
itpp::LLR_calc_unit::QLLRvec
Vec< QLLR > QLLRvec
Definition
llr.h:51
itpp::Mat::rows
int rows() const
The number of rows.
Definition
mat.h:237
itpp::Mat::cols
int cols() const
The number of columns.
Definition
mat.h:235
it_info_debug
#define it_info_debug(s)
Print information message if NDEBUG is not defined.
Definition
itassert.h:163
it_assert
#define it_assert(t, s)
Abort if t is not true.
Definition
itassert.h:94
itpp::pow2
double pow2(double x)
Calculate two to the power of x (2^x).
Definition
log_exp.h:55
itpp::length
int length(const Vec< T > &v)
Length of vector.
Definition
matfunc.h:51
llr.h
Class for numerically efficient log-likelihood algebra.
itpp
itpp namespace
Definition
itmex.h:37
itpp::operator<<
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition
binary.cpp:36
Generated by
1.17.0