1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-10-30 23:03:05 +00:00

Improving documentation and some code cleaning

git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@446 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
Carles Fernandez
2013-11-17 10:48:27 +00:00
parent 6eabb93de7
commit a7b1f71566
17 changed files with 1767 additions and 1600 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2013 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
@@ -228,22 +228,28 @@ public:
GpsL1CaSubframeFsm::GpsL1CaSubframeFsm()
{
d_nav.reset();
initiate(); //start the FSM
d_nav.reset();
initiate(); //start the FSM
}
void GpsL1CaSubframeFsm::gps_word_to_subframe(int position)
{
// insert the word in the correct position of the subframe
std::memcpy(&d_subframe[position*GPS_WORD_LENGTH], &d_GPS_frame_4bytes, sizeof(char)*GPS_WORD_LENGTH);
// insert the word in the correct position of the subframe
std::memcpy(&d_subframe[position*GPS_WORD_LENGTH], &d_GPS_frame_4bytes, sizeof(char)*GPS_WORD_LENGTH);
}
void GpsL1CaSubframeFsm::gps_subframe_to_nav_msg()
{
int subframe_ID;
// NEW GPS SUBFRAME HAS ARRIVED!
subframe_ID = d_nav.subframe_decoder(this->d_subframe); //decode the subframe
std::cout << "NAVIGATION FSM: received subframe " << subframe_ID << " for satellite " << Gnss_Satellite(std::string("GPS"), i_satellite_PRN) << std::endl;
std::cout << "NAVIGATION FSM: received subframe "
<< subframe_ID << " for satellite "
<< Gnss_Satellite(std::string("GPS"), i_satellite_PRN) << std::endl;
d_nav.i_satellite_PRN = i_satellite_PRN;
d_nav.i_channel_ID = i_channel_ID;
d_nav.d_subframe_timestamp_ms = this->d_preamble_time_ms;
@@ -251,48 +257,52 @@ void GpsL1CaSubframeFsm::gps_subframe_to_nav_msg()
switch (subframe_ID)
{
case 3: //we have a new set of ephemeris data for the current SV
if (d_nav.satellite_validation()==true)
{
// get ephemeris object for this SV (mandatory)
Gps_Ephemeris ephemeris=d_nav.get_ephemeris();
d_ephemeris_queue->push(ephemeris);
}
break;
if (d_nav.satellite_validation() == true)
{
// get ephemeris object for this SV (mandatory)
Gps_Ephemeris ephemeris = d_nav.get_ephemeris();
d_ephemeris_queue->push(ephemeris);
}
break;
case 4: // Possible IONOSPHERE and UTC model update (page 18)
if (d_nav.flag_iono_valid==true)
{
Gps_Iono iono=d_nav.get_iono(); //notice that the read operation will clear the valid flag
d_iono_queue->push(iono);
}
if (d_nav.flag_utc_model_valid==true)
{
Gps_Utc_Model utc_model=d_nav.get_utc_model(); //notice that the read operation will clear the valid flag
d_utc_model_queue->push(utc_model);
}
break;
if (d_nav.flag_iono_valid == true)
{
Gps_Iono iono = d_nav.get_iono(); //notice that the read operation will clear the valid flag
d_iono_queue->push(iono);
}
if (d_nav.flag_utc_model_valid == true)
{
Gps_Utc_Model utc_model = d_nav.get_utc_model(); //notice that the read operation will clear the valid flag
d_utc_model_queue->push(utc_model);
}
break;
case 5:
// get almanac (if available)
//TODO: implement almanac reader in navigation_message
break;
// get almanac (if available)
//TODO: implement almanac reader in navigation_message
break;
default:
break;
break;
}
}
void GpsL1CaSubframeFsm::Event_gps_word_valid()
{
this->process_event(Ev_gps_word_valid());
this->process_event(Ev_gps_word_valid());
}
void GpsL1CaSubframeFsm::Event_gps_word_invalid()
{
this->process_event(Ev_gps_word_invalid());
this->process_event(Ev_gps_word_invalid());
}
void GpsL1CaSubframeFsm::Event_gps_word_preamble()
{
this->process_event(Ev_gps_word_preamble());
this->process_event(Ev_gps_word_preamble());
}

View File

@@ -67,46 +67,48 @@ struct gps_subframe_fsm_S9;
struct gps_subframe_fsm_S10;
struct gps_subframe_fsm_S11;
/*!
* \brief This class implements a Finite State Machine that handles the decoding
* of the GPS L1 C/A NAV message
*/
class GpsL1CaSubframeFsm : public sc::state_machine< GpsL1CaSubframeFsm, gps_subframe_fsm_S0 >
{
public:
// channel and satellite info
int i_channel_ID;
unsigned int i_satellite_PRN;
GpsL1CaSubframeFsm(); //!< The constructor starts the Finite State Machine
// ephemeris queue
concurrent_queue<Gps_Ephemeris> *d_ephemeris_queue;
// ionospheric parameters queue
concurrent_queue<Gps_Iono> *d_iono_queue;
// UTC model parameters queue
concurrent_queue<Gps_Utc_Model> *d_utc_model_queue;
// Almanac queue
concurrent_queue<Gps_Almanac> *d_almanac_queue;
// channel and satellite info
int i_channel_ID; //!< Channel id
unsigned int i_satellite_PRN; //!< Satellite PRN number
// navigation message class
Gps_Navigation_Message d_nav;
concurrent_queue<Gps_Ephemeris> *d_ephemeris_queue; //!< Ephemeris queue
concurrent_queue<Gps_Iono> *d_iono_queue; //!< Ionospheric parameters queue
concurrent_queue<Gps_Utc_Model> *d_utc_model_queue; //!< UTC model parameters queue
concurrent_queue<Gps_Almanac> *d_almanac_queue; //!< Almanac queue
// GPS SV and System parameters
Gps_Ephemeris ephemeris;
Gps_Almanac almanac;
Gps_Utc_Model utc_model;
Gps_Iono iono;
Gps_Navigation_Message d_nav; //!< GPS L1 C/A navigation message object
// GPS SV and System parameters
Gps_Ephemeris ephemeris; //!< Object that handles GPS ephemeris parameters
Gps_Almanac almanac; //!< Object that handles GPS almanac data
Gps_Utc_Model utc_model; //!< Object that handles UTM model parameters
Gps_Iono iono; //!< Object that handles ionospheric parameters
char d_subframe[GPS_SUBFRAME_LENGTH];
char d_GPS_frame_4bytes[GPS_WORD_LENGTH];
char d_subframe[GPS_SUBFRAME_LENGTH];
char d_GPS_frame_4bytes[GPS_WORD_LENGTH];
double d_preamble_time_ms;
double d_preamble_time_ms;
void gps_word_to_subframe(int position); //!< inserts the word in the correct position of the subframe
void gps_word_to_subframe(int position);
void gps_subframe_to_nav_msg();
/*!
* \brief This function decodes a NAv message subframe and pushes the information to the right queues
*/
void gps_subframe_to_nav_msg();
//FSM EVENTS
void Event_gps_word_valid();
void Event_gps_word_invalid();
void Event_gps_word_preamble();
GpsL1CaSubframeFsm();
//FSM EVENTS
void Event_gps_word_valid(); //!< FSM event: the received word is valid
void Event_gps_word_invalid(); //!< FSM event: the received word is not valid
void Event_gps_word_preamble(); //!< FSM event: word preamble detected
};
#endif

View File

@@ -47,7 +47,6 @@
Viterbi_Decoder::Viterbi_Decoder(const int g_encoder[], const int KK, const int nn)
{
d_nn = nn; //Coding rate 1/n
d_KK = KK; //Constraint Length
@@ -84,27 +83,25 @@ Viterbi_Decoder::~Viterbi_Decoder()
delete[] d_metric_c;
}
void
Viterbi_Decoder::reset()
void Viterbi_Decoder::reset()
{
init_trellis_state();
}
/* Function decode_block()
Description: Uses the Viterbi algorithm to perform hard-decision decoding of a convolutional code.
Input parameters:
r[] The received signal in LLR-form. For BPSK, must be in form r = 2*a*y/(sigma^2).
LL The number of data bits to be decoded (doen't inlcude the mm zero-tail-bits)
r[] The received signal in LLR-form. For BPSK, must be in form r = 2*a*y/(sigma^2).
LL The number of data bits to be decoded (doen't inlcude the mm zero-tail-bits)
Output parameters:
output_u_int[] Hard decisions on the data bits (without the mm zero-tail-bits)
output_u_int[] Hard decisions on the data bits (without the mm zero-tail-bits)
*/
float
Viterbi_Decoder::decode_block(const double input_c[], int output_u_int[], const int LL)
float Viterbi_Decoder::decode_block(const double input_c[], int output_u_int[], const int LL)
{
int state;
int decoding_length_mismatch;
@@ -125,9 +122,13 @@ Viterbi_Decoder::decode_block(const double input_c[], int output_u_int[], const
return d_indicator_metric;
}
float
Viterbi_Decoder::decode_continuous(const double sym[], const int traceback_depth, int bits[],
const int nbits_requested, int &nbits_decoded)
float Viterbi_Decoder::decode_continuous(const double sym[],
const int traceback_depth,
int bits[],
const int nbits_requested,
int &nbits_decoded)
{
int state;
int decoding_length_mismatch;
@@ -150,11 +151,11 @@ Viterbi_Decoder::decode_continuous(const double sym[], const int traceback_depth
return d_indicator_metric;
}
void
Viterbi_Decoder::init_trellis_state()
void Viterbi_Decoder::init_trellis_state()
{
int state;
// if trellis state has been initialised, free old state memory
if(d_trellis_state_is_initialised)
{
@@ -182,8 +183,10 @@ Viterbi_Decoder::init_trellis_state()
d_indicator_metric = 0;
}
int
Viterbi_Decoder::do_acs(const double sym[], int nbits)
int Viterbi_Decoder::do_acs(const double sym[], int nbits)
{
int t, i, state_at_t;
float metric;
@@ -202,11 +205,9 @@ Viterbi_Decoder::do_acs(const double sym[], int nbits)
pm_t_next[state_at_t] = -MAXLOG;
}
/* go through trellis */
for (t = 0; t < nbits; t++)
{
/* 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];
@@ -223,7 +224,6 @@ Viterbi_Decoder::do_acs(const double sym[], int nbits)
/* step through all states */
for (state_at_t = 0; state_at_t < d_states; state_at_t++)
{
int next_state_if_0 = d_state0[state_at_t];
int next_state_if_1 = d_state1[state_at_t];
@@ -256,7 +256,6 @@ Viterbi_Decoder::do_acs(const double sym[], int nbits)
d_trellis_paths.push_front(next_trellis_states);
/* normalize -> afterwards, the largest metric value is always 0 */
//max_val = 0;
max_val = -MAXLOG;
@@ -275,14 +274,14 @@ Viterbi_Decoder::do_acs(const double sym[], int nbits)
}
}
delete[] pm_t_next;
return t;
}
int
Viterbi_Decoder::do_traceback(size_t traceback_length)
int Viterbi_Decoder::do_traceback(size_t traceback_length)
{
// traceback_length is in bits
int state;
@@ -303,17 +302,17 @@ Viterbi_Decoder::do_traceback(size_t traceback_length)
return state;
}
int
Viterbi_Decoder::do_tb_and_decode(int traceback_length, int requested_decoding_length, int state, int output_u_int[], float& indicator_metric)
int Viterbi_Decoder::do_tb_and_decode(int traceback_length, int requested_decoding_length, int state, int output_u_int[], float& indicator_metric)
{
int n_of_branches_for_indicator_metric = 500;
int t_out;
std::deque<Prev>::iterator it;
int decoding_length_mismatch;
int overstep_length;
int n_im=0;
int n_im = 0;
VLOG(FLOW) << "do_tb_and_decode(): requested_decoding_length=" << requested_decoding_length;
@@ -323,12 +322,13 @@ Viterbi_Decoder::do_tb_and_decode(int traceback_length, int requested_decoding_l
overstep_length = decoding_length_mismatch >= 0 ? decoding_length_mismatch : 0;
VLOG(BLOCK) << "overstep_length=" << overstep_length;
for (it = d_trellis_paths.begin() + traceback_length; it < d_trellis_paths.begin()+traceback_length + overstep_length; ++it)
for (it = d_trellis_paths.begin() + traceback_length;
it < d_trellis_paths.begin() + traceback_length + overstep_length; ++it)
{
state = it->get_anchestor_state_of_current_state(state);
}
t_out = d_trellis_paths.end()-(d_trellis_paths.begin() + traceback_length + overstep_length)-1;//requested_decoding_length-1;
t_out = d_trellis_paths.end() - (d_trellis_paths.begin() + traceback_length + overstep_length) - 1;//requested_decoding_length-1;
indicator_metric = 0;
for (it = d_trellis_paths.begin() + traceback_length + overstep_length; it < d_trellis_paths.end(); ++it)
{
@@ -342,19 +342,20 @@ Viterbi_Decoder::do_tb_and_decode(int traceback_length, int requested_decoding_l
}
output_u_int[t_out] = it->get_bit_of_current_state(state);
state = it->get_anchestor_state_of_current_state(state);
t_out--;
}
indicator_metric/=n_im;
indicator_metric /= n_im;
VLOG(BLOCK) << "indicator metric: " << indicator_metric;
// remove old states
if (d_trellis_paths.begin() + traceback_length+overstep_length <= d_trellis_paths.end())
if (d_trellis_paths.begin() + traceback_length + overstep_length <= d_trellis_paths.end())
{
d_trellis_paths.erase(d_trellis_paths.begin()+traceback_length+overstep_length, d_trellis_paths.end());
d_trellis_paths.erase(d_trellis_paths.begin() + traceback_length+overstep_length, d_trellis_paths.end());
}
return decoding_length_mismatch;
}
/* function Gamma()
Description: Computes the branch metric used for decoding.
@@ -426,8 +427,7 @@ Viterbi_Decoder::nsc_transit(int output_p[], int trans_p[], int input, const int
This function is used by rsc_encode(), nsc_transit(), rsc_transit(), and nsc_transit() */
int
Viterbi_Decoder::nsc_enc_bit(int state_out_p[], int input, int state_in,
int Viterbi_Decoder::nsc_enc_bit(int state_out_p[], int input, int state_in,
const int g[], int KK, int nn)
{
/* declare variables */
@@ -462,18 +462,15 @@ Viterbi_Decoder::nsc_enc_bit(int state_out_p[], int input, int state_in,
This function is used by nsc_enc_bit(), rsc_enc_bit(), and rsc_tail() */
int
Viterbi_Decoder::parity_counter(int symbol, int length)
int Viterbi_Decoder::parity_counter(int symbol, int length)
{
int counter;
int temp_parity = 0;
for (counter = 0; counter < length; counter++)
{
temp_parity = temp_parity ^ (symbol & 1);
symbol = symbol >> 1;
}
return (temp_parity);
}
@@ -486,27 +483,26 @@ Viterbi_Decoder::Prev::Prev(int states, int t)
state = new int[states];
bit = new int[states];
metric = new float[states];
refcount = new int;
*refcount = 1;
//std::cout << "Prev(" << states << ", " << t << ")" << " constructor" << std::endl;
}
// copy constructor
Viterbi_Decoder::Prev::Prev(const Prev& prev)
{
refcount = prev.refcount;
(*refcount)++;
t = prev.t;
state = prev.state;
bit = prev.bit;
metric = prev.metric;
VLOG(LMORE) << "Prev(" << "?" << ", " << t << ")" << " copy, new refcount = " << *refcount;
}
// assignment constructor
Viterbi_Decoder::Prev& Viterbi_Decoder::Prev::operator=(const Prev& other)
{
@@ -517,7 +513,7 @@ Viterbi_Decoder::Prev& Viterbi_Decoder::Prev::operator=(const Prev& other)
}
// handle old resources
if(*refcount==1)
if(*refcount == 1)
{ // if they are not used anymore -> unallocate them
delete[] state;
delete[] bit;
@@ -543,6 +539,9 @@ Viterbi_Decoder::Prev& Viterbi_Decoder::Prev::operator=(const Prev& other)
return *this;
}
Viterbi_Decoder::Prev::~Prev()
{
if (*refcount == 1)
@@ -560,12 +559,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;
return state[current_state];
}
int Viterbi_Decoder::Prev::get_bit_of_current_state(int current_state)
{
//std::cout << "get prev bit : for state " << current_state << " at time " << t << ", the send bit is " << bit[current_state] << std::endl;

View File

@@ -29,8 +29,8 @@
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_VITERBIDECODER_H_
#define GNSS_SDR_VITERBIDECODER_H_
#ifndef GNSS_SDR_VITERBI_DECODER_H_
#define GNSS_SDR_VITERBI_DECODER_H_
#include <deque>
#include <iostream>
@@ -41,12 +41,22 @@ public:
Viterbi_Decoder(const int g_encoder[], const int KK, const int nn);
~Viterbi_Decoder();
void reset();
/*!
* \brief Uses the Viterbi algorithm to perform hard-decision decoding of a convolutional code.
*
* \param input_c[] The received signal in LLR-form. For BPSK, must be in form r = 2*a*y/(sigma^2).
* \param LL The number of data bits to be decoded (does not include the mm zero-tail-bits)
*
* \return output_u_int[] Hard decisions on the data bits (without the mm zero-tail-bits)
*/
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);
private:
class Prev
{
public:
@@ -111,4 +121,4 @@ private:
int parity_counter(int symbol, int length);
};
#endif /* GNSS_SDR_VITERBIDECODER_H_ */
#endif /* GNSS_SDR_VITERBI_DECODER_H_ */