IT++ Logo
turbo.h
Go to the documentation of this file.
1 
29 #ifndef TURBO_H
30 #define TURBO_H
31 
33 #include <itpp/comm/interleave.h>
34 #include <itpp/comm/llr.h>
35 #include <itpp/itexports.h>
36 
37 namespace itpp
38 {
39 
41 
42 #if (defined(_MSC_VER) && defined (ITPP_SHARED_LIB))
43 //MSVC explicitely instantiate required template while building the shared library
44 template class ITPP_EXPORT Sequence_Interleaver<bin>;
45 template class ITPP_EXPORT Sequence_Interleaver<double>;
46 #endif
47 
49 
50 
66 class ITPP_EXPORT Turbo_Codec
67 {
68 public:
69 
71  Turbo_Codec(void) {}
72 
74  virtual ~Turbo_Codec(void) {}
75 
99  void set_parameters(ivec gen1, ivec gen2, int constraint_length,
100  const ivec &interleaver_sequence, int in_iterations = 8,
101  const std::string &in_metric = "LOGMAX", double in_logmax_scale_factor = 1.0,
102  bool in_adaptive_stop = false, LLR_calc_unit lcalc = LLR_calc_unit());
103 
110  void set_interleaver(const ivec &interleaver_sequence);
111 
124  void set_metric(std::string in_metric = "LOGMAX", double in_logmax_scale_factor = 1.0,
125  LLR_calc_unit lcalc = LLR_calc_unit());
126 
130  void set_iterations(int in_iterations = 8);
131 
138  void set_adaptive_stop(bool in_adaptive_stop = true);
139 
146  void set_awgn_channel_parameters(double in_Ec, double in_N0);
147 
170  void set_scaling_factor(double in_Lc);
171 
191  void encode(const bvec &input, bvec &output);
192 
204  virtual void decode(const vec &received_signal, bvec &decoded_bits, const bvec &true_bits = "0");
205 
218  virtual void decode(const vec &received_signal, bvec &decoded_bits, ivec &nrof_used_iterations,
219  const bvec &true_bits = "0");
220 
237  void encode_block(const bvec &input, bvec &in1, bvec &in2, bmat &parity1, bmat &parity2);
238 
268  virtual void decode_block(const vec &rec_syst1, const vec &rec_syst2, const mat &rec_parity1, const mat &rec_parity2,
269  bmat &decoded_bits_i, int &nrof_used_iterations_i, const bvec &true_bits = "0");
270 
272  int get_Ncoded() const { return Ncoded; }
273 
275  int get_Nuncoded() const { return Nuncoded; }
276 
277 protected:
278 
282  void decode_n3(const vec &received_signal, bvec &decoded_bits, ivec &nrof_used_iterations,
283  const bvec &true_bits = "0");
284 
285  //Scalars:
286  int interleaver_size;
287  int Ncoded, Nuncoded;
288  int m_tail, n1, n2, n_tot, iterations;
289  double Ec, N0, Lc, R, logmax_scale_factor;
290  bool adaptive_stop;
291  struct ITPP_EXPORT Metric
292  {
293  enum Type {Unknown, LOGMAX, LOGMAP, MAP, TABLE};
294  Metric() : _t(Unknown) {}
295  Metric(Type t) : _t(t) {}
296  operator Type () const {return _t;}
297  private:
298  Type _t;
299  template<typename T> operator T () const;
300  };
301  Metric metric;
302 
303  //Vectors:
304  bvec decoded_bits_previous_iteration;
305 
306  //Classes:
307  Rec_Syst_Conv_Code rscc1, rscc2;
308  Sequence_Interleaver<bin> bit_interleaver;
309  Sequence_Interleaver<double> float_interleaver;
310  static std::string string_from_metric(const Metric& m);
311 };
312 
331 class ITPP_EXPORT Punctured_Turbo_Codec : public Turbo_Codec
332 {
333 public:
334 
336  Punctured_Turbo_Codec(void) { Period = 0; };
337 
339  virtual ~Punctured_Turbo_Codec(void) {}
340 
368  void set_parameters(ivec gen1, ivec gen2, int constraint_length, const ivec &interleaver_sequence, bmat &pmatrix, int in_iterations = 8, std::string in_metric = "LOGMAX", double in_logmax_scale_factor = 1.0, bool in_adaptive_stop = false, itpp::LLR_calc_unit lcalc = itpp::LLR_calc_unit());
369 
375  void set_puncture_matrix(const bmat &pmatrix);
376 
380  bmat get_puncture_matrix(void) { return puncture_matrix; };
381 
385  int get_puncture_period(void) { return Period; };
386 
392  int get_punctured_size(void) { it_assert(Period != 0, "Punctured_Turbo_Codec: puncture matrix is not set"); return pNcoded; };
393 
399  double get_rate(bool nominal = true);
400 
407  int get_coded_size(void) { return Ncoded; };
408 
431  void encode(const bvec &input, bvec &output);
432 
440  bvec encode(const bvec &input);
441 
453  virtual void decode(const vec &received_signal, bvec &decoded_bits, const bvec &true_bits = "0");
454 
464  virtual bvec decode(const vec &received_signal);
465 
478  virtual void decode(const vec &received_signal, bvec &decoded_bits, ivec &nrof_used_iterations,
479  const bvec &true_bits = "0");
480 
493  friend int calculate_uncoded_size(Punctured_Turbo_Codec &tc, int punctured_size, int &fill_bits);
494 
495 protected:
502  void calculate_punctured_size(void);
503 
504  //Scalars:
505  int Period;
506  long pNcoded;
507  int punct_total, punct_total1, punct_total2;
508  double rate;
509  bmat puncture_matrix;
510 };
511 
512 
517 ITPP_EXPORT ivec wcdma_turbo_interleaver_sequence(int interleaver_size);
518 
524 ITPP_EXPORT ivec lte_turbo_interleaver_sequence(int interleaver_size);
525 
526 } // namespace itpp
527 
528 #endif // #ifndef TURBO_H
SourceForge Logo

Generated on Sat Jul 6 2013 10:54:24 for IT++ by Doxygen 1.8.2