2011-11-22 17:21:54 +00:00
|
|
|
/*!
|
2012-10-21 09:54:37 +00:00
|
|
|
* \file lock_detectors.cc
|
|
|
|
* \brief Implementation of a library with a set of code and carrier phase lock detectors.
|
2012-09-12 15:03:38 +00:00
|
|
|
*
|
|
|
|
* SNV_CN0 is a Carrier-to-Noise (CN0) estimator
|
2011-12-28 21:36:45 +00:00
|
|
|
* based on the Signal-to-Noise Variance (SNV) estimator [1].
|
2011-11-22 17:21:54 +00:00
|
|
|
* Carrier lock detector using normalised estimate of the cosine
|
|
|
|
* of twice the carrier phase error [2].
|
2012-09-12 15:03:38 +00:00
|
|
|
*
|
2011-11-22 17:21:54 +00:00
|
|
|
* [1] 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.
|
2012-09-12 15:03:38 +00:00
|
|
|
*
|
2011-11-22 17:21:54 +00:00
|
|
|
* [2] Van Dierendonck, A.J. (1996), Global Positioning System: Theory and
|
|
|
|
* Applications,
|
|
|
|
* Volume I, Chapter 8: GPS Receivers, AJ Systems, Los Altos, CA 94024.
|
|
|
|
* Inc.: 329-407.
|
2012-09-12 15:03:38 +00:00
|
|
|
* \authors <ul>
|
|
|
|
* <li> Javier Arribas, 2011. jarribas(at)cttc.es
|
|
|
|
* <li> Luis Esteve, 2012. luis(at)epsilon-formacion.com
|
|
|
|
* </ul>
|
2011-11-22 17:21:54 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2018-05-13 20:49:11 +00:00
|
|
|
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
2011-11-22 17:21:54 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
|
|
|
* GNSS-SDR is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2015-01-08 18:49:59 +00:00
|
|
|
* (at your option) any later version.
|
2011-11-22 17:21:54 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-05-13 20:49:11 +00:00
|
|
|
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
|
2011-11-22 17:21:54 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
2012-10-21 09:54:37 +00:00
|
|
|
|
|
|
|
#include "lock_detectors.h"
|
2016-01-04 17:06:54 +00:00
|
|
|
#include <cmath>
|
2011-11-22 17:21:54 +00:00
|
|
|
|
2011-12-28 21:36:45 +00:00
|
|
|
/*
|
2011-11-22 17:21:54 +00:00
|
|
|
* Signal-to-Noise (SNR) (\f$\rho\f$) estimator using the Signal-to-Noise Variance (SNV) estimator:
|
|
|
|
* \f{equation}
|
2016-05-02 21:46:30 +00:00
|
|
|
* \hat{\rho}=\frac{\hat{P}_s}{\hat{P}_n}=\frac{\hat{P}_s}{\hat{P}_{tot}-\hat{P}_s},
|
2011-11-22 17:21:54 +00:00
|
|
|
* \f}
|
|
|
|
* where \f$\hat{P}_s=\left(\frac{1}{N}\sum^{N-1}_{i=0}|Re(Pc(i))|\right)^2\f$ is the estimation of the signal power,
|
|
|
|
* \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.
|
|
|
|
*
|
2018-04-09 19:09:25 +00:00
|
|
|
* The SNR value is converted to CN0 [dB-Hz], taking to account the coherent integration time, using the following formula:
|
2011-11-22 17:21:54 +00:00
|
|
|
* \f{equation}
|
2019-05-22 11:23:21 +00:00
|
|
|
* CN0_{dB}=10*log(\hat{\rho})-10*log(T_{int}),
|
2011-11-22 17:21:54 +00:00
|
|
|
* \f}
|
2018-04-09 19:09:25 +00:00
|
|
|
* where \f$T_{int}\f$ is the coherent integration time, in seconds.
|
2011-12-28 21:36:45 +00:00
|
|
|
*
|
2011-11-22 17:21:54 +00:00
|
|
|
*/
|
2019-04-25 12:58:30 +00:00
|
|
|
float cn0_svn_estimator(const gr_complex* Prompt_buffer, int length, float coh_integration_time_s)
|
2011-11-22 17:21:54 +00:00
|
|
|
{
|
2019-04-25 12:58:30 +00:00
|
|
|
float SNR = 0.0;
|
|
|
|
float SNR_dB_Hz = 0.0;
|
|
|
|
float Psig = 0.0;
|
|
|
|
float Ptot = 0.0;
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < length; i++)
|
2011-12-28 21:36:45 +00:00
|
|
|
{
|
2019-04-25 12:58:30 +00:00
|
|
|
Psig += std::abs(Prompt_buffer[i].real());
|
|
|
|
Ptot += Prompt_buffer[i].imag() * Prompt_buffer[i].imag() + Prompt_buffer[i].real() * Prompt_buffer[i].real();
|
2011-12-28 21:36:45 +00:00
|
|
|
}
|
2019-04-25 12:58:30 +00:00
|
|
|
Psig /= static_cast<float>(length);
|
2015-11-27 13:06:30 +00:00
|
|
|
Psig = Psig * Psig;
|
2019-04-25 12:58:30 +00:00
|
|
|
Ptot /= static_cast<float>(length);
|
2012-10-21 09:54:37 +00:00
|
|
|
SNR = Psig / (Ptot - Psig);
|
2019-05-22 11:23:21 +00:00
|
|
|
SNR_dB_Hz = 10.0 * std::log10(SNR) - 10.0 * std::log10(coh_integration_time_s);
|
2019-04-25 12:58:30 +00:00
|
|
|
return SNR_dB_Hz;
|
2012-08-28 13:38:33 +00:00
|
|
|
}
|
2012-10-20 16:11:31 +00:00
|
|
|
|
|
|
|
|
2011-12-28 21:36:45 +00:00
|
|
|
/*
|
2012-10-21 09:54:37 +00:00
|
|
|
* The estimate of the cosine of twice the carrier phase error is given by
|
2011-11-22 17:21:54 +00:00
|
|
|
* \f{equation}
|
2016-05-02 21:46:30 +00:00
|
|
|
* \cos(2\phi)=\frac{NBD}{NBP},
|
2011-11-22 17:21:54 +00:00
|
|
|
* \f}
|
2012-10-20 16:11:31 +00:00
|
|
|
* where \f$NBD=(\sum^{N-1}_{i=0}Im(Pc(i)))^2-(\sum^{N-1}_{i=0}Re(Pc(i)))^2\f$,
|
|
|
|
* \f$NBP=(\sum^{N-1}_{i=0}Im(Pc(i)))^2+(\sum^{N-1}_{i=0}Re(Pc(i)))^2\f$, and
|
2011-11-22 17:21:54 +00:00
|
|
|
* \f$Pc(i)\f$ is the prompt correlator output for the sample index i.
|
|
|
|
*/
|
|
|
|
float carrier_lock_detector(gr_complex* Prompt_buffer, int length)
|
|
|
|
{
|
2018-03-12 14:16:39 +00:00
|
|
|
float tmp_sum_I = 0.0;
|
|
|
|
float tmp_sum_Q = 0.0;
|
|
|
|
float NBD = 0.0;
|
|
|
|
float NBP = 0.0;
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < length; i++)
|
2011-12-28 21:36:45 +00:00
|
|
|
{
|
2012-10-20 16:11:31 +00:00
|
|
|
tmp_sum_I += Prompt_buffer[i].real();
|
|
|
|
tmp_sum_Q += Prompt_buffer[i].imag();
|
2011-12-28 21:36:45 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
NBP = tmp_sum_I * tmp_sum_I + tmp_sum_Q * tmp_sum_Q;
|
|
|
|
NBD = tmp_sum_I * tmp_sum_I - tmp_sum_Q * tmp_sum_Q;
|
|
|
|
return NBD / NBP;
|
2011-11-22 17:21:54 +00:00
|
|
|
}
|