IT++ Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
39 namespace itpp
40 {
41 
45 typedef signed int QLLR;
46 
51 
56 
60 const QLLR QLLR_MAX = (std::numeric_limits<QLLR>::max() >> 4);
61 // added some margin to make sure the sum of two LLR is still permissible
62 
124 {
125 public:
127  LLR_calc_unit();
128 
134  LLR_calc_unit(short int Dint1, short int Dint2, short int Dint3);
135 
164  void init_llr_tables(short int Dint1 = 12, short int Dint2 = 300,
165  short int Dint3 = 7);
166 
168  QLLR to_qllr(double l) const;
169 
171  QLLRvec to_qllr(const vec &l) const;
172 
174  QLLRmat to_qllr(const mat &l) const;
175 
177  double to_double(QLLR l) const;
178 
180  vec to_double(const QLLRvec &l) const;
181 
183  mat to_double(const QLLRmat &l) const;
184 
190  inline QLLR jaclog(QLLR a, QLLR b) const;
191  // Note: a version of this function taking "double" values as input
192  // is deliberately omitted, because this is rather slow.
193 
202  QLLR Boxplus(QLLR a, QLLR b) const;
203 
209  inline QLLR logexp(QLLR x) const;
210 
212  ivec get_Dint();
213 
215  friend std::ostream &operator<<(std::ostream &os, const LLR_calc_unit &l);
216 
217 private:
219  ivec construct_logexp_table();
220 
222  ivec logexp_table;
223 
225  short int Dint1, Dint2, Dint3;
226 };
227 
232 std::ostream &operator<<(std::ostream &os, const LLR_calc_unit &lcu);
233 
234 
235 // ----------------------------------------------------------------------
236 // implementation of some inline functions
237 // ----------------------------------------------------------------------
238 
239 inline double LLR_calc_unit::to_double(QLLR l) const
240 {
241  return static_cast<double>(l) / (1 << Dint1);
242 }
243 
244 inline QLLR LLR_calc_unit::to_qllr(double l) const
245 {
246  double QLLR_MAX_double = to_double(QLLR_MAX);
247  // Don't abort when overflow occurs, just saturate the QLLR
248  if (l > QLLR_MAX_double) {
249  it_info_debug("LLR_calc_unit::to_qllr(): LLR overflow");
250  return QLLR_MAX;
251  }
252  if (l < -QLLR_MAX_double) {
253  it_info_debug("LLR_calc_unit::to_qllr(): LLR overflow");
254  return -QLLR_MAX;
255  }
256  return static_cast<QLLR>(std::floor(0.5 + (1 << Dint1) * l));
257 }
258 
259 
261 {
262  it_assert_debug(x >= 0, "LLR_calc_unit::logexp(): Wrong LLR value");
263  int ind = x >> Dint3;
264  if (ind >= Dint2) // outside table
265  return 0;
266 
267  it_assert_debug(ind >= 0, "LLR_calc_unit::logexp(): Internal error");
268  it_assert_debug(ind < Dint2, "LLR_calc_unit::logexp(): internal error");
269 
270  // With interpolation
271  // int delta=x-(ind<<Dint3);
272  // return ((delta*logexp_table(ind+1) + ((1<<Dint3)-delta)*logexp_table(ind)) >> Dint3);
273 
274  // Without interpolation
275  return logexp_table(ind);
276 }
277 
278 
280 {
281  QLLR x, maxab;
282 
283  if (a > b) {
284  maxab = a;
285  x = a - b;
286  }
287  else {
288  maxab = b;
289  x = b - a;
290  }
291 
292  if (maxab >= QLLR_MAX)
293  return QLLR_MAX;
294  else
295  return (maxab + logexp(x));
296 }
297 
298 }
299 
300 #endif
SourceForge Logo

Generated on Fri Mar 21 2014 17:14:13 for IT++ by Doxygen 1.8.1.2