llr.h
Go to the documentation of this file.
#ifndef LLR_H
#define LLR_H
#include <limits>
#include <itpp/base/vec.h>
#include <itpp/base/mat.h>
#include <itpp/base/specmat.h>
#include <itpp/base/matfunc.h>
#include <limits>
#include <itpp/itexports.h>
namespace itpp
{
typedef signed int QLLR;
typedef Vec<QLLR> QLLRvec;
typedef Mat<QLLR> QLLRmat;
const QLLR QLLR_MAX = (std::numeric_limits<QLLR>::max() >> 4);
// added some margin to make sure the sum of two LLR is still permissible
class ITPP_EXPORT LLR_calc_unit
{
public:
LLR_calc_unit();
LLR_calc_unit(short int Dint1, short int Dint2, short int Dint3);
void init_llr_tables(short int Dint1 = 12, short int Dint2 = 300,
short int Dint3 = 7);
QLLR to_qllr(double l) const;
QLLRvec to_qllr(const vec &l) const;
QLLRmat to_qllr(const mat &l) const;
double to_double(QLLR l) const;
vec to_double(const QLLRvec &l) const;
mat to_double(const QLLRmat &l) const;
inline QLLR jaclog(QLLR a, QLLR b) const;
// Note: a version of this function taking "double" values as input
// is deliberately omitted, because this is rather slow.
QLLR Boxplus(QLLR a, QLLR b) const;
inline QLLR logexp(QLLR x) const;
ivec get_Dint();
friend ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const LLR_calc_unit &l);
private:
ivec construct_logexp_table();
ivec logexp_table;
short int Dint1, Dint2, Dint3;
};
ITPP_EXPORT std::ostream &operator<<(std::ostream &os, const LLR_calc_unit &lcu);
// ----------------------------------------------------------------------
// implementation of some inline functions
// ----------------------------------------------------------------------
inline double LLR_calc_unit::to_double(QLLR l) const
{
return static_cast<double>(l) / (1 << Dint1);
}
inline QLLR LLR_calc_unit::to_qllr(double l) const
{
double QLLR_MAX_double = to_double(QLLR_MAX);
// Don't abort when overflow occurs, just saturate the QLLR
if (l > QLLR_MAX_double) {
it_info_debug("LLR_calc_unit::to_qllr(): LLR overflow");
return QLLR_MAX;
}
if (l < -QLLR_MAX_double) {
it_info_debug("LLR_calc_unit::to_qllr(): LLR overflow");
return -QLLR_MAX;
}
return static_cast< QLLR >(std::floor(0.5 + (1 << Dint1) * l));
}
inline QLLR LLR_calc_unit::logexp(QLLR x) const
{
it_assert_debug(x >= 0, "LLR_calc_unit::logexp(): Wrong LLR value");
int ind = x >> Dint3;
if (ind >= Dint2) // outside table
return 0;
it_assert_debug(ind >= 0, "LLR_calc_unit::logexp(): Internal error");
it_assert_debug(ind < Dint2, "LLR_calc_unit::logexp(): internal error");
// With interpolation
// int delta=x-(ind<<Dint3);
// return ((delta*logexp_table(ind+1) + ((1<<Dint3)-delta)*logexp_table(ind)) >> Dint3);
// Without interpolation
return logexp_table(ind);
}
inline QLLR LLR_calc_unit::jaclog(QLLR a, QLLR b) const
{
QLLR x, maxab;
if (a > b) {
maxab = a;
x = a - b;
}
else {
maxab = b;
x = b - a;
}
if (maxab >= QLLR_MAX)
return QLLR_MAX;
else
return (maxab + logexp(x));
}
}
#endif
itpp::Array
General array class.
Definition array.h:105
itpp::Array::operator<<
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
itpp::LLR_calc_unit
Log-likelihood algebra calculation unit.
Definition llr.h:125
itpp::LLR_calc_unit::QLLR
signed int QLLR
Definition llr.h:46
itpp::LLR_calc_unit::jaclog
QLLR jaclog(QLLR a, QLLR b) const
Jacobian logarithm.
Definition llr.h:280
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::QLLR_MAX
const QLLR QLLR_MAX
Definition llr.h:61
itpp::LLR_calc_unit::QLLRvec
Vec< QLLR > QLLRvec
Definition llr.h:51
itpp::Mat
Matrix Class (Templated)
Definition mat.h:202
itpp::Vec
Vector Class (Templated)
Definition vec.h:245
it_info_debug
#define it_info_debug(s)
Print information message if NDEBUG is not defined.
Definition itassert.h:163
it_assert_debug
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Definition itassert.h:107
mat.h
Matrix Class Definitions.
matfunc.h
Various functions on vectors and matrices - header file.
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
specmat.h
Definitions of special vectors and matrices.
vec.h
Templated Vector Class Definitions.

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