IT++ Logo

llr.cpp

Go to the documentation of this file.
00001 
00032 #include <itpp/comm/llr.h>
00033 
00034 
00035 namespace itpp {
00036 
00037   LLR_calc_unit::LLR_calc_unit()
00038   {
00039     init_llr_tables();
00040   }
00041 
00042   LLR_calc_unit::LLR_calc_unit(short int d1, short int d2, short int d3)
00043   {
00044     init_llr_tables(d1,d2,d3);
00045   }
00046 
00047 
00048   void LLR_calc_unit::operator=(const LLR_calc_unit &x)
00049   {
00050     Dint1=x.Dint1;
00051     Dint2=x.Dint2;
00052     Dint3=x.Dint3;
00053     logexp_table=x.logexp_table;
00054   }
00055 
00056 
00057   ivec LLR_calc_unit::get_Dint()
00058   {
00059     ivec r(3);
00060     r(0) = Dint1;
00061     r(1) = Dint2;
00062     r(2) = Dint3;
00063     return r;
00064   }
00065 
00066   void LLR_calc_unit::init_llr_tables(short int d1, short int d2, short int d3)
00067   {
00068     Dint1 = d1;      // 1<<Dint1 determines how integral LLRs relate to real LLRs (to_double=(1<<Dint)*int_llr)
00069     Dint2 = d2;      // number of entries in table for LLR operations
00070     Dint3 = d3;      // table resolution is 2^(-(Dint1-Dint3))
00071     //    cerr << "Initializing LLR tables, Dint1=" << Dint1 << "   Dint2=" << Dint2 << "  Dint3=" << Dint3
00072     //   << "  resoltion: " << pow(2.0,((double) (Dint3-Dint1))) << endl;
00073     logexp_table = construct_logexp_table();
00074   }
00075 
00076   ivec LLR_calc_unit::construct_logexp_table()
00077   {
00078     ivec result(Dint2);
00079     for (int i=0; i<Dint2; i++) {
00080       double x = pow2(static_cast<double>(Dint3 - Dint1)) * i;
00081       result(i) = to_qllr(std::log(1 + std::exp(-x)));
00082     }
00083     it_assert(length(result)==Dint2,"Ldpc_codec::construct_logexp_table()");
00084 
00085     return result;
00086   }
00087 
00088   QLLRvec LLR_calc_unit::to_qllr(const vec &l) const {
00089     int n=length(l);
00090     ivec result(n);
00091     for (int i=0; i<n; i++) {
00092       result.set(i,to_qllr(l(i)));
00093     }
00094     return result;
00095   }
00096 
00097   vec LLR_calc_unit::to_double(const QLLRvec &l) const {
00098     int n=length(l);
00099     vec result(n);
00100     for (int i=0; i<n; i++) {
00101       result.set(i,to_double(l(i)));
00102     }
00103     return result;
00104   }
00105 
00106   QLLRmat LLR_calc_unit::to_qllr(const mat &l)  const {
00107     int m=l.rows();
00108     int n=l.cols();
00109     imat result(m,n);
00110     for (int i=0; i<m; i++) {
00111       for (int j=0; j<n; j++) {
00112   result.set(i,j,to_qllr(l(i,j)));
00113       }
00114     }
00115     return result;
00116   }
00117 
00118   mat LLR_calc_unit::to_double(const QLLRmat &l) const {
00119     int m=l.rows();
00120     int n=l.cols();
00121     mat result(m,n);
00122     for (int i=0; i<m; i++) {
00123       for (int j=0; j<n; j++) {
00124   result.set(i,j,to_double(l(i,j)));
00125       }
00126     }
00127     return result;
00128   }
00129 
00130   std::ostream &operator<<(std::ostream &os, const LLR_calc_unit &lcu)
00131   {
00132     os << "---------- LLR calculation unit -----------------" << std::endl;
00133     os << "LLR_calc_unit table properties:" << std::endl;
00134     os << "The granularity in the LLR representation is "
00135        << pow2(static_cast<double>(-lcu.Dint1)) << std::endl;
00136     os << "The LLR scale factor is " << (1 << lcu.Dint1) << std::endl;
00137     os << "The largest LLR that can be represented is "
00138        << lcu.to_double(QLLR_MAX) << std::endl;
00139     os << "The table resolution is "
00140        << pow2(static_cast<double>(lcu.Dint3 - lcu.Dint1)) << std::endl;
00141     os << "The number of entries in the table is " << lcu.Dint2 << std::endl;
00142     os << "The tables truncates at the LLR value "
00143        << pow2(static_cast<double>(lcu.Dint3 - lcu.Dint1)) * lcu.Dint2
00144        << std::endl;
00145     os << "-------------------------------------------------" << std::endl;
00146     return os;
00147   }
00148 
00149 }
SourceForge Logo

Generated on Sun Sep 14 18:52:35 2008 for IT++ by Doxygen 1.5.6