IT++ Logo
llr.h
Go to the documentation of this file.
1
29#ifndef LLR_H
30#define LLR_H
31
32#include <limits>
33#include <itpp/base/vec.h>
34#include <itpp/base/mat.h>
35#include <itpp/base/specmat.h>
36#include <itpp/base/matfunc.h>
37#include <limits>
38#include <itpp/itexports.h>
39
40namespace itpp
41{
42
46typedef signed int QLLR;
47
52
57
61const QLLR QLLR_MAX = (std::numeric_limits<QLLR>::max() >> 4);
62// added some margin to make sure the sum of two LLR is still permissible
63
125{
126public:
129
135 LLR_calc_unit(short int Dint1, short int Dint2, short int Dint3);
136
165 void init_llr_tables(short int Dint1 = 12, short int Dint2 = 300,
166 short int Dint3 = 7);
167
169 QLLR to_qllr(double l) const;
170
172 QLLRvec to_qllr(const vec &l) const;
173
175 QLLRmat to_qllr(const mat &l) const;
176
178 double to_double(QLLR l) const;
179
181 vec to_double(const QLLRvec &l) const;
182
184 mat to_double(const QLLRmat &l) const;
185
191 inline QLLR jaclog(QLLR a, QLLR b) const;
192 // Note: a version of this function taking "double" values as input
193 // is deliberately omitted, because this is rather slow.
194
203 QLLR Boxplus(QLLR a, QLLR b) const;
204
210 inline QLLR logexp(QLLR x) const;
211
213 ivec get_Dint();
214
216 friend ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const LLR_calc_unit &l);
217
218private:
220 ivec construct_logexp_table();
221
223 ivec logexp_table;
224
226 short int Dint1, Dint2, Dint3;
227};
228
233ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const LLR_calc_unit &lcu);
234
235
236// ----------------------------------------------------------------------
237// implementation of some inline functions
238// ----------------------------------------------------------------------
239
240inline double LLR_calc_unit::to_double(QLLR l) const
241{
242 return static_cast<double>(l) / (1 << Dint1);
243}
244
245inline QLLR LLR_calc_unit::to_qllr(double l) const
246{
248 // Don't abort when overflow occurs, just saturate the QLLR
249 if (l > QLLR_MAX_double) {
250 it_info_debug("LLR_calc_unit::to_qllr(): LLR overflow");
251 return QLLR_MAX;
252 }
253 if (l < -QLLR_MAX_double) {
254 it_info_debug("LLR_calc_unit::to_qllr(): LLR overflow");
255 return -QLLR_MAX;
256 }
257 return static_cast<QLLR>(std::floor(0.5 + (1 << Dint1) * l));
258}
259
260
262{
263 it_assert_debug(x >= 0, "LLR_calc_unit::logexp(): Wrong LLR value");
264 int ind = x >> Dint3;
265 if (ind >= Dint2) // outside table
266 return 0;
267
268 it_assert_debug(ind >= 0, "LLR_calc_unit::logexp(): Internal error");
269 it_assert_debug(ind < Dint2, "LLR_calc_unit::logexp(): internal error");
270
271 // With interpolation
272 // int delta=x-(ind<<Dint3);
273 // return ((delta*logexp_table(ind+1) + ((1<<Dint3)-delta)*logexp_table(ind)) >> Dint3);
274
275 // Without interpolation
276 return logexp_table(ind);
277}
278
279
281{
282 QLLR x, maxab;
283
284 if (a > b) {
285 maxab = a;
286 x = a - b;
287 }
288 else {
289 maxab = b;
290 x = b - a;
291 }
292
293 if (maxab >= QLLR_MAX)
294 return QLLR_MAX;
295 else
296 return (maxab + logexp(x));
297}
298
299}
300
301#endif
General array class.
Definition array.h:105
std::ostream & operator<<(std::ostream &os, const Array< T > &a)
Output stream for Array<T>. T must have ostream operator<< defined.
Definition array.h:545
Log-likelihood algebra calculation unit.
Definition llr.h:125
signed int QLLR
Definition llr.h:46
QLLR jaclog(QLLR a, QLLR b) const
Jacobian logarithm.
Definition llr.h:280
QLLR to_qllr(double l) const
Convert a "real" LLR value to an LLR type.
Definition llr.h:245
Mat< QLLR > QLLRmat
Definition llr.h:56
QLLR logexp(QLLR x) const
Logexp operator.
Definition llr.h:261
double to_double(QLLR l) const
Convert an LLR type to a "real" LLR.
Definition llr.h:240
const QLLR QLLR_MAX
Definition llr.h:61
Vec< QLLR > QLLRvec
Definition llr.h:51
Matrix Class (Templated)
Definition mat.h:202
Vector Class (Templated)
Definition vec.h:245
#define it_info_debug(s)
Print information message if NDEBUG is not defined.
Definition itassert.h:163
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Definition itassert.h:107
Matrix Class Definitions.
Various functions on vectors and matrices - header file.
itpp namespace
Definition itmex.h:37
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition binary.cpp:36
Definitions of special vectors and matrices.
Templated Vector Class Definitions.
SourceForge Logo

Generated on Mon Jun 10 2024 11:49:21 for IT++ by Doxygen 1.9.8