00001 00033 #ifndef CONVCODE_H 00034 #define CONVCODE_H 00035 00036 #include <itpp/base/vec.h> 00037 #include <itpp/base/mat.h> 00038 #include <itpp/base/array.h> 00039 #include <itpp/base/binary.h> 00040 #include <itpp/comm/channel_code.h> 00041 00042 00043 namespace itpp { 00044 00049 enum CONVOLUTIONAL_CODE_TYPE {MFD, ODS}; 00050 00055 enum CONVOLUTIONAL_CODE_METHOD {Trunc, Tail, Tailbite}; 00056 00105 class Convolutional_Code : public Channel_Code { 00106 public: 00108 Convolutional_Code(void): K(0), start_state(0), cc_method(Tail) 00109 { 00110 set_code(MFD, 2, 7); 00111 init_encoder(); 00112 } 00113 00115 virtual ~Convolutional_Code(void) {} 00116 00118 void set_method(const CONVOLUTIONAL_CODE_METHOD method) 00119 { 00120 cc_method = method; 00121 } 00122 00130 void set_code(const CONVOLUTIONAL_CODE_TYPE type_of_code, int inverse_rate, 00131 int constraint_length); 00132 00134 void set_generator_polynomials(const ivec &gen, int constraint_length); 00136 ivec get_generator_polynomials(void) const { return gen_pol; } 00137 00139 void reset(); 00140 00141 00143 00144 virtual void encode(const bvec &input, bvec &output); 00145 virtual bvec encode(const bvec &input) 00146 { 00147 bvec output; encode(input, output); return output; 00148 } 00150 00152 00153 void encode_trunc(const bvec &input, bvec &output); 00154 bvec encode_trunc(const bvec &input) 00155 { 00156 bvec output; encode_trunc(input, output); return output; 00157 } 00159 00161 00168 void encode_tail(const bvec &input, bvec &output); 00169 bvec encode_tail(const bvec &input) 00170 { 00171 bvec output; encode_tail(input, output); return output; 00172 } 00174 00176 00177 void encode_tailbite(const bvec &input, bvec &output); 00178 bvec encode_tailbite(const bvec &input) 00179 { 00180 bvec output; encode_tailbite(input, output); return output; 00181 } 00183 00185 00190 void encode_bit(const bin &input, bvec &output); 00191 bvec encode_bit(const bin &input) 00192 { 00193 bvec output; encode_bit(input, output); return output; 00194 } 00196 00197 // ------------ Hard-decision decoding is not implemented ------------------- 00198 virtual void decode(const bvec &coded_bits, bvec &decoded_bits); 00199 virtual bvec decode(const bvec &coded_bits); 00200 00202 00203 virtual void decode(const vec &received_signal, bvec &output); 00204 virtual bvec decode(const vec &received_signal) 00205 { 00206 bvec output; decode(received_signal, output); return output; 00207 } 00209 00211 00217 virtual void decode_tail(const vec &received_signal, bvec &output); 00218 virtual bvec decode_tail(const vec &received_signal) 00219 { 00220 bvec output; decode_tail(received_signal, output); return output; 00221 } 00223 00225 00226 00227 virtual void decode_tailbite(const vec &received_signal, bvec &output); 00228 virtual bvec decode_tailbite(const vec &received_signal) 00229 { 00230 bvec output; decode_tailbite(received_signal, output); return output; 00231 } 00233 00235 00236 virtual void decode_trunc(const vec &received_signal, bvec &output); 00237 virtual bvec decode_trunc(const vec &received_signal) 00238 { 00239 bvec output; decode_trunc(received_signal, output); return output; 00240 } 00242 00243 00245 virtual double get_rate(void) { return rate; } 00246 00247 00249 void set_start_state(int state) 00250 { 00251 it_error_if((state < 0) || ((state >= (1 << m)) && m != 0), 00252 "Convolutional_Code::set_start_state(): Invalid start state"); 00253 start_state = state; 00254 } 00255 00257 void init_encoder() { encoder_state = start_state; } 00258 00260 int get_encoder_state(void) const { return encoder_state; } 00261 00262 00264 void set_truncation_length(const int length) 00265 { 00266 it_error_if(length < K, "Convolutional_Code::set_truncation_length(): Truncation length shorter than K"); 00267 trunc_length = length; 00268 } 00269 00271 int get_truncation_length(void) const { return trunc_length; } 00272 00273 00275 bool catastrophic(void); 00276 00277 00286 bool inverse_tail(const bvec coded_sequence, bvec &input); 00287 00288 00291 void distance_profile(ivec &dist_prof, int dmax = 100000, 00292 bool reverse = false); 00293 00309 void calculate_spectrum(Array<ivec> &spectrum, int dmax, int no_terms); 00310 00333 int fast(Array<ivec> &spectrum, const int dfree, const int no_terms, 00334 const int Cdfree = 1000000, const bool test_catastrophic = false); 00335 00336 protected: 00338 int next_state(const int instate, const int input) 00339 { 00340 return ((instate >> 1) | (input << (m - 1))); 00341 } 00343 int previous_state(const int state, const int input) 00344 { 00345 return (((state << 1) | input) & ((1 << m) - 1)); 00346 } 00348 void previous_state(const int state, int &S0, int &S1) 00349 { 00350 S0 = (state << 1) & (no_states - 1); 00351 S1 = S0 | 1; 00352 } 00354 int weight(const int state, const int input); 00356 void weight(const int state, int &w0, int &w1); 00359 int weight_reverse(const int state, const int input); 00362 void weight_reverse(const int state, int &w0, int &w1); 00364 bvec output_reverse(const int state, const int input); 00366 void output_reverse(const int state, bvec &zero_output, bvec &one_output); 00368 void output_reverse(const int state, int &zero_output, int &one_output); 00370 void calc_metric_reverse(const int state, const vec &rx_codeword, 00371 double &zero_metric, double &one_metric); 00373 void calc_metric(const vec &rx_codeword, vec &delta_metrics); 00375 int get_input(const int state) { return (state >> (m - 1)); } 00376 00378 int n; 00380 int K; 00382 int m; 00383 // number of states 00384 int no_states; 00386 ivec gen_pol; 00388 ivec gen_pol_rev; 00390 int encoder_state; 00392 int start_state; 00394 int trunc_length; 00396 double rate; 00398 bvec xor_int_table; 00400 imat output_reverse_int; 00402 CONVOLUTIONAL_CODE_METHOD cc_method; 00404 imat path_memory; 00406 Array<bool> visited_state; 00408 vec sum_metric; 00410 int trunc_ptr; 00412 int trunc_state; 00413 }; 00414 00415 // --------------- Some other functions that maybe should be moved ----------- 00420 int reverse_int(int length, int in); 00421 00426 int weight_int(int length, int in); 00427 00432 int compare_spectra(ivec v1, ivec v2); 00433 //int compare_spectra(llvec v1, llvec v2); 00434 00441 int compare_spectra(ivec v1, ivec v2, vec weight_profile); 00442 00443 } // namespace itpp 00444 00445 #endif // #ifndef CONVCODE_H
Generated on Fri Jun 8 02:08:54 2007 for IT++ by Doxygen 1.5.2