From aefe47cd7a0200bb67b89fefe439892bddd5343d Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 11 Jan 2016 00:50:09 +0100 Subject: [PATCH] Removing unused code --- src/algorithms/PVT/libs/geojson_printer.cc | 1 - src/algorithms/PVT/libs/geojson_printer.h | 1 - src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.h | 1 - .../telemetry_decoder/libs/convolutional.h | 344 +----------------- .../telemetry_decoder/libs/viterbi_decoder.cc | 93 ++--- .../telemetry_decoder/libs/viterbi_decoder.h | 2 - 6 files changed, 72 insertions(+), 370 deletions(-) diff --git a/src/algorithms/PVT/libs/geojson_printer.cc b/src/algorithms/PVT/libs/geojson_printer.cc index f07f39651..997992934 100644 --- a/src/algorithms/PVT/libs/geojson_printer.cc +++ b/src/algorithms/PVT/libs/geojson_printer.cc @@ -32,7 +32,6 @@ #include "geojson_printer.h" #include -#include #include #include #include diff --git a/src/algorithms/PVT/libs/geojson_printer.h b/src/algorithms/PVT/libs/geojson_printer.h index 4ab3e9d6f..b286e164a 100644 --- a/src/algorithms/PVT/libs/geojson_printer.h +++ b/src/algorithms/PVT/libs/geojson_printer.h @@ -33,7 +33,6 @@ #ifndef GNSS_SDR_GEOJSON_PRINTER_H_ #define GNSS_SDR_GEOJSON_PRINTER_H_ -#include #include #include #include diff --git a/src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.h b/src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.h index ea9b4d491..c926d24c4 100644 --- a/src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.h +++ b/src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.h @@ -32,7 +32,6 @@ #define GNSS_SDR_GPS_L1_CA_LS_PVT_H_ #include -#include #include #include #include "ls_pvt.h" diff --git a/src/algorithms/telemetry_decoder/libs/convolutional.h b/src/algorithms/telemetry_decoder/libs/convolutional.h index 2ca3b683a..4738aef43 100644 --- a/src/algorithms/telemetry_decoder/libs/convolutional.h +++ b/src/algorithms/telemetry_decoder/libs/convolutional.h @@ -37,11 +37,14 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -//#ifndef GNSS_SDR_CONVOLUTIONAL_H_ -//#define GNSS_SDR_CONVOLUTIONAL_H_ -/* define constants used throughout the library */ -#define MAXLOG 1e7 /* Define infinity */ +#ifndef GNSS_SDR_CONVOLUTIONAL_H_ +#define GNSS_SDR_CONVOLUTIONAL_H_ + +#include // for calloc + +/* define constants used throughout the library */ +const float MAXLOG = 1e7; /* Define infinity */ /*! * \brief Converts an integer symbol into a vector of bits @@ -103,7 +106,7 @@ static int parity_counter(int symbol, int length) * \param[out] state_out_p[] An integer containing the final state of the encoder * (i.e. the state after encoding this bit) * - * This function is used by rsc_encode(), nsc_transit(), rsc_transit(), and nsc_transit() + * This function is used by nsc_transit() */ static int nsc_enc_bit(int state_out_p[], int input, @@ -194,169 +197,6 @@ static void nsc_transit(int output_p[], -/*! - * \brief Calculates the "transition matrix" for the trellis. - * This information tells the decoder what the next state and output bits - * will be given the current state and input bit. - * - * \param[in] input Either 0 or 1 --- the input data bit. - * \param[in] g[] A two element vector containing the code generators. - * \param[in] KK The constraint length of the convolutional code. - * \param[out] output_p[] A vector of length max_states = 2^(KK-1) containing - * the output symbols. - * \param[out] trans_p[] A vector of length max_states that tells the decoder - * what the next state will be given the input and current state. - * - * This function is used by turbo_decode() - */ -static void rsc_transit(int output_p[], - int trans_p[], - int input, - int g[], - int KK, - int nn ) -{ - int nextstate[1]; - int state, states; - - states = 1 << (KK - 1); // The number of states: 2^mm - - // Determine the output and next state for each possible starting state - for(state = 0; state < states; state++) - { - output_p[state] = rsc_enc_bit( nextstate, input, state, g, KK, nn ); - trans_p[state] = nextstate[0]; - } - return; -} - - - -/*! - * \brief determines the tail for a RSC code - */ -static void rsc_tail(int tail_p[], - int g[], - int max_states, - int mm ) -{ - int state; - - /* Determine the tail for each state */ - for(state = 0; state < max_states; state++) - { - /* determine feedback word */ - tail_p[state] = parity_counter(g[0]&state, mm); - } - return; -} - - - -/*! - * \brief Perform convolutional encoding - */ -static void conv_encode(int output_p[], - int input[], - int out0[], - int state0[], - int out1[], - int state1[], - int tail[], - int KK, - int LL, - int nn) -{ - int i, j, outsym; - int *bin_vec; - int state = 0; - - /* Negative value in "tail" is a flag that this is - a tail-biting NSC code. Determine initial state */ - - if ( tail[0] < 0 ) - { - for (i = LL - KK + 1; i < LL; i++) - { - if (input[i]) - { - /* Determine next state */ - state = state1[state]; - } - else - { - /* Determine next state */ - state = state0[state]; - } - } - } - - bin_vec = (int*)calloc( nn, sizeof(int) ); - - /* encode data bits one bit at a time */ - for (i = 0; i < LL; i++) - { - if (input[i]) - { - /* Input is a one */ - outsym = out1[state]; /* The output symbol */ - - /* Determine next state */ - state = state1[state]; - } - else - { - /* Input is a zero */ - outsym = out0[state]; /* The output symbol */ - - /* Determine next state */ - state = state0[state]; - } - - /* Convert symbol to a binary vector */ - itob( bin_vec, outsym, nn ); - - /* Assign to output */ - for (j = 0; j < nn; j++) - output_p[nn*i + j] = bin_vec[j]; - } - - /* encode tail if needed */ - if (tail[0] >= 0) - { - for (i = LL; i < LL + KK - 1; i++) - { - if (tail[state]) - { - /* Input is a one */ - outsym = out1[state]; /* The output symbol */ - - /* Determine next state */ - state = state1[state]; - } - else - { - /* Input is a zero */ - outsym = out0[state]; /* The output symbol */ - - /* Determine next state */ - state = state0[state]; - } - - /* Convert symbol to a binary vector */ - itob( bin_vec, outsym, nn ); - - /* Assign to output */ - for (j = 0; j < nn; j++) - output_p[nn*i + j] = bin_vec[j]; - } - } - - free(bin_vec); - return; -} - - /*! * \brief Computes the branch metric used for decoding. * \return (returned float) The metric between the hypothetical symbol and the received vector @@ -386,10 +226,10 @@ static float Gamma(float rec_array[], /*! * \brief Uses the Viterbi algorithm to perform hard-decision decoding of a convolutional code. - * \param[in] out0[] The output bits for each state if input is a 0 (generated by rsc_transit). - * \param[in] state0[] The next state if input is a 0 (generated by rsc_transit). - * \param[in] out1[] The output bits for each state if input is a 1 (generated by rsc_transit). - * \param[in] state1[] The next state if input is a 1 (generated by rsc_transit). + * \param[in] out0[] The output bits for each state if input is a 0. + * \param[in] state0[] The next state if input is a 0. + * \param[in] out1[] The output bits for each state if input is a 1. + * \param[in] state1[] The next state if input is a 1. * \param[in] r[] The received signal in LLR-form. For BPSK, must be in form r = 2*a*y/(sigma^2). * \param[in] KK The constraint length of the convolutional code. * \param[in] LL The number of data bits. @@ -422,12 +262,12 @@ static void Viterbi(int output_u_int[], number_symbols = 1 << nn; /* 2^nn */ /* dynamically allocate memory */ - prev_section = (float*)calloc( states, sizeof(float) ); - next_section = (float*)calloc( states, sizeof(float) ); - prev_bit = (int*)calloc( states*(LL + mm), sizeof(int) ); - prev_state = (int*)calloc( states*(LL + mm), sizeof(int) ); - rec_array = (float*)calloc( nn, sizeof(float) ); - metric_c = (float*)calloc( number_symbols, sizeof(float) ); + prev_section = static_cast(calloc( states, sizeof(float) )); + next_section = static_cast(calloc( states, sizeof(float) )); + prev_bit = static_cast(calloc( states*(LL + mm), sizeof(int) )); + prev_state = static_cast(calloc( states*(LL + mm), sizeof(int) )); + rec_array = static_cast(calloc( nn, sizeof(float) )); + metric_c = static_cast(calloc( number_symbols, sizeof(float) )); /* initialize trellis */ for (state = 0; state < states; state++) @@ -441,7 +281,7 @@ static void Viterbi(int output_u_int[], for (t = 0; t < LL + mm; t++) { for (i = 0; i < nn; i++) - rec_array[i] = (float)input_c[nn*t + i]; + rec_array[i] = static_cast(input_c[nn*t + i]); /* precompute all possible branch metrics */ for (i = 0; i < number_symbols; i++) @@ -514,148 +354,4 @@ static void Viterbi(int output_u_int[], } -/*! - * \brief Uses the Viterbi algorithm to perform hard-decision decoding of a tail-biting convolutional code. - * Input parameters: - * out0[] The output bits for each state if input is a 0 (generated by rsc_transit). - * state0[] The next state if input is a 0 (generated by rsc_transit). - * out1[] The output bits for each state if input is a 1 (generated by rsc_transit). - * state1[] The next state if input is a 1 (generated by rsc_transit). - * r[] The received signal in LLR-form. For BPSK, must be in form r = 2*a*y/(sigma^2). - * KK The constraint length of the convolutional code. - * LL The number of data bits. - * depth head and tail decoding length [Ref. W. Sung, Electronics Letters, vol. 36, no. 7] - * Output parameters: - * output_u_int[] Hard decisions on the data bits - */ -static void ViterbiTb(int output_u_int[], - int out0[], - int state0[], - int out1[], - int state1[], - double input_c[], - int KK, - int nn, - int LL, - int depth) -{ - int i, t, state, mm, states, max_state; - int number_symbols, starting_bit; - float metric; - float *prev_section, *next_section; - int *prev_bit; - int *prev_state; - float *metric_c; /* Set of all possible branch metrics */ - float *rec_array; /* Received values for one trellis section */ - float max_val; - - /* some derived constants */ - mm = KK - 1; - states = 1 << mm; /* 2^mm */ - number_symbols = 1 << nn; /* 2^nn */ - - /* dynamically allocate memory */ - prev_section = (float*)calloc( states, sizeof(float) ); - next_section = (float*)calloc( states, sizeof(float) ); - prev_bit = (int*)calloc( states*(LL + depth), sizeof(int) ); - prev_state = (int*)calloc( states*(LL + depth), sizeof(int) ); - rec_array = (float*)calloc( nn, sizeof(float) ); - metric_c = (float*)calloc( number_symbols, sizeof(float) ); - - /* initialize trellis */ - for (state = 0; state < states; state++) - { - prev_section[state] = 0; /* equally likely starting state */ - next_section[state] = -MAXLOG; - } - - /* go through trellis */ - for (t = -depth; t < LL + depth; t++) - { - /* determine the corresponding data bits */ - starting_bit = nn*(t % LL); - if (starting_bit < 0 ) - starting_bit = nn*LL + starting_bit; - - for (i = 0; i < nn; i++) - { - rec_array[i] = (float)input_c[starting_bit+i]; - } - - /* precompute all possible branch metrics */ - for (i = 0; i < number_symbols; i++) - metric_c[i] = Gamma( rec_array, i, nn ); - - /* step through all states */ - for (state = 0; state < states; state++) - { - /* hypothesis: info bit is a zero */ - metric = prev_section[state] + metric_c[ out0[ state ] ]; - - /* store new metric if more than metric in storage */ - if ( metric > next_section[state0[state]] ) - { - next_section[state0[state]] = metric; - if (t >= 0) - { - prev_state[t*states+state0[state]] = state; - prev_bit[t*states+state0[state]] = 0; - } - } - - /* hypothesis: info bit is a one */ - metric = prev_section[state] + metric_c[ out1[ state ] ]; - - /* store new metric if more than metric in storage */ - if ( metric > next_section[state1[state]] ) - { - next_section[state1[state]] = metric; - if (t >= 0) - { - prev_state[t*states+state1[state]] = state; - prev_bit[t*states+state1[state]] = 1; - } - } - } - - /* normalize */ - max_val = 0; - for (state = 0; state < states; state++) - { - if (next_section[state] > max_val) - { - max_val = next_section[state]; - max_state = state; - } - } - for (state = 0; state < states; state++) - { - prev_section[state] = next_section[state] - max_val; - next_section[state] = -MAXLOG; - } - } - - /* trace-back operation */ - state = max_state; - - /* tail, no need to output */ - for (t = LL + depth - 1; t >= LL; t--) - { - state = prev_state[t*states + state]; - } - - for (t = LL - 1; t >= 0; t--) - { - output_u_int[t] = prev_bit[t*states + state]; - state = prev_state[t*states + state]; - } - - /* free the dynamically allocated memory */ - free(prev_section); - free(next_section); - free(prev_bit); - free(prev_state); - free(rec_array); - free(metric_c); -} -//#endif +#endif diff --git a/src/algorithms/telemetry_decoder/libs/viterbi_decoder.cc b/src/algorithms/telemetry_decoder/libs/viterbi_decoder.cc index c306f40fb..27e27e197 100644 --- a/src/algorithms/telemetry_decoder/libs/viterbi_decoder.cc +++ b/src/algorithms/telemetry_decoder/libs/viterbi_decoder.cc @@ -41,7 +41,7 @@ #define LMORE 6 // many entries per sample / very specific stuff -#define MAXLOG 1e7 /* Define infinity */ +const float MAXLOG = 1e7; /* Define infinity */ Viterbi_Decoder::Viterbi_Decoder(const int g_encoder[], const int KK, const int nn) { @@ -59,7 +59,6 @@ Viterbi_Decoder::Viterbi_Decoder(const int g_encoder[], const int KK, const int d_state0 = new int[d_states]; d_state1 = new int[d_states]; - nsc_transit(d_out0, d_state0, 0, g_encoder, d_KK, d_nn); nsc_transit(d_out1, d_state1, 1, g_encoder, d_KK, d_nn); @@ -68,6 +67,7 @@ Viterbi_Decoder::Viterbi_Decoder(const int g_encoder[], const int KK, const int Viterbi_Decoder::init_trellis_state(); } + Viterbi_Decoder::~Viterbi_Decoder() { // trellis definition @@ -110,7 +110,7 @@ float Viterbi_Decoder::decode_block(const double input_c[], int output_u_int[], // init init_trellis_state(); // do add compare select - do_acs(input_c, LL+d_mm); + do_acs(input_c, LL + d_mm); // tail, no need to output -> traceback, but don't decode state = do_traceback(d_mm); // traceback and decode @@ -207,7 +207,7 @@ int Viterbi_Decoder::do_acs(const double sym[], int nbits) { /* Temporarily store the received symbols current decoding step */ for (i = 0; i < d_nn; i++) - d_rec_array[i] = (float) sym[d_nn * t + i]; + d_rec_array[i] = static_cast(sym[d_nn * t + i]); /* precompute all possible branch metrics */ for (i = 0; i < d_number_symbols; i++) @@ -478,15 +478,15 @@ int Viterbi_Decoder::parity_counter(int symbol, int length) Viterbi_Decoder::Prev::Prev(int states, int t) { this->t = t; - num_states=states; + num_states = states; state = new int[states]; bit = new int[states]; metric = new float[states]; refcount = new int; *refcount = 1; - memset(state,0,sizeof(int)*num_states); - memset(bit,0,sizeof(int)*num_states); - memset(metric,0,sizeof(float)*num_states); + memset(state, 0, sizeof(int) * num_states); + memset(bit, 0, sizeof(int) * num_states); + memset(metric, 0, sizeof(float) * num_states); } @@ -498,7 +498,7 @@ Viterbi_Decoder::Prev::Prev(const Prev& prev) (*refcount)++; t = prev.t; state = prev.state; - num_states=prev.num_states; + num_states = prev.num_states; bit = prev.bit; metric = prev.metric; VLOG(LMORE) << "Prev(" << "?" << ", " << t << ")" << " copy, new refcount = " << *refcount; @@ -567,14 +567,16 @@ Viterbi_Decoder::Prev::~Prev() int Viterbi_Decoder::Prev::get_anchestor_state_of_current_state(int current_state) { //std::cout << "get prev state: for state " << current_state << " at time " << t << ", the prev state at time " << t-1 << " is " << state[current_state] << std::endl; - if (num_states>current_state) - { - return state[current_state]; - }else{ - //std::cout<<"alarm "<<"num_states="<current_state) - { - return bit[current_state]; - }else{ - return 0; - } + if (num_states > current_state) + { + return bit[current_state]; + } + else + { + return 0; + } } + float Viterbi_Decoder::Prev::get_metric_of_current_state(int current_state) { - if (num_states>current_state) - { - return metric[current_state]; - }else{ - return 0; - } + if (num_states > current_state) + { + return metric[current_state]; + } + else + { + return 0; + } } + int Viterbi_Decoder::Prev::get_t() { return t; } + void Viterbi_Decoder::Prev::set_current_state_as_ancestor_of_next_state(int next_state, int current_state) { - if (num_states>next_state) - { - state[next_state] = current_state; - } + if (num_states > next_state) + { + state[next_state] = current_state; + } } + void Viterbi_Decoder::Prev::set_decoded_bit_for_next_state(int next_state, int bit) { - if (num_states>next_state) - { - this->bit[next_state] = bit; - } + if (num_states > next_state) + { + this->bit[next_state] = bit; + } } + void Viterbi_Decoder::Prev::set_survivor_branch_metric_of_next_state(int next_state, float metric) { - if (num_states>next_state) - { - this->metric[next_state] = metric; - } + if (num_states > next_state) + { + this->metric[next_state] = metric; + } } diff --git a/src/algorithms/telemetry_decoder/libs/viterbi_decoder.h b/src/algorithms/telemetry_decoder/libs/viterbi_decoder.h index b65666778..4cd6d6885 100644 --- a/src/algorithms/telemetry_decoder/libs/viterbi_decoder.h +++ b/src/algorithms/telemetry_decoder/libs/viterbi_decoder.h @@ -33,7 +33,6 @@ #define GNSS_SDR_VITERBI_DECODER_H_ #include -#include /*! * \brief Class that implements a Viterbi decoder @@ -55,7 +54,6 @@ public: */ float decode_block(const double input_c[], int* output_u_int, const int LL); - float decode_continuous(const double sym[], const int traceback_depth, int output_u_int[], const int nbits_requested, int &nbits_decoded);