IT++ Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
convcode.h
Go to the documentation of this file.
1 
29 #ifndef CONVCODE_H
30 #define CONVCODE_H
31 
32 #include <itpp/base/vec.h>
33 #include <itpp/base/mat.h>
34 #include <itpp/base/array.h>
35 #include <itpp/base/binary.h>
36 #include <itpp/comm/channel_code.h>
37 
38 
39 namespace itpp
40 {
41 
46 enum CONVOLUTIONAL_CODE_TYPE {MFD, ODS};
47 
52 enum CONVOLUTIONAL_CODE_METHOD {Trunc, Tail, Tailbite};
53 
103 {
104 public:
106  Convolutional_Code(void): K(0), start_state(0), cc_method(Tail) {
107  set_code(MFD, 2, 7);
108  init_encoder();
109  }
110 
112  virtual ~Convolutional_Code(void) {}
113 
116  cc_method = method;
117  }
118 
126  void set_code(const CONVOLUTIONAL_CODE_TYPE type_of_code, int inverse_rate,
127  int constraint_length);
128 
130  void set_generator_polynomials(const ivec &gen, int constraint_length);
132  ivec get_generator_polynomials(void) const { return gen_pol; }
133 
135  void reset();
136 
137 
139 
140  virtual void encode(const bvec &input, bvec &output);
141  virtual bvec encode(const bvec &input) {
142  bvec output;
143  encode(input, output);
144  return output;
145  }
147 
149 
155  void encode_trunc(const bvec &input, bvec &output);
156  bvec encode_trunc(const bvec &input) {
157  bvec output;
158  encode_trunc(input, output);
159  return output;
160  }
162 
164 
174  void encode_tail(const bvec &input, bvec &output);
175  bvec encode_tail(const bvec &input) {
176  bvec output;
177  encode_tail(input, output);
178  return output;
179  }
181 
183 
197  void encode_tailbite(const bvec &input, bvec &output);
198  bvec encode_tailbite(const bvec &input) {
199  bvec output;
200  encode_tailbite(input, output);
201  return output;
202  }
204 
206 
211  void encode_bit(const bin &input, bvec &output);
212  bvec encode_bit(const bin &input) {
213  bvec output;
214  encode_bit(input, output);
215  return output;
216  }
218 
219  // ------------ Hard-decision decoding is not implemented ----------------
220  virtual void decode(const bvec &coded_bits, bvec &decoded_bits);
221  virtual bvec decode(const bvec &coded_bits);
222 
224 
225  virtual void decode(const vec &received_signal, bvec &output);
226  virtual bvec decode(const vec &received_signal) {
227  bvec output;
228  decode(received_signal, output);
229  return output;
230  }
232 
234 
240  virtual void decode_tail(const vec &received_signal, bvec &output);
241  virtual bvec decode_tail(const vec &received_signal) {
242  bvec output;
243  decode_tail(received_signal, output);
244  return output;
245  }
247 
249 
257  virtual void decode_tailbite(const vec &received_signal, bvec &output);
258  virtual bvec decode_tailbite(const vec &received_signal) {
259  bvec output;
260  decode_tailbite(received_signal, output);
261  return output;
262  }
264 
266 
267  virtual void decode_trunc(const vec &received_signal, bvec &output);
268  virtual bvec decode_trunc(const vec &received_signal) {
269  bvec output;
270  decode_trunc(received_signal, output);
271  return output;
272  }
274 
275 
277  virtual double get_rate(void) const { return rate; }
278 
279 
281  void set_start_state(int state) {
282  it_error_if((state < 0) || ((state >= (1 << m)) && m != 0),
283  "Convolutional_Code::set_start_state(): Invalid start state");
284  start_state = state;
285  }
286 
292 
294  int get_encoder_state(void) const { return encoder_state; }
295 
296 
298  void set_truncation_length(const int length) {
299  it_error_if(length < K, "Convolutional_Code::set_truncation_length(): "
300  "Truncation length shorter than K");
302  }
303 
305  int get_truncation_length(void) const { return trunc_length; }
306 
307 
309  bool catastrophic(void);
310 
311 
320  bool inverse_tail(const bvec coded_sequence, bvec &input);
321 
322 
325  void distance_profile(ivec &dist_prof, int dmax = 100000,
326  bool reverse = false);
327 
343  void calculate_spectrum(Array<ivec> &spectrum, int dmax, int no_terms);
344 
367  int fast(Array<ivec> &spectrum, const int dfree, const int no_terms,
368  const int Cdfree = 1000000, const bool test_catastrophic = false);
369 
370 protected:
372  int next_state(const int instate, const int input) {
373  return ((instate >> 1) | (input << (m - 1)));
374  }
376  int previous_state(const int state, const int input) {
377  return (((state << 1) | input) & ((1 << m) - 1));
378  }
380  void previous_state(const int state, int &S0, int &S1) {
381  S0 = (state << 1) & (no_states - 1);
382  S1 = S0 | 1;
383  }
385  int weight(const int state, const int input);
387  void weight(const int state, int &w0, int &w1);
390  int weight_reverse(const int state, const int input);
393  void weight_reverse(const int state, int &w0, int &w1);
395  bvec output_reverse(const int state, const int input);
397  void output_reverse(const int state, bvec &zero_output, bvec &one_output);
399  void output_reverse(const int state, int &zero_output, int &one_output);
401  void calc_metric_reverse(const int state, const vec &rx_codeword,
402  double &zero_metric, double &one_metric);
404  void calc_metric(const vec &rx_codeword, vec &delta_metrics);
406  int get_input(const int state) { return (state >> (m - 1)); }
407 
409  int n;
411  int K;
413  int m;
417  ivec gen_pol;
427  double rate;
444 };
445 
446 // --------------- Some other functions that maybe should be moved -----------
451 int reverse_int(int length, int in);
452 
457 int weight_int(int length, int in);
458 
463 int compare_spectra(ivec v1, ivec v2);
464 
471 int compare_spectra(ivec v1, ivec v2, vec weight_profile);
472 
473 } // namespace itpp
474 
475 #endif // #ifndef CONVCODE_H
SourceForge Logo

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