IT++ Logo
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 #include <itpp/itexports.h>
38 #include <itpp/base/base_exports.h>
39 
40 namespace itpp
41 {
42 
47 enum CONVOLUTIONAL_CODE_TYPE {MFD, ODS};
48 
53 enum CONVOLUTIONAL_CODE_METHOD {Trunc, Tail, Tailbite};
54 
55 
104 class ITPP_EXPORT Convolutional_Code : public Channel_Code
105 {
106 public:
108  Convolutional_Code(void): K(0), start_state(0), cc_method(Tail) {
109  set_code(MFD, 2, 7);
110  init_encoder();
111  }
112 
114  virtual ~Convolutional_Code(void) {}
115 
118  cc_method = method;
119  }
120 
128  void set_code(const CONVOLUTIONAL_CODE_TYPE type_of_code, int inverse_rate,
129  int constraint_length);
130 
132  void set_generator_polynomials(const ivec &gen, int constraint_length);
134  ivec get_generator_polynomials(void) const { return gen_pol; }
135 
137  void reset();
138 
139 
141  virtual void encode(const bvec &input, bvec &output);
143  virtual bvec encode(const bvec &input) {
144  bvec output;
145  encode(input, output);
146  return output;
147  }
149 
151 
157  void encode_trunc(const bvec &input, bvec &output);
158  bvec encode_trunc(const bvec &input) {
159  bvec output;
160  encode_trunc(input, output);
161  return output;
162  }
164 
166 
176  void encode_tail(const bvec &input, bvec &output);
177  bvec encode_tail(const bvec &input) {
178  bvec output;
179  encode_tail(input, output);
180  return output;
181  }
183 
185 
199  void encode_tailbite(const bvec &input, bvec &output);
200  bvec encode_tailbite(const bvec &input) {
201  bvec output;
202  encode_tailbite(input, output);
203  return output;
204  }
206 
208 
213  void encode_bit(const bin &input, bvec &output);
214  bvec encode_bit(const bin &input) {
215  bvec output;
216  encode_bit(input, output);
217  return output;
218  }
220 
221  // ------------ Hard-decision decoding is not implemented ----------------
222  virtual void decode(const bvec &coded_bits, bvec &decoded_bits);
223  virtual bvec decode(const bvec &coded_bits);
224 
226  virtual void decode(const vec &received_signal, bvec &output);
228  virtual bvec decode(const vec &received_signal) {
229  bvec output;
230  decode(received_signal, output);
231  return output;
232  }
234 
236 
242  virtual void decode_tail(const vec &received_signal, bvec &output);
243  virtual bvec decode_tail(const vec &received_signal) {
244  bvec output;
245  decode_tail(received_signal, output);
246  return output;
247  }
249 
251 
259  virtual void decode_tailbite(const vec &received_signal, bvec &output);
260  virtual bvec decode_tailbite(const vec &received_signal) {
261  bvec output;
262  decode_tailbite(received_signal, output);
263  return output;
264  }
266 
268  virtual void decode_trunc(const vec &received_signal, bvec &output);
270  virtual bvec decode_trunc(const vec &received_signal) {
271  bvec output;
272  decode_trunc(received_signal, output);
273  return output;
274  }
276 
277 
279  virtual double get_rate(void) const { return rate; }
280 
281 
283  void set_start_state(int state) {
284  it_error_if((state < 0) || ((state >= (1 << m)) && m != 0),
285  "Convolutional_Code::set_start_state(): Invalid start state");
286  start_state = state;
287  }
288 
293  void init_encoder() { encoder_state = start_state; }
294 
296  int get_encoder_state(void) const { return encoder_state; }
297 
298 
300  void set_truncation_length(const int length) {
301  it_error_if(length < K, "Convolutional_Code::set_truncation_length(): "
302  "Truncation length shorter than K");
303  trunc_length = length;
304  }
305 
307  int get_truncation_length(void) const { return trunc_length; }
308 
309 
311  bool catastrophic(void);
312 
313 
322  bool inverse_tail(const bvec coded_sequence, bvec &input);
323 
324 
327  void distance_profile(ivec &dist_prof, int dmax = 100000,
328  bool reverse = false);
329 
345  void calculate_spectrum(Array<ivec> &spectrum, int dmax, int no_terms);
346 
369  int fast(Array<ivec> &spectrum, const int dfree, const int no_terms,
370  const int Cdfree = 1000000, const bool test_catastrophic = false);
371 
372 protected:
374  int next_state(const int instate, const int input) {
375  return ((instate >> 1) | (input << (m - 1)));
376  }
378  int previous_state(const int state, const int input) {
379  return (((state << 1) | input) & ((1 << m) - 1));
380  }
382  void previous_state(const int state, int &S0, int &S1) {
383  S0 = (state << 1) & (no_states - 1);
384  S1 = S0 | 1;
385  }
387  int weight(const int state, const int input);
389  void weight(const int state, int &w0, int &w1);
392  int weight_reverse(const int state, const int input);
395  void weight_reverse(const int state, int &w0, int &w1);
397  bvec output_reverse(const int state, const int input);
399  void output_reverse(const int state, bvec &zero_output, bvec &one_output);
401  void output_reverse(const int state, int &zero_output, int &one_output);
403  void calc_metric_reverse(const int state, const vec &rx_codeword,
404  double &zero_metric, double &one_metric);
406  void calc_metric(const vec &rx_codeword, vec &delta_metrics);
408  int get_input(const int state) { return (state >> (m - 1)); }
409 
411  int n;
413  int K;
415  int m;
419  ivec gen_pol;
429  double rate;
446 };
447 
448 // --------------- Some other functions that maybe should be moved -----------
453 ITPP_EXPORT int reverse_int(int length, int in);
454 
459 ITPP_EXPORT int weight_int(int length, int in);
460 
465 ITPP_EXPORT int compare_spectra(ivec v1, ivec v2);
466 
473 ITPP_EXPORT int compare_spectra(ivec v1, ivec v2, vec weight_profile);
474 
475 } // namespace itpp
476 
477 #endif // #ifndef CONVCODE_H
#define it_error_if(t, s)
Abort if t is true.
Definition: itassert.h:117
void set_method(const CONVOLUTIONAL_CODE_METHOD method)
Set encoding and decoding method (Trunc, Tail, or Tailbite)
Definition: convcode.h:117
bvec encode_tail(const bvec &input)
Encoding that starts and ends in the zero state.
Definition: convcode.h:177
int K
Constraint length.
Definition: convcode.h:413
int reverse_int(int length, int in)
Definition: convcode.cpp:1442
Binary Convolutional rate 1/n class.
Definition: convcode.h:104
Vec< T > reverse(const Vec< T > &in)
Reverse the input vector.
Definition: matfunc.h:777
int trunc_length
The decoder truncation length.
Definition: convcode.h:427
virtual bvec decode_trunc(const vec &received_signal)
Viterbi decoding using truncation of memory (default = 5*K)
Definition: convcode.h:270
Array< bool > visited_state
Visited states.
Definition: convcode.h:439
int get_encoder_state(void) const
Get the current encoder state.
Definition: convcode.h:296
imat output_reverse_int
output in int format for a given state and input
Definition: convcode.h:433
Binary class definition.
virtual bvec encode(const bvec &input)
Encode an input binary vector using specified method (Tail by default)
Definition: convcode.h:143
int weight_int(int length, int in)
Definition: convcode.cpp:1460
bvec xor_int_table
Auxilary table used by the codec.
Definition: convcode.h:431
int next_state(const int instate, const int input)
Next state from instate given the input.
Definition: convcode.h:374
ivec get_generator_polynomials(void) const
Get generator polynomials.
Definition: convcode.h:134
int get_truncation_length(void) const
Get memory truncation length.
Definition: convcode.h:307
int length(const Vec< T > &v)
Length of vector.
Definition: matfunc.h:51
void set_start_state(int state)
Set encoder default start state.
Definition: convcode.h:283
int no_states
Number of states.
Definition: convcode.h:417
Generic Channel Code class.
Definition: channel_code.h:50
int weight(const bvec &a)
Calculate the Hamming weight of a.
Definition: commfunc.cpp:71
Definition of Array class (container)
int trunc_state
Truncated memory fill state.
Definition: convcode.h:445
virtual bvec decode(const vec &received_signal)
Decode a block of encoded data using specified method (Tail by default)
Definition: convcode.h:228
int m
Memory of the encoder.
Definition: convcode.h:415
CONVOLUTIONAL_CODE_TYPE
Type of Convolutional Code.
Definition: convcode.h:47
Import/Export definitions for some templates defined in base folder.
Matrix Class Definitions.
ivec gen_pol_rev
Generator polynomials for the reverse code.
Definition: convcode.h:421
virtual ~Convolutional_Code(void)
Destructor.
Definition: convcode.h:114
Channel Code class virtual interface.
bvec encode_trunc(const bvec &input)
Encode a binary vector starting from the previous encoder state.
Definition: convcode.h:158
virtual bvec decode_tail(const vec &received_signal)
Decode a block of encoded data where encode_tail has been used.
Definition: convcode.h:243
int encoder_state
The current encoder state.
Definition: convcode.h:423
vec spectrum(const vec &v, int nfft, int noverlap)
Power spectrum calculation.
Definition: sigfun.cpp:267
itpp namespace
Definition: itmex.h:36
virtual bvec decode_tailbite(const vec &received_signal)
Decode a block of encoded data where encode_tailbite has been used.
Definition: convcode.h:260
CONVOLUTIONAL_CODE_METHOD
Encoding and decoding methods for Convolutional codes.
Definition: convcode.h:53
bvec encode_tailbite(const bvec &input)
Encode an input binary vector using tailbiting.
Definition: convcode.h:200
void set_truncation_length(const int length)
Set memory truncation length. Must be at least K.
Definition: convcode.h:300
Convolutional_Code(void)
Default constructor - sets (0133,0171) code with tail.
Definition: convcode.h:108
double rate
The rate of the code.
Definition: convcode.h:429
int n
Number of generators.
Definition: convcode.h:411
int start_state
The encoder start state.
Definition: convcode.h:425
int trunc_ptr
Truncated path memory pointer.
Definition: convcode.h:443
Binary arithmetic (boolean) class.
Definition: binary.h:56
int previous_state(const int state, const int input)
The previous state from state given the input.
Definition: convcode.h:378
void init_encoder()
Initialise internal encoder state with start state. Has no effect on Tail and Tailbite methods...
Definition: convcode.h:293
bvec encode_bit(const bin &input)
Encode a binary bit starting from the internal encoder state.
Definition: convcode.h:214
void previous_state(const int state, int &S0, int &S1)
The previous state from state given the input.
Definition: convcode.h:382
virtual double get_rate(void) const
Return rate of code (not including the rate-loss)
Definition: convcode.h:279
CONVOLUTIONAL_CODE_METHOD cc_method
encoding and decoding method
Definition: convcode.h:435
int get_input(const int state)
Returns the input that results in state, that is the MSB of state.
Definition: convcode.h:408
int compare_spectra(ivec v1, ivec v2)
Definition: convcode.cpp:1472
ivec gen_pol
Generator polynomials.
Definition: convcode.h:419
vec sum_metric
Metrics accumulator.
Definition: convcode.h:441
imat path_memory
Path memory (trellis)
Definition: convcode.h:437
Templated Vector Class Definitions.
SourceForge Logo

Generated on Sun Apr 10 2022 12:00:00 for IT++ by Doxygen 1.8.14