convcode.h
Go to the documentation of this file.
#ifndef CONVCODE_H
#define CONVCODE_H
#include <itpp/base/vec.h>
#include <itpp/base/mat.h>
#include <itpp/base/array.h>
#include <itpp/base/binary.h>
#include <itpp/comm/channel_code.h>
#include <itpp/itexports.h>
#include <itpp/base/base_exports.h>
namespace itpp
{
enum CONVOLUTIONAL_CODE_TYPE {MFD, ODS};
enum CONVOLUTIONAL_CODE_METHOD {Trunc, Tail, Tailbite};
class ITPP_EXPORT Convolutional_Code : public Channel_Code
{
public:
Convolutional_Code(void): K(0), start_state(0), cc_method(Tail) {
set_code(MFD, 2, 7);
init_encoder();
}
virtual ~Convolutional_Code(void) {}
void set_method(const CONVOLUTIONAL_CODE_METHOD method) {
cc_method = method;
}
void set_code(const CONVOLUTIONAL_CODE_TYPE type_of_code, int inverse_rate,
int constraint_length);
void set_generator_polynomials(const ivec &gen, int constraint_length);
ivec get_generator_polynomials(void) const { return gen_pol; }
void reset();
virtual void encode(const bvec &input, bvec &output);
virtual bvec encode(const bvec &input) {
bvec output;
encode(input, output);
return output;
}
void encode_trunc(const bvec &input, bvec &output);
bvec encode_trunc(const bvec &input) {
bvec output;
encode_trunc(input, output);
return output;
}
void encode_tail(const bvec &input, bvec &output);
bvec encode_tail(const bvec &input) {
bvec output;
encode_tail(input, output);
return output;
}
void encode_tailbite(const bvec &input, bvec &output);
bvec encode_tailbite(const bvec &input) {
bvec output;
encode_tailbite(input, output);
return output;
}
void encode_bit(const bin &input, bvec &output);
bvec encode_bit(const bin &input) {
bvec output;
encode_bit(input, output);
return output;
}
// ------------ Hard-decision decoding is not implemented ----------------
virtual void decode(const bvec &coded_bits, bvec &decoded_bits);
virtual bvec decode(const bvec &coded_bits);
virtual void decode(const vec &received_signal, bvec &output);
virtual bvec decode(const vec &received_signal) {
bvec output;
decode(received_signal, output);
return output;
}
virtual void decode_tail(const vec &received_signal, bvec &output);
virtual bvec decode_tail(const vec &received_signal) {
bvec output;
decode_tail(received_signal, output);
return output;
}
virtual void decode_tailbite(const vec &received_signal, bvec &output);
virtual bvec decode_tailbite(const vec &received_signal) {
bvec output;
decode_tailbite(received_signal, output);
return output;
}
virtual void decode_trunc(const vec &received_signal, bvec &output);
virtual bvec decode_trunc(const vec &received_signal) {
bvec output;
decode_trunc(received_signal, output);
return output;
}
virtual double get_rate(void) const { return rate; }
void set_start_state(int state) {
it_error_if((state < 0) || ((state >= (1 << m)) && m != 0),
"Convolutional_Code::set_start_state(): Invalid start state");
start_state = state;
}
void init_encoder() { encoder_state = start_state; }
int get_encoder_state(void) const { return encoder_state; }
void set_truncation_length(const int length) {
it_error_if(length < K, "Convolutional_Code::set_truncation_length(): "
"Truncation length shorter than K");
trunc_length = length;
}
int get_truncation_length(void) const { return trunc_length; }
bool catastrophic(void);
bool inverse_tail(const bvec coded_sequence, bvec &input);
void distance_profile(ivec &dist_prof, int dmax = 100000,
bool reverse = false);
void calculate_spectrum(Array<ivec> &spectrum, int dmax, int no_terms);
int fast(Array<ivec> &spectrum, const int dfree, const int no_terms,
const int Cdfree = 1000000, const bool test_catastrophic = false);
protected:
int next_state(const int instate, const int input) {
return ((instate >> 1) | (input << (m - 1)));
}
int previous_state(const int state, const int input) {
return (((state << 1) | input) & ((1 << m) - 1));
}
void previous_state(const int state, int &S0, int &S1) {
S0 = (state << 1) & (no_states - 1);
S1 = S0 | 1;
}
int weight(const int state, const int input);
void weight(const int state, int &w0, int &w1);
int weight_reverse(const int state, const int input);
void weight_reverse(const int state, int &w0, int &w1);
bvec output_reverse(const int state, const int input);
void output_reverse(const int state, bvec &zero_output, bvec &one_output);
void output_reverse(const int state, int &zero_output, int &one_output);
void calc_metric_reverse(const int state, const vec &rx_codeword,
double &zero_metric, double &one_metric);
void calc_metric(const vec &rx_codeword, vec &delta_metrics);
int get_input(const int state) { return (state >> (m - 1)); }
int n;
int K;
int m;
int no_states;
ivec gen_pol;
ivec gen_pol_rev;
int encoder_state;
int start_state;
int trunc_length;
double rate;
bvec xor_int_table;
imat output_reverse_int;
CONVOLUTIONAL_CODE_METHOD cc_method;
imat path_memory;
Array<bool> visited_state;
vec sum_metric;
int trunc_ptr;
int trunc_state;
};
// --------------- Some other functions that maybe should be moved -----------
ITPP_EXPORT int reverse_int(int length, int in);
ITPP_EXPORT int weight_int(int length, int in);
ITPP_EXPORT int compare_spectra(ivec v1, ivec v2);
ITPP_EXPORT int compare_spectra(ivec v1, ivec v2, vec weight_profile);
} // namespace itpp
#endif // #ifndef CONVCODE_H
array.h
Definition of Array class (container)
base_exports.h
Import/Export definitions for some templates defined in base folder.
binary.h
Binary class definition.
channel_code.h
Channel Code class virtual interface.
itpp::Array
General array class.
Definition array.h:105
itpp::Array::length
int length() const
Returns the number of data elements in the array object.
Definition array.h:157
itpp::Channel_Code
Generic Channel Code class.
Definition channel_code.h:51
itpp::Convolutional_Code
Binary Convolutional rate 1/n class.
Definition convcode.h:105
itpp::Convolutional_Code::get_input
int get_input(const int state)
Returns the input that results in state, that is the MSB of state.
Definition convcode.h:408
itpp::Convolutional_Code::encoder_state
int encoder_state
The current encoder state.
Definition convcode.h:423
itpp::Convolutional_Code::get_encoder_state
int get_encoder_state(void) const
Get the current encoder state.
Definition convcode.h:296
itpp::Convolutional_Code::rate
double rate
The rate of the code.
Definition convcode.h:429
itpp::Convolutional_Code::set_method
void set_method(const CONVOLUTIONAL_CODE_METHOD method)
Set encoding and decoding method (Trunc, Tail, or Tailbite)
Definition convcode.h:117
itpp::Convolutional_Code::sum_metric
vec sum_metric
Metrics accumulator.
Definition convcode.h:441
itpp::Convolutional_Code::path_memory
imat path_memory
Path memory (trellis)
Definition convcode.h:437
itpp::Convolutional_Code::get_truncation_length
int get_truncation_length(void) const
Get memory truncation length.
Definition convcode.h:307
itpp::Convolutional_Code::next_state
int next_state(const int instate, const int input)
Next state from instate given the input.
Definition convcode.h:374
itpp::Convolutional_Code::get_rate
virtual double get_rate(void) const
Return rate of code (not including the rate-loss)
Definition convcode.h:279
itpp::Convolutional_Code::trunc_length
int trunc_length
The decoder truncation length.
Definition convcode.h:427
itpp::Convolutional_Code::get_generator_polynomials
ivec get_generator_polynomials(void) const
Get generator polynomials.
Definition convcode.h:134
itpp::Convolutional_Code::set_start_state
void set_start_state(int state)
Set encoder default start state.
Definition convcode.h:283
itpp::Convolutional_Code::K
int K
Constraint length.
Definition convcode.h:413
itpp::Convolutional_Code::previous_state
void previous_state(const int state, int &S0, int &S1)
The previous state from state given the input.
Definition convcode.h:382
itpp::Convolutional_Code::previous_state
int previous_state(const int state, const int input)
The previous state from state given the input.
Definition convcode.h:378
itpp::Convolutional_Code::start_state
int start_state
The encoder start state.
Definition convcode.h:425
itpp::Convolutional_Code::~Convolutional_Code
virtual ~Convolutional_Code(void)
Destructor.
Definition convcode.h:114
itpp::Convolutional_Code::output_reverse_int
imat output_reverse_int
output in int format for a given state and input
Definition convcode.h:433
itpp::Convolutional_Code::Convolutional_Code
Convolutional_Code(void)
Default constructor - sets (0133,0171) code with tail.
Definition convcode.h:108
itpp::Convolutional_Code::trunc_ptr
int trunc_ptr
Truncated path memory pointer.
Definition convcode.h:443
itpp::Convolutional_Code::no_states
int no_states
Number of states.
Definition convcode.h:417
itpp::Convolutional_Code::init_encoder
void init_encoder()
Initialise internal encoder state with start state. Has no effect on Tail and Tailbite methods.
Definition convcode.h:293
itpp::Convolutional_Code::set_truncation_length
void set_truncation_length(const int length)
Set memory truncation length. Must be at least K.
Definition convcode.h:300
itpp::Convolutional_Code::n
int n
Number of generators.
Definition convcode.h:411
itpp::Convolutional_Code::m
int m
Memory of the encoder.
Definition convcode.h:415
itpp::Convolutional_Code::gen_pol_rev
ivec gen_pol_rev
Generator polynomials for the reverse code.
Definition convcode.h:421
itpp::Convolutional_Code::trunc_state
int trunc_state
Truncated memory fill state.
Definition convcode.h:445
itpp::Convolutional_Code::cc_method
CONVOLUTIONAL_CODE_METHOD cc_method
encoding and decoding method
Definition convcode.h:435
itpp::Convolutional_Code::xor_int_table
bvec xor_int_table
Auxilary table used by the codec.
Definition convcode.h:431
itpp::Convolutional_Code::gen_pol
ivec gen_pol
Generator polynomials.
Definition convcode.h:419
itpp::Convolutional_Code::visited_state
Array< bool > visited_state
Visited states.
Definition convcode.h:439
itpp::Convolutional_Code::decode
virtual bvec decode(const vec &received_signal)
Decode a vec of received data.
Definition convcode.h:228
itpp::Convolutional_Code::encode
virtual bvec encode(const bvec &input)
Encode a bvec of input.
Definition convcode.h:143
it_error_if
#define it_error_if(t, s)
Abort if t is true.
Definition itassert.h:117
itpp::CONVOLUTIONAL_CODE_METHOD
CONVOLUTIONAL_CODE_METHOD
Encoding and decoding methods for Convolutional codes.
Definition convcode.h:53
itpp::CONVOLUTIONAL_CODE_TYPE
CONVOLUTIONAL_CODE_TYPE
Type of Convolutional Code.
Definition convcode.h:47
itpp::length
int length(const Vec< T > &v)
Length of vector.
Definition matfunc.h:51
itpp::weight
int weight(const bvec &a)
Calculate the Hamming weight of a.
Definition commfunc.cpp:71
itpp::reverse
Vec< T > reverse(const Vec< T > &in)
Reverse the input vector.
Definition matfunc.h:777
itpp::spectrum
vec spectrum(const vec &v, int nfft, int noverlap)
Power spectrum calculation.
Definition sigfun.cpp:267
mat.h
Matrix Class Definitions.
itpp
itpp namespace
Definition itmex.h:37
itpp::weight_int
int weight_int(int length, int in)
Definition convcode.cpp:1460
itpp::compare_spectra
int compare_spectra(ivec v1, ivec v2)
Definition convcode.cpp:1472
itpp::reverse_int
int reverse_int(int length, int in)
Definition convcode.cpp:1442
vec.h
Templated Vector Class Definitions.

Generated on Mon Jun 10 2024 11:49:20 for IT++ by Doxygen 1.9.8