40inline double max(
double x,
double y) {
return std::max(x, y); }
45int Rec_Syst_Conv_Code::calc_state_transition(
const int instate,
const int input, ivec &parity)
47 int i, j, in = 0, temp = (gen_pol_rev(0) & (instate << 1)), parity_temp, parity_bit;
49 for (i = 0; i < K; i++) {
55 parity.set_size(n - 1,
false);
56 for (j = 0; j < (n - 1); j++) {
57 parity_temp = ((instate << 1) + in) & gen_pol_rev(j + 1);
59 for (i = 0; i < K; i++) {
60 parity_bit = (parity_temp & 1) ^ parity_bit;
61 parity_temp = parity_temp >> 1;
63 parity(j) = parity_bit;
65 return in + ((instate << 1) & ((1 << m) - 1));
78 gen_pol_rev.set_size(n,
false);
79 for (
int i = 0;
i < n;
i++) {
84 state_trans.set_size(Nstates, 2,
false);
85 rev_state_trans.set_size(Nstates, 2,
false);
86 output_parity.set_size(Nstates, 2*(n - 1),
false);
87 rev_output_parity.set_size(Nstates, 2*(n - 1),
false);
94 for (
j = 0;
j < (n - 1);
j++) {
96 rev_output_parity(
s0, 2*
j + 0) =
p0(
j);
102 for (
j = 0;
j < (n - 1);
j++) {
104 rev_output_parity(
s1, 2*
j + 1) =
p1(
j);
116 Lc = 4.0 * std::sqrt(Ec) / N0;
132 for (
j = 0;
j < (n - 1);
j++) {
133 parity_bits(
i,
j) = output_parity(encoder_state, 2 *
j +
int(input(
i)));
135 encoder_state = state_trans(encoder_state,
int(input(
i)));
139 for (
i = 0;
i < m;
i++) {
142 else { tail(
i) =
bin(1); }
143 for (
j = 0;
j < (n - 1);
j++) {
158 for (
j = 0;
j < (n - 1);
j++) {
159 parity_bits(
i,
j) = output_parity(encoder_state, 2 *
j +
int(input(
i)));
161 encoder_state = state_trans(encoder_state,
int(input(
i)));
189 for (
j = 0;
j < (n - 1);
j++) {
220 alpha.set_col(0,
zeros(Nstates));
225 for (s = 0; s < Nstates; s++) {
226 s_prim0 = rev_state_trans(s, 0);
227 s_prim1 = rev_state_trans(s, 1);
233 alpha.set_col(k, alpha.get_col(k) /
denom(k));
252 beta.set_col(k - 1, beta.get_col(k - 1) /
denom(k));
265 for (
j = 0;
j < (n - 1);
j++) {
286 if (metric ==
"TABLE") {
301 int i,
j,
s0,
s1, k,
kk, l, s,
s_prim,
s_prim0,
s_prim1,
block_length =
rec_systematic.
length();
308 it_error(
"Rec_Syst_Conv_Code::log_decode: Illegal metric parameter");
322 "Rec_Syst_Conv_Code::log_decode: This function assumes that Lc = 1.0. Please use proper scaling of the input data");
330 for (
j = 0;
j < (n - 1);
j++) {
343 for (
j = 1;
j < Nstates;
j++) { alpha(
j, 0) = -infinity; }
348 for (s = 0; s < Nstates; s++) {
349 s_prim0 = rev_state_trans(s, 0);
350 s_prim1 = rev_state_trans(s, 1);
357 for (l = 0; l < Nstates; l++) { alpha(l, k) -=
denom(k); }
377 for (l = 0; l < Nstates; l++) { beta(l, k - 1) -=
denom(k); }
390 for (
j = 0;
j < (n - 1);
j++) {
407 if (metric ==
"TABLE") {
429 it_error(
"Rec_Syst_Conv_Code::log_decode_n2: Illegal metric parameter");
442 "Rec_Syst_Conv_Code::log_decode_n2: This function assumes that Lc = 1.0. Please use proper scaling of the input data");
445 for (s = 1; s < Nstates; s++) { alpha(s, 0) = -infinity; }
458 for (s = 0; s < Nstates; s++) {
459 s_prim0 = rev_state_trans(s, 0);
460 s_prim1 = rev_state_trans(s, 1);
472 for (l = 0; l < Nstates; l++) { alpha(l, k) -=
norm; }
477 for (s = 1; s < Nstates; s++) { beta(s,
block_length) = -infinity; }
492 for (l = 0; l < Nstates; l++) { beta(l, k) -=
norm; }
523 int i,
j,
s0,
s1, k,
kk, l, s,
s_prim,
s_prim0,
s_prim1,
block_length =
rec_systematic.
length();
537 "Rec_Syst_Conv_Code::log_decode: This function assumes that Lc = 1.0. Please use proper scaling of the input data");
545 for (
j = 0;
j < (n - 1);
j++) {
559 for (
j = 1;
j < Nstates;
j++) {
alpha_q(
j, 0) = -QLLR_MAX; }
564 for (s = 0; s < Nstates; s++) {
565 s_prim0 = rev_state_trans(s, 0);
566 s_prim1 = rev_state_trans(s, 1);
596 for (l = 0; l < Nstates; l++) {
beta_q(l, k - 1) -=
denom_q(k); }
609 for (
j = 0;
j < (n - 1);
j++) {
651 "Rec_Syst_Conv_Code::log_decode_n2: This function assumes that Lc = 1.0. Please use proper scaling of the input data");
654 for (s = 1; s < Nstates; s++) {
alpha_q(s, 0) = -QLLR_MAX; }
667 for (s = 0; s < Nstates; s++) {
668 s_prim0 = rev_state_trans(s, 0);
669 s_prim1 = rev_state_trans(s, 1);
681 for (l = 0; l < Nstates; l++) {
alpha_q(l, k) -=
norm; }
701 for (l = 0; l < Nstates; l++) {
beta_q(l, k) -=
norm; }
int size() const
Returns the number of data elements in the array object.
void set_size(int n, bool copy=false)
Resizing an Array<T>.
int length() const
Returns the number of data elements in the array object.
Log-likelihood algebra calculation unit.
QLLR jaclog(QLLR a, QLLR b) const
Jacobian logarithm.
QLLR to_qllr(double l) const
Convert a "real" LLR value to an LLR type.
double to_double(QLLR l) const
Convert an LLR type to a "real" LLR.
virtual void map_decode(const vec &rec_systematic, const mat &rec_parity, const vec &extrinsic_input, vec &extrinsic_output, bool set_terminated=false)
Maximum A Posteriori (MAP) Probability symbol-by-symbol decoder.
void set_generator_polynomials(const ivec &gen, int constraint_length)
Set generator polynomials.
void encode(const bvec &input, bmat &parity_bits)
Encode a binary vector of inputs starting from zero state without adding of a tail.
void encode_tail(const bvec &input, bvec &tail, bmat &parity_bits)
Encode a binary vector of inputs and also adds a tail of K-1 zeros to force the encoder into the zero...
virtual void log_decode_n2(const vec &rec_systematic, const vec &rec_parity, const vec &extrinsic_input, vec &extrinsic_output, bool set_terminated=false, std::string metric="LOGMAX")
Special Log-MAP/Log-MAX decoder implementation for n = 2.
void set_llrcalc(LLR_calc_unit in_llrcalc)
Set the lookup table for algebra with quantized LLR values (see LLR_calc_unit class)
void set_awgn_channel_parameters(double Ec, double N0)
Sets the channel parameters needed for MAP-decoding.
void set_scaling_factor(double in_Lc)
Set scaling factor for the decoder.
virtual void log_decode(const vec &rec_systematic, const mat &rec_parity, const vec &extrinsic_input, vec &extrinsic_output, bool set_terminated=false, std::string metric="LOGMAX")
Log domain implementation of the Maximum A Posteriori (MAP) Probability symbol-by-symbol decoder.
Binary arithmetic (boolean) class.
#define it_error(s)
Abort unconditionally.
#define it_assert(t, s)
Abort if t is not true.
double trunc_log(double x)
Truncated natural logarithm function.
double log_add(double log_a, double log_b)
Safe substitute for log(exp(log_a) + exp(log_b))
double trunc_exp(double x)
Truncated exponential function.
int length(const Vec< T > &v)
Length of vector.
double gamma(double x)
Deprecated gamma function - please use tgamma() instead.
T max(const Vec< T > &v)
Maximum value of vector.
ITPP_EXPORT vec zeros(int size)
A Double vector of zeros.
double norm(const cvec &v)
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2))
Mat< bin > bmat
bin matrix
int reverse_int(int length, int in)
double(* com_log)(double, double)
Pointer to logarithmic branch metric function.
Definitions of a Recursive Systematic Convolutional codec class.