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 00150 void encode_trunc(const bvec &input, bvec &output); 00151 bvec encode_trunc(const bvec &input) 00152 { 00153 bvec output; encode_trunc(input, output); return output; 00154 } 00156 00158 00165 void encode_tail(const bvec &input, bvec &output); 00166 bvec encode_tail(const bvec &input) 00167 { 00168 bvec output; encode_tail(input, output); return output; 00169 } 00171 00173 00174 void encode_tailbite(const bvec &input, bvec &output); 00175 bvec encode_tailbite(const bvec &input) 00176 { 00177 bvec output; encode_tailbite(input, output); return output; 00178 } 00180 00182 00187 void encode_bit(const bin &input, bvec &output); 00188 bvec encode_bit(const bin &input) 00189 { 00190 bvec output; encode_bit(input, output); return output; 00191 } 00193 00194 // ------------ Hard-decision decoding is not implemented ------------------- 00195 virtual void decode(const bvec &coded_bits, bvec &decoded_bits); 00196 virtual bvec decode(const bvec &coded_bits); 00197 00199 00200 virtual void decode(const vec &received_signal, bvec &output); 00201 virtual bvec decode(const vec &received_signal) 00202 { 00203 bvec output; decode(received_signal, output); return output; 00204 } 00206 00208 00214 virtual void decode_tail(const vec &received_signal, bvec &output); 00215 virtual bvec decode_tail(const vec &received_signal) 00216 { 00217 bvec output; decode_tail(received_signal, output); return output; 00218 } 00220 00222 00223 00224 virtual void decode_tailbite(const vec &received_signal, bvec &output); 00225 virtual bvec decode_tailbite(const vec &received_signal) 00226 { 00227 bvec output; decode_tailbite(received_signal, output); return output; 00228 } 00230 00232 00233 virtual void decode_trunc(const vec &received_signal, bvec &output); 00234 virtual bvec decode_trunc(const vec &received_signal) 00235 { 00236 bvec output; decode_trunc(received_signal, output); return output; 00237 } 00239 00240 00242 virtual double get_rate(void) const { return rate; } 00243 00244 00246 void set_start_state(int state) 00247 { 00248 it_error_if((state < 0) || ((state >= (1 << m)) && m != 0), 00249 "Convolutional_Code::set_start_state(): Invalid start state"); 00250 start_state = state; 00251 } 00252 00254 void init_encoder() { encoder_state = start_state; } 00255 00257 int get_encoder_state(void) const { return encoder_state; } 00258 00259 00261 void set_truncation_length(const int length) 00262 { 00263 it_error_if(length < K, "Convolutional_Code::set_truncation_length(): Truncation length shorter than K"); 00264 trunc_length = length; 00265 } 00266 00268 int get_truncation_length(void) const { return trunc_length; } 00269 00270 00272 bool catastrophic(void); 00273 00274 00283 bool inverse_tail(const bvec coded_sequence, bvec &input); 00284 00285 00288 void distance_profile(ivec &dist_prof, int dmax = 100000, 00289 bool reverse = false); 00290 00306 void calculate_spectrum(Array<ivec> &spectrum, int dmax, int no_terms); 00307 00330 int fast(Array<ivec> &spectrum, const int dfree, const int no_terms, 00331 const int Cdfree = 1000000, const bool test_catastrophic = false); 00332 00333 protected: 00335 int next_state(const int instate, const int input) 00336 { 00337 return ((instate >> 1) | (input << (m - 1))); 00338 } 00340 int previous_state(const int state, const int input) 00341 { 00342 return (((state << 1) | input) & ((1 << m) - 1)); 00343 } 00345 void previous_state(const int state, int &S0, int &S1) 00346 { 00347 S0 = (state << 1) & (no_states - 1); 00348 S1 = S0 | 1; 00349 } 00351 int weight(const int state, const int input); 00353 void weight(const int state, int &w0, int &w1); 00356 int weight_reverse(const int state, const int input); 00359 void weight_reverse(const int state, int &w0, int &w1); 00361 bvec output_reverse(const int state, const int input); 00363 void output_reverse(const int state, bvec &zero_output, bvec &one_output); 00365 void output_reverse(const int state, int &zero_output, int &one_output); 00367 void calc_metric_reverse(const int state, const vec &rx_codeword, 00368 double &zero_metric, double &one_metric); 00370 void calc_metric(const vec &rx_codeword, vec &delta_metrics); 00372 int get_input(const int state) { return (state >> (m - 1)); } 00373 00375 int n; 00377 int K; 00379 int m; 00381 int no_states; 00383 ivec gen_pol; 00385 ivec gen_pol_rev; 00387 int encoder_state; 00389 int start_state; 00391 int trunc_length; 00393 double rate; 00395 bvec xor_int_table; 00397 imat output_reverse_int; 00399 CONVOLUTIONAL_CODE_METHOD cc_method; 00401 imat path_memory; 00403 Array<bool> visited_state; 00405 vec sum_metric; 00407 int trunc_ptr; 00409 int trunc_state; 00410 }; 00411 00412 // --------------- Some other functions that maybe should be moved ----------- 00417 int reverse_int(int length, int in); 00418 00423 int weight_int(int length, int in); 00424 00429 int compare_spectra(ivec v1, ivec v2); 00430 00437 int compare_spectra(ivec v1, ivec v2, vec weight_profile); 00438 00439 } // namespace itpp 00440 00441 #endif // #ifndef CONVCODE_H
Generated on Sun Sep 14 18:57:04 2008 for IT++ by Doxygen 1.5.6