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 00046 enum CONVOLUTIONAL_CODE_TYPE {MFD, ODS}; 00047 00052 enum CONVOLUTIONAL_CODE_METHOD {Trunc, Tail, Tailbite}; 00053 00102 class Convolutional_Code : public Channel_Code { 00103 public: 00105 Convolutional_Code(void): K(0), start_state(0), cc_method(Tail) 00106 { 00107 set_code(MFD, 2, 7); 00108 init_encoder(); 00109 } 00110 00112 virtual ~Convolutional_Code(void) {} 00113 00115 void set_method(const CONVOLUTIONAL_CODE_METHOD method) 00116 { 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 { 00144 bvec output; encode(input, output); return output; 00145 } 00147 00149 00155 void encode_trunc(const bvec &input, bvec &output); 00156 bvec encode_trunc(const bvec &input) 00157 { 00158 bvec output; encode_trunc(input, output); return output; 00159 } 00161 00163 00173 void encode_tail(const bvec &input, bvec &output); 00174 bvec encode_tail(const bvec &input) 00175 { 00176 bvec output; encode_tail(input, output); return output; 00177 } 00179 00181 00195 void encode_tailbite(const bvec &input, bvec &output); 00196 bvec encode_tailbite(const bvec &input) 00197 { 00198 bvec output; encode_tailbite(input, output); return output; 00199 } 00201 00203 00208 void encode_bit(const bin &input, bvec &output); 00209 bvec encode_bit(const bin &input) 00210 { 00211 bvec output; encode_bit(input, output); return output; 00212 } 00214 00215 // ------------ Hard-decision decoding is not implemented ---------------- 00216 virtual void decode(const bvec &coded_bits, bvec &decoded_bits); 00217 virtual bvec decode(const bvec &coded_bits); 00218 00220 00221 virtual void decode(const vec &received_signal, bvec &output); 00222 virtual bvec decode(const vec &received_signal) 00223 { 00224 bvec output; decode(received_signal, output); return output; 00225 } 00227 00229 00235 virtual void decode_tail(const vec &received_signal, bvec &output); 00236 virtual bvec decode_tail(const vec &received_signal) 00237 { 00238 bvec output; decode_tail(received_signal, output); return output; 00239 } 00241 00243 00251 virtual void decode_tailbite(const vec &received_signal, bvec &output); 00252 virtual bvec decode_tailbite(const vec &received_signal) 00253 { 00254 bvec output; decode_tailbite(received_signal, output); return output; 00255 } 00257 00259 00260 virtual void decode_trunc(const vec &received_signal, bvec &output); 00261 virtual bvec decode_trunc(const vec &received_signal) 00262 { 00263 bvec output; decode_trunc(received_signal, output); return output; 00264 } 00266 00267 00269 virtual double get_rate(void) const { return rate; } 00270 00271 00273 void set_start_state(int state) 00274 { 00275 it_error_if((state < 0) || ((state >= (1 << m)) && m != 0), 00276 "Convolutional_Code::set_start_state(): Invalid start state"); 00277 start_state = state; 00278 } 00279 00284 void init_encoder() { encoder_state = start_state; } 00285 00287 int get_encoder_state(void) const { return encoder_state; } 00288 00289 00291 void set_truncation_length(const int length) 00292 { 00293 it_error_if(length < K, "Convolutional_Code::set_truncation_length(): " 00294 "Truncation length shorter than K"); 00295 trunc_length = length; 00296 } 00297 00299 int get_truncation_length(void) const { return trunc_length; } 00300 00301 00303 bool catastrophic(void); 00304 00305 00314 bool inverse_tail(const bvec coded_sequence, bvec &input); 00315 00316 00319 void distance_profile(ivec &dist_prof, int dmax = 100000, 00320 bool reverse = false); 00321 00337 void calculate_spectrum(Array<ivec> &spectrum, int dmax, int no_terms); 00338 00361 int fast(Array<ivec> &spectrum, const int dfree, const int no_terms, 00362 const int Cdfree = 1000000, const bool test_catastrophic = false); 00363 00364 protected: 00366 int next_state(const int instate, const int input) 00367 { 00368 return ((instate >> 1) | (input << (m - 1))); 00369 } 00371 int previous_state(const int state, const int input) 00372 { 00373 return (((state << 1) | input) & ((1 << m) - 1)); 00374 } 00376 void previous_state(const int state, int &S0, int &S1) 00377 { 00378 S0 = (state << 1) & (no_states - 1); 00379 S1 = S0 | 1; 00380 } 00382 int weight(const int state, const int input); 00384 void weight(const int state, int &w0, int &w1); 00387 int weight_reverse(const int state, const int input); 00390 void weight_reverse(const int state, int &w0, int &w1); 00392 bvec output_reverse(const int state, const int input); 00394 void output_reverse(const int state, bvec &zero_output, bvec &one_output); 00396 void output_reverse(const int state, int &zero_output, int &one_output); 00398 void calc_metric_reverse(const int state, const vec &rx_codeword, 00399 double &zero_metric, double &one_metric); 00401 void calc_metric(const vec &rx_codeword, vec &delta_metrics); 00403 int get_input(const int state) { return (state >> (m - 1)); } 00404 00406 int n; 00408 int K; 00410 int m; 00412 int no_states; 00414 ivec gen_pol; 00416 ivec gen_pol_rev; 00418 int encoder_state; 00420 int start_state; 00422 int trunc_length; 00424 double rate; 00426 bvec xor_int_table; 00428 imat output_reverse_int; 00430 CONVOLUTIONAL_CODE_METHOD cc_method; 00432 imat path_memory; 00434 Array<bool> visited_state; 00436 vec sum_metric; 00438 int trunc_ptr; 00440 int trunc_state; 00441 }; 00442 00443 // --------------- Some other functions that maybe should be moved ----------- 00448 int reverse_int(int length, int in); 00449 00454 int weight_int(int length, int in); 00455 00460 int compare_spectra(ivec v1, ivec v2); 00461 00468 int compare_spectra(ivec v1, ivec v2, vec weight_profile); 00469 00470 } // namespace itpp 00471 00472 #endif // #ifndef CONVCODE_H
Generated on Sun Apr 20 12:40:06 2008 for IT++ by Doxygen 1.5.5