00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00026 #ifndef __convcode_h
00027 #define __convcode_h
00028
00029 #include <array.h>
00030 #include <binary.h>
00031 #include <vector.h>
00032 #include <matrix.h>
00033
00034 using std::string;
00035 namespace SPUC {
00076 class Convolutional_Code {
00077 public:
00079 Convolutional_Code(void) { trunc_length = 0; K = 0; m = 0; set_start_state(0); }
00081 virtual ~Convolutional_Code(void) {}
00088 void set_code(string type_of_code, int inverse_rate, int constraint_length);
00090 void set_generator_polynomials(const ivec &gen, int constraint_length);
00092 ivec get_generator_polynomials(void) { return gen_pol; }
00094 double get_rate(void) { return rate; }
00095
00097 void encode(const bvec &input, bvec &output);
00099 bvec encode(const bvec &input) { bvec output; encode(input, output); return output; }
00107 void encode_tail(const bvec &input, bvec &output);
00109 bvec encode_tail(const bvec &input) { bvec output; encode_tail(input, output); return output; }
00110
00112 void encode_tailbite(const bvec &input, bvec &output);
00114 bvec encode_tailbite(const bvec &input)
00115 { bvec output; encode_tailbite(input, output); return output; }
00116
00122 void encode_bit(const bin &input, bvec &output);
00124 bvec encode_bit(const bin &input) { bvec output; encode_bit(input, output); return output; }
00126 void init_encoder() { encoder_state = start_state; }
00127
00134 void decode_tail(const vec &received_signal, bvec &output);
00136 bvec decode_tail(const vec &received_signal)
00137 { bvec output; decode_tail(received_signal, output); return output; }
00138
00140 void decode_tailbite(const vec &received_signal, bvec &output);
00142 bvec decode_tailbite(const vec &received_signal)
00143 { bvec output; decode_tail(received_signal, output); return output; }
00144
00146 void decode(const vec &received_signal, bvec &output);
00148 bvec decode(const vec &received_signal)
00149 { bvec output; decode(received_signal, output); return output; }
00150
00158 bool inverse_tail(const bvec coded_sequence, bvec &input);
00160 void set_start_state(const int state)
00161 {
00162
00163 start_state = state; }
00165 int get_encoder_state(void) { return encoder_state; }
00166
00168 void set_truncation_length(const int length) {
00169
00170 trunc_length = length; }
00172 int get_truncation_length(void) { return trunc_length; }
00173
00175 bool catastrophic(void);
00176
00178 void distance_profile(llvec &dist_prof, int dmax = 100000, bool reverse = false);
00189 void calculate_spectrum(Array<llvec> &spectrum, int dmax, int no_terms);
00205 int fast(Array<llvec> &spectrum, const int dfree, const int no_terms,
00206 const int Cdfree = 1000000, const bool test_catastrophic = false);
00207
00208 protected:
00210 int next_state(const int instate, const int input) { return ( (instate >> 1) | (input << (m-1))); }
00212 int previous_state(const int state, const int input) { return ( ((state << 1) | input) & ((1<<m)-1) ); }
00214 int weight(const int state, const int input);
00216 void weight(const int state, int &w0, int &w1);
00218 int weight_reverse(const int state, const int input);
00220 void weight_reverse(const int state, int &w0, int &w1);
00222 bvec output_reverse(const int state, const int input);
00224 void output_reverse(const int state, bvec &zero_output, bvec &one_output);
00226 void calc_metric_reverse(const int state, const vec &rx_codeword, double &zero_metric, double &one_metric);
00227
00229 int get_input(const int state) { return (state >> (m-1)); }
00230
00232 int n;
00234 int K;
00236 int m;
00238 ivec gen_pol;
00240 ivec gen_pol_rev;
00242 int encoder_state;
00244 int start_state;
00246 int trunc_length;
00248 double rate;
00250 bvec xor_int_table;
00251 };
00252
00253
00258 int reverse_int(int length, int in);
00259
00264 int weight_int(int length, int in);
00265
00270 int compare_spectra(llvec v1, llvec v2);
00271
00278 int compare_spectra(ivec v1, ivec v2, vec weight_profile);
00279 }
00280
00281 #endif // __convcode_h