00001 00030 #ifndef CONVCODE_H 00031 #define CONVCODE_H 00032 00033 #include <itpp/base/vec.h> 00034 #include <itpp/base/mat.h> 00035 #include <itpp/base/array.h> 00036 #include <itpp/base/binary.h> 00037 #include <itpp/comm/channel_code.h> 00038 00039 00040 namespace itpp 00041 { 00042 00047 enum CONVOLUTIONAL_CODE_TYPE {MFD, ODS}; 00048 00053 enum CONVOLUTIONAL_CODE_METHOD {Trunc, Tail, Tailbite}; 00054 00103 class Convolutional_Code : public Channel_Code 00104 { 00105 public: 00107 Convolutional_Code(void): K(0), start_state(0), cc_method(Tail) { 00108 set_code(MFD, 2, 7); 00109 init_encoder(); 00110 } 00111 00113 virtual ~Convolutional_Code(void) {} 00114 00116 void set_method(const CONVOLUTIONAL_CODE_METHOD method) { 00117 cc_method = method; 00118 } 00119 00127 void set_code(const CONVOLUTIONAL_CODE_TYPE type_of_code, int inverse_rate, 00128 int constraint_length); 00129 00131 void set_generator_polynomials(const ivec &gen, int constraint_length); 00133 ivec get_generator_polynomials(void) const { return gen_pol; } 00134 00136 void reset(); 00137 00138 00140 00141 virtual void encode(const bvec &input, bvec &output); 00142 virtual bvec encode(const bvec &input) { 00143 bvec output; 00144 encode(input, output); 00145 return output; 00146 } 00148 00150 00156 void encode_trunc(const bvec &input, bvec &output); 00157 bvec encode_trunc(const bvec &input) { 00158 bvec output; 00159 encode_trunc(input, output); 00160 return output; 00161 } 00163 00165 00175 void encode_tail(const bvec &input, bvec &output); 00176 bvec encode_tail(const bvec &input) { 00177 bvec output; 00178 encode_tail(input, output); 00179 return output; 00180 } 00182 00184 00198 void encode_tailbite(const bvec &input, bvec &output); 00199 bvec encode_tailbite(const bvec &input) { 00200 bvec output; 00201 encode_tailbite(input, output); 00202 return output; 00203 } 00205 00207 00212 void encode_bit(const bin &input, bvec &output); 00213 bvec encode_bit(const bin &input) { 00214 bvec output; 00215 encode_bit(input, output); 00216 return output; 00217 } 00219 00220 // ------------ Hard-decision decoding is not implemented ---------------- 00221 virtual void decode(const bvec &coded_bits, bvec &decoded_bits); 00222 virtual bvec decode(const bvec &coded_bits); 00223 00225 00226 virtual void decode(const vec &received_signal, bvec &output); 00227 virtual bvec decode(const vec &received_signal) { 00228 bvec output; 00229 decode(received_signal, output); 00230 return output; 00231 } 00233 00235 00241 virtual void decode_tail(const vec &received_signal, bvec &output); 00242 virtual bvec decode_tail(const vec &received_signal) { 00243 bvec output; 00244 decode_tail(received_signal, output); 00245 return output; 00246 } 00248 00250 00258 virtual void decode_tailbite(const vec &received_signal, bvec &output); 00259 virtual bvec decode_tailbite(const vec &received_signal) { 00260 bvec output; 00261 decode_tailbite(received_signal, output); 00262 return output; 00263 } 00265 00267 00268 virtual void decode_trunc(const vec &received_signal, bvec &output); 00269 virtual bvec decode_trunc(const vec &received_signal) { 00270 bvec output; 00271 decode_trunc(received_signal, output); 00272 return output; 00273 } 00275 00276 00278 virtual double get_rate(void) const { return rate; } 00279 00280 00282 void set_start_state(int state) { 00283 it_error_if((state < 0) || ((state >= (1 << m)) && m != 0), 00284 "Convolutional_Code::set_start_state(): Invalid start state"); 00285 start_state = state; 00286 } 00287 00292 void init_encoder() { encoder_state = start_state; } 00293 00295 int get_encoder_state(void) const { return encoder_state; } 00296 00297 00299 void set_truncation_length(const int length) { 00300 it_error_if(length < K, "Convolutional_Code::set_truncation_length(): " 00301 "Truncation length shorter than K"); 00302 trunc_length = length; 00303 } 00304 00306 int get_truncation_length(void) const { return trunc_length; } 00307 00308 00310 bool catastrophic(void); 00311 00312 00321 bool inverse_tail(const bvec coded_sequence, bvec &input); 00322 00323 00326 void distance_profile(ivec &dist_prof, int dmax = 100000, 00327 bool reverse = false); 00328 00344 void calculate_spectrum(Array<ivec> &spectrum, int dmax, int no_terms); 00345 00368 int fast(Array<ivec> &spectrum, const int dfree, const int no_terms, 00369 const int Cdfree = 1000000, const bool test_catastrophic = false); 00370 00371 protected: 00373 int next_state(const int instate, const int input) { 00374 return ((instate >> 1) | (input << (m - 1))); 00375 } 00377 int previous_state(const int state, const int input) { 00378 return (((state << 1) | input) & ((1 << m) - 1)); 00379 } 00381 void previous_state(const int state, int &S0, int &S1) { 00382 S0 = (state << 1) & (no_states - 1); 00383 S1 = S0 | 1; 00384 } 00386 int weight(const int state, const int input); 00388 void weight(const int state, int &w0, int &w1); 00391 int weight_reverse(const int state, const int input); 00394 void weight_reverse(const int state, int &w0, int &w1); 00396 bvec output_reverse(const int state, const int input); 00398 void output_reverse(const int state, bvec &zero_output, bvec &one_output); 00400 void output_reverse(const int state, int &zero_output, int &one_output); 00402 void calc_metric_reverse(const int state, const vec &rx_codeword, 00403 double &zero_metric, double &one_metric); 00405 void calc_metric(const vec &rx_codeword, vec &delta_metrics); 00407 int get_input(const int state) { return (state >> (m - 1)); } 00408 00410 int n; 00412 int K; 00414 int m; 00416 int no_states; 00418 ivec gen_pol; 00420 ivec gen_pol_rev; 00422 int encoder_state; 00424 int start_state; 00426 int trunc_length; 00428 double rate; 00430 bvec xor_int_table; 00432 imat output_reverse_int; 00434 CONVOLUTIONAL_CODE_METHOD cc_method; 00436 imat path_memory; 00438 Array<bool> visited_state; 00440 vec sum_metric; 00442 int trunc_ptr; 00444 int trunc_state; 00445 }; 00446 00447 // --------------- Some other functions that maybe should be moved ----------- 00452 int reverse_int(int length, int in); 00453 00458 int weight_int(int length, int in); 00459 00464 int compare_spectra(ivec v1, ivec v2); 00465 00472 int compare_spectra(ivec v1, ivec v2, vec weight_profile); 00473 00474 } // namespace itpp 00475 00476 #endif // #ifndef CONVCODE_H
Generated on Wed Feb 9 2011 13:47:16 for IT++ by Doxygen 1.7.3