1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-12 19:20:32 +00:00

Work on the telemetry decoder to support the variable-length correlator in GPS L1 CA tracking

This commit is contained in:
Javier Arribas 2016-03-17 18:54:41 +01:00
parent 2f61ad7c64
commit 840bb1b9a3
5 changed files with 122 additions and 132 deletions

View File

@ -59,16 +59,16 @@ gps_l1_ca_make_telemetry_decoder_cc(Gnss_Satellite satellite, boost::shared_ptr<
void gps_l1_ca_telemetry_decoder_cc::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
if (noutput_items != 0)
{
for (unsigned i = 0; i < 3; i++)
{
ninput_items_required[i] = d_samples_per_bit * 8; //set the required sample history
}
}
}
//void gps_l1_ca_telemetry_decoder_cc::forecast (int noutput_items, gr_vector_int &ninput_items_required)
//{
// if (noutput_items != 0)
// {
// for (unsigned i = 0; i < 3; i++)
// {
// ninput_items_required[i] = d_samples_per_bit * 8; //set the required sample history
// }
// }
//}
@ -181,114 +181,101 @@ int gps_l1_ca_telemetry_decoder_cc::general_work (int noutput_items, gr_vector_i
// ########### Output the tracking data to navigation and PVT ##########
const Gnss_Synchro **in = (const Gnss_Synchro **) &input_items[0]; //Get the input samples pointer
// TODO Optimize me!
if (in[0][d_samples_per_bit*8 - 1].symbol_integration_enabled==false)
// keep the last valid symbols
if (in[0]->Flag_valid_symbol_output==true)
{
//******* preamble correlation ********
for (unsigned int i = 0; i < d_samples_per_bit*8; i++)
d_symbol_history.push_back(in[0]->Prompt_I);
if (static_cast<int>(d_symbol_history.size())>GPS_CA_PREAMBLE_LENGTH_SYMBOLS)
{
if (in[0][i].Prompt_I < 0) // symbols clipping
{
corr_value -= d_preambles_symbols[i];
}
else
{
corr_value += d_preambles_symbols[i];
}
d_symbol_history.pop_front();
}
}else{
//******* preamble correlation ********
for (unsigned int i = 0; i < d_samples_per_bit*8; i++)
{
if (in[0][i].Flag_valid_symbol_output==true)
{
if (in[0][i].Prompt_I < 0) // symbols clipping
if (d_symbol_history.size()==GPS_CA_PREAMBLE_LENGTH_SYMBOLS)
{
//******* preamble correlation ********
int current_symbol_index=0;
for (int i = 0; i < GPS_CA_PREAMBLE_LENGTH_SYMBOLS/in[0]->correlation_length_ms; i++)
{
current_symbol_index=i*in[0]->correlation_length_ms;//+static_cast<int>(floor(in[0]->correlation_length_ms/2));
if (d_symbol_history.at(i) < 0) // symbols clipping
{
corr_value -= d_preambles_symbols[i]*d_samples_per_bit;
//symbol weight expansion using the current tracking correlation length
corr_value -= d_preambles_symbols[current_symbol_index]*in[0]->correlation_length_ms;
}
else
{
corr_value += d_preambles_symbols[i]*d_samples_per_bit;
//symbol weight expansion using the current tracking correlation length
corr_value += d_preambles_symbols[current_symbol_index]*in[0]->correlation_length_ms;
}
}
}
}
}
if (abs(corr_value)>120)
{
std::cout<<abs(corr_value)<<std::endl;
}
}
d_flag_preamble = false;
//******* frame sync ******************
if (abs(corr_value) == 160)
{
//TODO: Rewrite with state machine
if (d_stat == 0)
{
d_GPS_FSM.Event_gps_word_preamble();
d_preamble_index = d_sample_counter;//record the preamble sample stamp
DLOG(INFO) << "Preamble detection for SAT " << this->d_satellite;
d_symbol_accumulator = 0; //sync the symbol to bits integrator
d_symbol_accumulator_counter = 0;
d_frame_bit_index = 7;
d_stat = 1; // enter into frame pre-detection status
}
else if (d_stat == 1) //check 6 seconds of preamble separation
{
preamble_diff = d_sample_counter - d_preamble_index;
if (abs(preamble_diff - 6000) < 1)
{
d_GPS_FSM.Event_gps_word_preamble();
d_flag_preamble = true;
d_preamble_index = d_sample_counter; //record the preamble sample stamp (t_P)
d_preamble_time_seconds = in[0][0].Tracking_timestamp_secs;// - d_preamble_duration_seconds; //record the PRN start sample index associated to the preamble
d_frame_bit_index = 7;
if (!d_flag_frame_sync)
{
//send asynchronous message to tracking to inform of frame sync and extend correlation time
pmt::pmt_t value = pmt::from_long(d_preamble_index-1);
this->message_port_pub(pmt::mp("preamble_index"),value);
if (abs(corr_value) == GPS_CA_PREAMBLE_LENGTH_SYMBOLS)
{
if (d_stat == 0)
{
d_GPS_FSM.Event_gps_word_preamble();
d_preamble_index = d_sample_counter;//record the preamble sample stamp
std::cout << "Preamble detection for SAT " << this->d_satellite;
d_symbol_accumulator = 0; //sync the symbol to bits integrator
d_symbol_accumulator_counter = 0;
d_frame_bit_index = 7;
d_stat = 1; // enter into frame pre-detection status
}
else if (d_stat == 1) //check 6 seconds of preamble separation
{
preamble_diff = d_sample_counter - d_preamble_index;
if (abs(preamble_diff - 6000) < 1)
{
std::cout <<"preamble! corr lenght="<<in[0]->correlation_length_ms<<std::endl;
d_GPS_FSM.Event_gps_word_preamble();
d_flag_preamble = true;
d_preamble_index = d_sample_counter; //record the preamble sample stamp (t_P)
d_preamble_time_seconds = in[0][0].Tracking_timestamp_secs;// - d_preamble_duration_seconds; //record the PRN start sample index associated to the preamble
d_frame_bit_index = 7;
if (!d_flag_frame_sync)
{
//send asynchronous message to tracking to inform of frame sync and extend correlation time
pmt::pmt_t value = pmt::from_long(d_preamble_index-2);
this->message_port_pub(pmt::mp("preamble_index"),value);
d_flag_frame_sync = true;
if (corr_value < 0)
{
flag_PLL_180_deg_phase_locked = true; //PLL is locked to opposite phase!
DLOG(INFO) << " PLL in opposite phase for Sat "<< this->d_satellite.get_PRN();
}
else
{
flag_PLL_180_deg_phase_locked = false;
}
DLOG(INFO) << " Frame sync SAT " << this->d_satellite << " with preamble start at " << d_preamble_time_seconds << " [s]";
}
}
}
}
else
{
if (d_stat == 1)
{
preamble_diff = d_sample_counter - d_preamble_index;
if (preamble_diff > 6001)
{
DLOG(INFO) << "Lost of frame sync SAT " << this->d_satellite << " preamble_diff= " << preamble_diff;
d_stat = 0; //lost of frame sync
d_flag_frame_sync = false;
flag_TOW_set = false;
}
}
}
d_flag_frame_sync = true;
if (corr_value < 0)
{
flag_PLL_180_deg_phase_locked = true; //PLL is locked to opposite phase!
std::cout << " PLL in opposite phase for Sat "<< this->d_satellite.get_PRN();
}
else
{
flag_PLL_180_deg_phase_locked = false;
}
std::cout << " Frame sync SAT " << this->d_satellite << " with preamble start at " << d_preamble_time_seconds << " [s]";
}
}else{
if (preamble_diff > 6001)
{
std::cout << "Lost of frame sync SAT " << this->d_satellite << " preamble_diff= " << preamble_diff;
d_stat = 0; //lost of frame sync
d_flag_frame_sync = false;
flag_TOW_set = false;
}
}
}
}
//******* SYMBOL TO BIT *******
if (in[0][d_samples_per_bit*8 - 1].Flag_valid_symbol_output==true)
if (in[0]->Flag_valid_symbol_output==true)
{
if (in[0][d_samples_per_bit*8 - 1].symbol_integration_enabled==true)
{
// extended correlation to bit period is enabled in tracking!
// 1 symbol = 1 bit
d_symbol_accumulator = in[0][d_samples_per_bit*8 - 1].Prompt_I; // accumulate the input value in d_symbol_accumulator
d_symbol_accumulator_counter=20;
}else{
// 20 symbols = 1 bit: do symbols integration in telemetry decoder
d_symbol_accumulator += in[0][d_samples_per_bit*8 - 1].Prompt_I; // accumulate the input value in d_symbol_accumulator
d_symbol_accumulator_counter++;
}
// extended correlation to bit period is enabled in tracking!
d_symbol_accumulator += in[0]->Prompt_I; // accumulate the input value in d_symbol_accumulator
d_symbol_accumulator_counter+=in[0]->correlation_length_ms;
}
if (d_symbol_accumulator_counter == 20 )
@ -342,8 +329,6 @@ int gps_l1_ca_telemetry_decoder_cc::general_work (int noutput_items, gr_vector_i
{
d_GPS_frame_4bytes <<= 1; //shift 1 bit left the telemetry word
}
}
// output the frame
consume_each(1); //one by one
@ -381,8 +366,8 @@ int gps_l1_ca_telemetry_decoder_cc::general_work (int noutput_items, gr_vector_i
if (flag_PLL_180_deg_phase_locked == true)
{
//correct the accumulated phase for the costas loop phase shift, if required
current_synchro_data.Carrier_phase_rads += GPS_PI;
//correct the accumulated phase for the costas loop phase shift, if required
current_synchro_data.Carrier_phase_rads += GPS_PI;
}
if(d_dump == true)

View File

@ -85,7 +85,7 @@ public:
* \brief Function which tells the scheduler how many input items
* are required to produce noutput_items output items.
*/
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
//void forecast (int noutput_items, gr_vector_int &ninput_items_required);
private:
friend gps_l1_ca_telemetry_decoder_cc_sptr
@ -107,6 +107,7 @@ private:
bool d_flag_frame_sync;
// symbols
std::deque<double> d_symbol_history;
double d_symbol_accumulator;
short int d_symbol_accumulator_counter;
@ -138,10 +139,6 @@ private:
double d_TOW_at_Preamble;
double d_TOW_at_current_symbol;
std::deque<double> d_symbol_TOW_queue_s;
// Doppler and Phase accumulator queue for interpolation in Observables
std::deque<double> d_carrier_doppler_queue_hz;
std::deque<double> d_acc_carrier_phase_queue_rads;
double Prn_timestamp_at_preamble_ms;
bool flag_TOW_set;

View File

@ -347,6 +347,8 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
d_pull_in = false;
// Fill the acquisition data
current_synchro_data = *d_acquisition_gnss_synchro;
current_synchro_data.correlation_length_ms=1;
current_synchro_data.Flag_valid_symbol_output = false;
*out[0] = current_synchro_data;
consume_each(samples_offset); //shift input to perform alignment with local replica
d_symbol_counter++;
@ -361,13 +363,13 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
multicorrelator_cpu.set_input_output_vectors(d_correlator_outs,in);
multicorrelator_cpu.Carrier_wipeoff_multicorrelator_resampler(d_rem_carrier_phase_rad, d_carrier_phase_step_rad, d_rem_code_phase_chips, d_code_phase_step_chips, d_correlation_length_samples);
// ####### 20ms coherent intergration extension (experimental)
// keep the last 40 symbols (2 bits to detect transitions)
// ####### coherent intergration extension
// keep the last symbols
d_E_history.push_back(d_correlator_outs[0]); // save early output
d_P_history.push_back(d_correlator_outs[1]); // save prompt output
d_L_history.push_back(d_correlator_outs[2]); // save late output
if (d_P_history.size()>d_extend_correlation_ms)
if (static_cast<int>(d_P_history.size())>d_extend_correlation_ms)
{
d_E_history.pop_front();
d_P_history.pop_front();
@ -382,7 +384,6 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
{
// compute coherent integration and enable tracking loop
// perform coherent integration using correlator output history
//gr_complex d_correlator_outs_2[3];
//std::cout<<"##### RESET COHERENT INTEGRATION ####"<<std::endl;
d_correlator_outs[0]=gr_complex(0.0,0.0);
d_correlator_outs[1]=gr_complex(0.0,0.0);
@ -402,14 +403,11 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
std::cout<<"dll="<<d_dll_bw_hz<<" dll_n="<<d_dll_bw_narrow_hz<<" pll="<<d_pll_bw_hz<<" pll_n="<<d_pll_bw_narrow_hz<<std::endl;
}
current_synchro_data.symbol_integration_enabled=true;
// UPDATE INTEGRATION TIME
CURRENT_INTEGRATION_TIME_S = static_cast<double>(d_extend_correlation_ms)*GPS_L1_CA_CODE_PERIOD;
enable_dll_pll=true;
}else{
current_synchro_data.symbol_integration_enabled=false;
if(d_preamble_synchronized==true)
{
// continue extended coherent correlation
@ -434,6 +432,10 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
//remnant code phase [chips]
d_rem_code_phase_chips = d_rem_code_phase_samples * (d_code_freq_chips / static_cast<double>(d_fs_in));
// UPDATE ACCUMULATED CARRIER PHASE
CORRECTED_INTEGRATION_TIME_S=(static_cast<double>(d_correlation_length_samples)/static_cast<double>(d_fs_in));
d_acc_carrier_phase_cycles -= d_carrier_doppler_hz * CORRECTED_INTEGRATION_TIME_S;
// disable tracking loop and inform telemetry decoder
enable_dll_pll=false;
}else{
@ -444,13 +446,11 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
}
}
}else{
current_synchro_data.symbol_integration_enabled=false;
// UPDATE INTEGRATION TIME
CURRENT_INTEGRATION_TIME_S = static_cast<double>(d_correlation_length_samples) / static_cast<double>(d_fs_in);
enable_dll_pll=true;
}
// ###### end 20ms correlation extension
if (enable_dll_pll==true)
{
@ -498,7 +498,7 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
d_correlation_length_samples = K_prn_samples + d_rem_code_phase_integer_samples; //round to a discrete samples
d_rem_code_phase_samples=d_rem_code_phase_samples-d_rem_code_phase_integer_samples;
// UPDATE REMNANT CARRIER PHASE
// UPDATE ACCUMULATED CARRIER PHASE
CORRECTED_INTEGRATION_TIME_S=(static_cast<double>(d_correlation_length_samples)/static_cast<double>(d_fs_in));
//remnant carrier phase [rad]
d_rem_carrier_phase_rad = fmod(d_rem_carrier_phase_rad + GPS_TWO_PI * d_carrier_doppler_hz * CORRECTED_INTEGRATION_TIME_S, GPS_TWO_PI);
@ -527,13 +527,8 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
{
d_cn0_estimation_counter = 0;
// Code lock indicator
if (current_synchro_data.symbol_integration_enabled==false)
{
d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS);
}else{
d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS*d_extend_correlation_ms);
}
// Carrier lock indicator
d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS);
// Carrier lock indicator
d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES);
// Loss of lock detection
if (d_carrier_lock_test < d_carrier_lock_threshold or d_CN0_SNV_dB_Hz < MINIMUM_VALID_CN0)
@ -569,6 +564,12 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
current_synchro_data.CN0_dB_hz = d_CN0_SNV_dB_Hz;
current_synchro_data.Flag_valid_pseudorange = false;
current_synchro_data.Flag_valid_symbol_output = true;
if (d_preamble_synchronized==true)
{
current_synchro_data.correlation_length_ms=d_extend_correlation_ms;
}else{
current_synchro_data.correlation_length_ms=1;
}
*out[0] = current_synchro_data;
}else{
//todo: fill synchronization data to produce output while coherent integration is running
@ -579,10 +580,16 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
current_synchro_data.Tracking_timestamp_secs = (static_cast<double>(d_sample_counter) + d_rem_code_phase_samples) / static_cast<double>(d_fs_in);
// This tracking block aligns the Tracking_timestamp_secs with the start sample of the PRN, thus, Code_phase_secs=0
current_synchro_data.Code_phase_secs = 0;
current_synchro_data.Carrier_phase_rads = GPS_TWO_PI * d_acc_carrier_phase_cycles; // todo: project the acc carrier phase
current_synchro_data.Carrier_phase_rads = GPS_TWO_PI * d_acc_carrier_phase_cycles;
current_synchro_data.Carrier_Doppler_hz = d_carrier_doppler_hz;// todo: project the carrier doppler
current_synchro_data.CN0_dB_hz = d_CN0_SNV_dB_Hz;
current_synchro_data.Flag_valid_pseudorange = false;
if (d_preamble_synchronized==true)
{
current_synchro_data.correlation_length_ms=d_extend_correlation_ms;
}else{
current_synchro_data.correlation_length_ms=1;
}
*out[0] = current_synchro_data;
}
@ -597,7 +604,7 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
{
d_last_seg = floor(d_sample_counter / d_fs_in);
std::cout << "Current input signal time = " << d_last_seg << " [s]" << std::endl;
std::cout << "GPS L1 C/A Tracking CH " << d_channel << ": Satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN)
DLOG(INFO) << "GPS L1 C/A Tracking CH " << d_channel << ": Satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN)
<< ", CN0 = " << d_CN0_SNV_dB_Hz << " [dB-Hz]" << std::endl;
//if (d_last_seg==5) d_carrier_lock_fail_counter=500; //DEBUG: force unlock!
}
@ -607,7 +614,7 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work (int noutput_items, gr_vec
if (floor(d_sample_counter / d_fs_in) != d_last_seg)
{
d_last_seg = floor(d_sample_counter / d_fs_in);
std::cout << "Tracking CH " << d_channel << ": Satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN)
DLOG(INFO) << "Tracking CH " << d_channel << ": Satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN)
<< ", CN0 = " << d_CN0_SNV_dB_Hz << " [dB-Hz]";
}
}

View File

@ -74,6 +74,7 @@ const int GPS_L1_CA_HISTORY_DEEP = 100;
#define GPS_PREAMBLE {1, 0, 0, 0, 1, 0, 1, 1}
const int GPS_CA_PREAMBLE_LENGTH_BITS = 8;
const int GPS_CA_PREAMBLE_LENGTH_SYMBOLS = 160;
const int GPS_CA_TELEMETRY_RATE_BITS_SECOND = 50; //!< NAV message bit rate [bits/s]
const int GPS_CA_TELEMETRY_SYMBOLS_PER_BIT = 20;
const int GPS_CA_TELEMETRY_RATE_SYMBOLS_SECOND = GPS_CA_TELEMETRY_RATE_BITS_SECOND*20; //!< NAV message bit rate [symbols/s]

View File

@ -61,7 +61,7 @@ public:
double Tracking_timestamp_secs; //!< Set by Tracking processing block
bool Flag_valid_tracking;
bool Flag_valid_symbol_output;
bool symbol_integration_enabled; //!< Set by Tracking processing block
int correlation_length_ms; //!< Set by Tracking processing block
//Telemetry Decoder
double Prn_timestamp_ms; //!< Set by Telemetry Decoder processing block