mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-31 15:23:04 +00:00 
			
		
		
		
	Improve C/N0 estimation
This commit is contained in:
		| @@ -606,7 +606,7 @@ bool dll_pll_veml_tracking::acquire_secondary() | ||||
| } | ||||
|  | ||||
|  | ||||
| bool dll_pll_veml_tracking::cn0_and_tracking_lock_status() | ||||
| bool dll_pll_veml_tracking::cn0_and_tracking_lock_status(double coh_integration_time_s) | ||||
| { | ||||
|     // ####### CN0 ESTIMATION AND LOCK DETECTORS ###### | ||||
|     if (d_cn0_estimation_counter < FLAGS_cn0_samples) | ||||
| @@ -620,7 +620,7 @@ bool dll_pll_veml_tracking::cn0_and_tracking_lock_status() | ||||
|         { | ||||
|             d_cn0_estimation_counter = 0; | ||||
|             // Code lock indicator | ||||
|             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, static_cast<long>(trk_parameters.fs_in), static_cast<double>(d_code_length_chips)); | ||||
|             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, coh_integration_time_s); | ||||
|             // Carrier lock indicator | ||||
|             d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, FLAGS_cn0_samples); | ||||
|             // Loss of lock detection | ||||
| @@ -1233,7 +1233,7 @@ int dll_pll_veml_tracking::general_work(int noutput_items __attribute__((unused) | ||||
|                 d_L_accu = *d_Late; | ||||
|  | ||||
|                 // Check lock status | ||||
|                 if (!cn0_and_tracking_lock_status()) | ||||
|                 if (!cn0_and_tracking_lock_status(static_cast<double>(d_correlation_length_ms) * 1000.0)) | ||||
|                     { | ||||
|                         clear_tracking_vars(); | ||||
|                         d_state = 0;  // loss-of-lock detected | ||||
| @@ -1411,7 +1411,7 @@ int dll_pll_veml_tracking::general_work(int noutput_items __attribute__((unused) | ||||
|                 save_correlation_results(); | ||||
|  | ||||
|                 // check lock status | ||||
|                 if (!cn0_and_tracking_lock_status()) | ||||
|                 if (!cn0_and_tracking_lock_status(static_cast<double>(d_correlation_length_ms) * 1000.0 * static_cast<double>(trk_parameters.extend_correlation_symbols))) | ||||
|                     { | ||||
|                         clear_tracking_vars(); | ||||
|                         d_state = 0;  // loss-of-lock detected | ||||
|   | ||||
| @@ -88,7 +88,7 @@ private: | ||||
|  | ||||
|     dll_pll_veml_tracking(dllpllconf_t conf_); | ||||
|  | ||||
|     bool cn0_and_tracking_lock_status(); | ||||
|     bool cn0_and_tracking_lock_status(double coh_integration_time_s); | ||||
|     bool acquire_secondary(); | ||||
|     void do_correlation_step(const gr_complex *input_samples); | ||||
|     void run_dll_pll(); | ||||
|   | ||||
| @@ -381,7 +381,7 @@ int Galileo_E1_Tcp_Connector_Tracking_cc::general_work(int noutput_items __attri | ||||
|                     d_cn0_estimation_counter = 0; | ||||
|  | ||||
|                     // Code lock indicator | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, d_fs_in, Galileo_E1_B_CODE_LENGTH_CHIPS); | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, Galileo_E1_CODE_PERIOD); | ||||
|  | ||||
|                     // Carrier lock indicator | ||||
|                     d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, FLAGS_cn0_samples); | ||||
|   | ||||
| @@ -762,7 +762,7 @@ int glonass_l1_ca_dll_pll_c_aid_tracking_cc::general_work(int noutput_items __at | ||||
|                         { | ||||
|                             d_cn0_estimation_counter = 0; | ||||
|                             // Code lock indicator | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GLONASS_L1_CA_CODE_LENGTH_CHIPS); | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, GLONASS_L1_CA_CODE_PERIOD); | ||||
|                             // Carrier lock indicator | ||||
|                             d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES); | ||||
|                             // Loss of lock detection | ||||
|   | ||||
| @@ -753,7 +753,7 @@ int glonass_l1_ca_dll_pll_c_aid_tracking_sc::general_work(int noutput_items __at | ||||
|                         { | ||||
|                             d_cn0_estimation_counter = 0; | ||||
|                             // Code lock indicator | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GLONASS_L1_CA_CODE_LENGTH_CHIPS); | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, GLONASS_L1_CA_CODE_PERIOD); | ||||
|                             // Carrier lock indicator | ||||
|                             d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES); | ||||
|                             // Loss of lock detection | ||||
|   | ||||
| @@ -622,7 +622,7 @@ int Glonass_L1_Ca_Dll_Pll_Tracking_cc::general_work(int noutput_items __attribut | ||||
|                 { | ||||
|                     d_cn0_estimation_counter = 0; | ||||
|                     // Code lock indicator | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GLONASS_L1_CA_CODE_LENGTH_CHIPS); | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, GLONASS_L1_CA_CODE_PERIOD); | ||||
|                     // Carrier lock indicator | ||||
|                     d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES); | ||||
|                     // Loss of lock detection | ||||
|   | ||||
| @@ -759,7 +759,7 @@ int glonass_l2_ca_dll_pll_c_aid_tracking_cc::general_work(int noutput_items __at | ||||
|                         { | ||||
|                             d_cn0_estimation_counter = 0; | ||||
|                             // Code lock indicator | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GLONASS_L2_CA_CODE_LENGTH_CHIPS); | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, GLONASS_L2_CA_CODE_PERIOD); | ||||
|                             // Carrier lock indicator | ||||
|                             d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES); | ||||
|                             // Loss of lock detection | ||||
|   | ||||
| @@ -751,7 +751,7 @@ int glonass_l2_ca_dll_pll_c_aid_tracking_sc::general_work(int noutput_items __at | ||||
|                         { | ||||
|                             d_cn0_estimation_counter = 0; | ||||
|                             // Code lock indicator | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GLONASS_L2_CA_CODE_LENGTH_CHIPS); | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, GLONASS_L2_CA_CODE_PERIOD); | ||||
|                             // Carrier lock indicator | ||||
|                             d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES); | ||||
|                             // Loss of lock detection | ||||
|   | ||||
| @@ -622,7 +622,7 @@ int Glonass_L2_Ca_Dll_Pll_Tracking_cc::general_work(int noutput_items __attribut | ||||
|                 { | ||||
|                     d_cn0_estimation_counter = 0; | ||||
|                     // Code lock indicator | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, GLONASS_L2_CA_CODE_LENGTH_CHIPS); | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, GLONASS_L2_CA_CODE_PERIOD); | ||||
|                     // Carrier lock indicator | ||||
|                     d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES); | ||||
|                     // Loss of lock detection | ||||
|   | ||||
| @@ -741,7 +741,7 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work(int noutput_items __attrib | ||||
|                         { | ||||
|                             d_cn0_estimation_counter = 0; | ||||
|                             // Code lock indicator | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS); | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, GPS_L1_CA_CODE_PERIOD); | ||||
|                             // Carrier lock indicator | ||||
|                             d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, FLAGS_cn0_samples); | ||||
|                             // Loss of lock detection | ||||
| @@ -842,7 +842,8 @@ int gps_l1_ca_dll_pll_c_aid_tracking_cc::general_work(int noutput_items __attrib | ||||
|                     // PLL commands | ||||
|                     tmp_float = 1.0 / (d_carr_phase_error_secs_Ti * CURRENT_INTEGRATION_TIME_S); | ||||
|                     d_dump_file.write(reinterpret_cast<char *>(&tmp_float), sizeof(float)); | ||||
|                     tmp_float = 1.0 / (d_code_error_filt_chips_Ti  * CURRENT_INTEGRATION_TIME_S);; | ||||
|                     tmp_float = 1.0 / (d_code_error_filt_chips_Ti * CURRENT_INTEGRATION_TIME_S); | ||||
|                     ; | ||||
|                     d_dump_file.write(reinterpret_cast<char *>(&tmp_float), sizeof(float)); | ||||
|                     // DLL commands | ||||
|                     tmp_float = d_code_error_chips_Ti * CURRENT_INTEGRATION_TIME_S; | ||||
|   | ||||
| @@ -558,7 +558,7 @@ int gps_l1_ca_dll_pll_c_aid_tracking_fpga_sc::general_work( | ||||
|                         { | ||||
|                             d_cn0_estimation_counter = 0; | ||||
|                             // Code lock indicator | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS); | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, GPS_L1_CA_CODE_PERIOD); | ||||
|                             // Carrier lock indicator | ||||
|                             d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, FLAGS_cn0_samples); | ||||
|                             // Loss of lock detection | ||||
|   | ||||
| @@ -743,7 +743,7 @@ int gps_l1_ca_dll_pll_c_aid_tracking_sc::general_work(int noutput_items __attrib | ||||
|                         { | ||||
|                             d_cn0_estimation_counter = 0; | ||||
|                             // Code lock indicator | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS); | ||||
|                             d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, GPS_L1_CA_CODE_PERIOD); | ||||
|                             // Carrier lock indicator | ||||
|                             d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, FLAGS_cn0_samples); | ||||
|                             // Loss of lock detection | ||||
|   | ||||
| @@ -413,7 +413,7 @@ int Gps_L1_Ca_Dll_Pll_Tracking_GPU_cc::general_work(int noutput_items __attribut | ||||
|                 { | ||||
|                     d_cn0_estimation_counter = 0; | ||||
|                     // Code lock indicator | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS); | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, GPS_L1_CA_CODE_PERIOD); | ||||
|                     // Carrier lock indicator | ||||
|                     d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, FLAGS_cn0_samples); | ||||
|                     // Loss of lock detection | ||||
|   | ||||
| @@ -418,7 +418,7 @@ int Gps_L1_Ca_Tcp_Connector_Tracking_cc::general_work(int noutput_items __attrib | ||||
|             else | ||||
|                 { | ||||
|                     d_cn0_estimation_counter = 0; | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, d_fs_in, GPS_L1_CA_CODE_LENGTH_CHIPS); | ||||
|                     d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, FLAGS_cn0_samples, GPS_L1_CA_CODE_PERIOD); | ||||
|                     d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, FLAGS_cn0_samples); | ||||
|  | ||||
|                     // ###### TRACKING UNLOCK NOTIFICATION ##### | ||||
|   | ||||
| @@ -58,14 +58,14 @@ | ||||
|  * \f$\hat{P}_{tot}=\frac{1}{N}\sum^{N-1}_{i=0}|Pc(i)|^2\f$ is the estimator of the total power, \f$|\cdot|\f$ is the absolute value, | ||||
|  * \f$Re(\cdot)\f$ stands for the real part of the value, and \f$Pc(i)\f$ is the prompt correlator output for the sample index i. | ||||
|  * | ||||
|  * The SNR value is converted to CN0 [dB-Hz], taking to account the receiver bandwidth and the PRN code gain, using the following formula: | ||||
|  * The SNR value is converted to CN0 [dB-Hz], taking to account the coherent integration time, using the following formula: | ||||
|  * \f{equation} | ||||
|  *     CN0_{dB}=10*log(\hat{\rho})+10*log(\frac{f_s}{2})-10*log(L_{PRN}), | ||||
|  *     CN0_{dB}=10*log(\hat{\rho})-10*log(2 * T_{int}), | ||||
|  * \f} | ||||
|  * where \f$f_s\f$ is the sampling frequency and \f$L_{PRN}\f$ is the PRN sequence length. | ||||
|  * where \f$T_{int}\f$ is the coherent integration time, in seconds. | ||||
|  * | ||||
|  */ | ||||
| float cn0_svn_estimator(gr_complex* Prompt_buffer, int length, long fs_in, double code_length) | ||||
| float cn0_svn_estimator(const gr_complex* Prompt_buffer, int length, double coh_integration_time_s) | ||||
| { | ||||
|     double SNR = 0.0; | ||||
|     double SNR_dB_Hz = 0.0; | ||||
| @@ -80,7 +80,7 @@ float cn0_svn_estimator(gr_complex* Prompt_buffer, int length, long fs_in, doubl | ||||
|     Psig = Psig * Psig; | ||||
|     Ptot /= static_cast<double>(length); | ||||
|     SNR = Psig / (Ptot - Psig); | ||||
|     SNR_dB_Hz = 10.0 * log10(SNR) + 10.0 * log10(static_cast<double>(fs_in) / 2.0) - 10.0 * log10(code_length); | ||||
|     SNR_dB_Hz = 10.0 * log10(SNR) - 10.0 * log10(2.0 * coh_integration_time_s); | ||||
|     return static_cast<float>(SNR_dB_Hz); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -62,17 +62,17 @@ | ||||
|  * \f$\hat{P}_{tot}=\frac{1}{N}\sum^{N-1}_{i=0}|Pc(i)|^2\f$ is the estimator of the total power, \f$|\cdot|\f$ is the absolute value, | ||||
|  * \f$Re(\cdot)\f$ stands for the real part of the value, and \f$Pc(i)\f$ is the prompt correlator output for the sample index i. | ||||
|  * | ||||
|  * The SNR value is converted to CN0 [dB-Hz], taking to account the receiver bandwidth and the PRN code gain, using the following formula: | ||||
|  * The SNR value is converted to CN0 [dB-Hz], taking to account the coherent integration time, using the following formula: | ||||
|  * \f{equation} | ||||
|  *  CN0_{dB}=10*log(\hat{\rho})+10*log(\frac{f_s}{2})-10*log(L_{PRN}), | ||||
|  *     CN0_{dB}=10*log(\hat{\rho})-10*log(2 * T_{int}), | ||||
|  * \f} | ||||
|  * where \f$f_s\f$ is the sampling frequency and \f$L_{PRN}\f$ is the PRN sequence length. | ||||
|  * where \f$T_{int}\f$ is the coherent integration time, in seconds. | ||||
|  * Ref: Marco Pini, Emanuela Falletti and Maurizio Fantino, "Performance | ||||
|  * Evaluation of C/N0 Estimators using a Real Time GNSS Software Receiver," | ||||
|  * IEEE 10th International Symposium on Spread Spectrum Techniques and | ||||
|  * Applications, pp.28-30, August 2008. | ||||
|  */ | ||||
| float cn0_svn_estimator(gr_complex* Prompt_buffer, int length, long fs_in, double code_length); | ||||
| float cn0_svn_estimator(const gr_complex* Prompt_buffer, int length, double coh_integration_time_s); | ||||
|  | ||||
|  | ||||
| /*! \brief A carrier lock detector | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Carles Fernandez
					Carles Fernandez