GNSS-SDR  0.0.13
An Open Source GNSS Software Defined Receiver
tracking_discriminators.h
Go to the documentation of this file.
1 /*!
2  * \file tracking_discriminators.h
3  * \brief Interface of a library with a set of code tracking and carrier
4  * tracking discriminators.
5  * \authors <ul>
6  * <li> Javier Arribas, 2011. jarribas(at)cttc.es
7  * <li> Luis Esteve, 2012. luis(at)epsilon-formacion.com
8  * </ul>
9  *
10  * Library with a set of code tracking and carrier tracking discriminators
11  * that is used by the tracking algorithms.
12  *
13  * -----------------------------------------------------------------------------
14  *
15  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
16  *
17  * GNSS-SDR is a software defined Global Navigation
18  * Satellite Systems receiver
19  *
20  * This file is part of GNSS-SDR.
21  *
22  * SPDX-License-Identifier: GPL-3.0-or-later
23  *
24  * -----------------------------------------------------------------------------
25  */
26 
27 #ifndef GNSS_SDR_TRACKING_DISCRIMINATORS_H
28 #define GNSS_SDR_TRACKING_DISCRIMINATORS_H
29 
30 #include <gnuradio/gr_complex.h>
31 #include <cmath>
32 
33 /*! brief FLL four quadrant arctan discriminator
34  *
35  * FLL four quadrant arctan discriminator:
36  * \f{equation}
37  * \frac{\phi_2-\phi_1}{t_2-t1}=\frac{ATAN2(cross,dot)}{t_1-t_2},
38  * \f}
39  * where \f$cross=I_{PS1}Q_{PS2}-I_{PS2}Q_{PS1}\f$ and \f$dot=I_{PS1}I_{PS2}+Q_{PS1}Q_{PS2}\f$,
40  * \f$I_{PS1},Q_{PS1}\f$ are the inphase and quadrature prompt correlator outputs respectively at sample time \f$t_1\f$, and
41  * \f$I_{PS2},Q_{PS2}\f$ are the inphase and quadrature prompt correlator outputs respectively at sample time \f$t_2\f$. The output is in [radians/second].
42  */
43 double fll_four_quadrant_atan(gr_complex prompt_s1, gr_complex prompt_s2, double t1, double t2);
44 
45 
46 /*
47  * FLL differential arctan discriminator:
48  * \f{equation}
49  * e_{atan}(k)=\frac{1}{t_1-t_2}\text{phase_unwrap}(\tan^-1(\frac{Q(k)}{I(k)})-\tan^-1(\frac{Q(k-1)}{I(k-1)}))
50  * \f}
51  * The output is in [radians/second].
52  */
53 double fll_diff_atan(gr_complex prompt_s1, gr_complex prompt_s2, double t1, double t2);
54 
55 
56 /*! \brief Phase unwrapping function, input is [rad]
57  */
58 double phase_unwrap(double phase_rad);
59 
60 
61 /*! \brief PLL four quadrant arctan discriminator
62  *
63  * PLL four quadrant arctan discriminator:
64  * \f{equation}
65  * \phi=ATAN2(Q_{PS},I_{PS}),
66  * \f}
67  * where \f$I_{PS1},Q_{PS1}\f$ are the inphase and quadrature prompt correlator outputs respectively. The output is in [radians].
68  */
69 double pll_four_quadrant_atan(gr_complex prompt_s1);
70 
71 
72 /*! \brief PLL Costas loop two quadrant arctan discriminator
73  *
74  * PLL Costas loop two quadrant arctan discriminator:
75  * \f{equation}
76  * \phi=ATAN\left(\frac{Q_{PS}}{I_{PS}}\right),
77  * \f}
78  * where \f$I_{PS1},Q_{PS1}\f$ are the inphase and quadrature prompt correlator outputs respectively. The output is in [radians].
79  */
80 double pll_cloop_two_quadrant_atan(gr_complex prompt_s1);
81 
82 
83 /*! \brief DLL Noncoherent Early minus Late envelope normalized discriminator
84  *
85  * DLL Noncoherent Early minus Late envelope normalized discriminator:
86  * \f{equation}
87  * error = \frac{y_{intercept} - \text{slope} * \epsilon}{\text{slope}} \frac{E-L}{E+L},
88  * \f}
89  * where \f$E=\sqrt{I_{ES}^2+Q_{ES}^2}\f$ is the Early correlator output absolute value and
90  * \f$L=\sqrt{I_{LS}^2+Q_{LS}^2}\f$ is the Late correlator output absolute value. The output is in [chips].
91  */
92 double dll_nc_e_minus_l_normalized(gr_complex early_s1, gr_complex late_s1, float spc = 0.5, float slope = 1.0, float y_intercept = 1.0);
93 
94 
95 /*! \brief DLL Noncoherent Very Early Minus Late Power (VEMLP) normalized discriminator
96  *
97  * DLL Noncoherent Very Early Minus Late Power (VEMLP) normalized discriminator, using the outputs
98  * of four correlators, Very Early (VE), Early (E), Late (L) and Very Late (VL):
99  * \f{equation}
100  * error=\frac{E-L}{E+L},
101  * \f}
102  * where \f$E=\sqrt{I_{VE}^2+Q_{VE}^2+I_{E}^2+Q_{E}^2}\f$ and
103  * \f$L=\sqrt{I_{VL}^2+Q_{VL}^2+I_{L}^2+Q_{L}^2}\f$ . The output is in [chips].
104  */
105 double dll_nc_vemlp_normalized(gr_complex very_early_s1, gr_complex early_s1, gr_complex late_s1, gr_complex very_late_s1);
106 
107 
108 template <typename Fun>
109 double CalculateSlope(Fun &&f, double x)
110 {
111  static constexpr double dx = 1e-6;
112 
113  return (f(x + dx / 2.0) - f(x - dx / 2.0)) / dx;
114 }
115 
116 template <typename Fun>
117 double CalculateSlopeAbs(Fun &&f, double x)
118 {
119  static constexpr double dx = 1e-6;
120 
121  return (std::abs(f(x + dx / 2.0)) - std::abs(f(x - dx / 2.0))) / dx;
122 }
123 
124 template <typename Fun>
125 double GetYIntercept(Fun &&f, double x)
126 {
127  double slope = CalculateSlope(f, x);
128  double y1 = f(x);
129 
130  return y1 - slope * x;
131 }
132 
133 template <typename Fun>
134 double GetYInterceptAbs(Fun &&f, double x)
135 {
136  double slope = CalculateSlopeAbs(f, x);
137  double y1 = std::abs(f(x));
138  return y1 - slope * x;
139 }
140 
141 // SinBocCorrelationFunction and CosBocCorrelationFunction from
142 // Sousa, F. and Nunes, F., "New Expressions for the Autocorrelation
143 // Function of BOC GNSS Signals", NAVIGATION - Journal of the Institute
144 // of Navigation, March 2013.
145 //
146 template <int M = 1, int N = M>
147 double SinBocCorrelationFunction(double offset_in_chips)
148 {
149  static constexpr int TWO_P = 2 * M / N;
150 
151  double abs_tau = std::abs(offset_in_chips);
152 
153  if (abs_tau > 1.0)
154  {
155  return 0.0;
156  }
157 
158  int k = static_cast<int>(std::ceil(TWO_P * abs_tau));
159 
160  double sgn = ((k & 0x01) == 0 ? 1.0 : -1.0); // (-1)^k
161 
162  return sgn * (2.0 * (k * k - k * TWO_P - k) / TWO_P + 1.0 +
163  (2 * TWO_P - 2 * k + 1) * abs_tau);
164 }
165 
166 
167 template <int M = 1, int N = M>
168 double CosBocCorrelationFunction(double offset_in_chips)
169 {
170  static constexpr int TWO_P = 2 * M / N;
171 
172  double abs_tau = std::abs(offset_in_chips);
173 
174  if (abs_tau > 1.0)
175  {
176  return 0.0;
177  }
178 
179  int k = static_cast<int>(std::floor(2.0 * TWO_P * abs_tau));
180 
181  if ((k & 0x01) == 0) // k is even
182  {
183  double sgn = ((k >> 1) & 0x01 ? -1.0 : 1.0); // (-1)^(k/2)
184 
185  return sgn * ((2 * k * TWO_P + 2 * TWO_P - k * k) / (2.0 * TWO_P) + (-2 * TWO_P + k - 1) * abs_tau);
186  }
187  else
188  {
189  double sgn = (((k + 1) >> 1) & 0x01 ? -1.0 : 1.0); // (-1)^((k+1)/2)
190 
191  return sgn * ((k * k + 2 * k - 2 * k * TWO_P + 1) / (2.0 * TWO_P) + (2 * TWO_P - k - 2) * abs_tau);
192  }
193 }
194 
195 #endif
double pll_four_quadrant_atan(gr_complex prompt_s1)
PLL four quadrant arctan discriminator.
double phase_unwrap(double phase_rad)
Phase unwrapping function, input is [rad].
double pll_cloop_two_quadrant_atan(gr_complex prompt_s1)
PLL Costas loop two quadrant arctan discriminator.
double dll_nc_vemlp_normalized(gr_complex very_early_s1, gr_complex early_s1, gr_complex late_s1, gr_complex very_late_s1)
DLL Noncoherent Very Early Minus Late Power (VEMLP) normalized discriminator.
double fll_four_quadrant_atan(gr_complex prompt_s1, gr_complex prompt_s2, double t1, double t2)
double dll_nc_e_minus_l_normalized(gr_complex early_s1, gr_complex late_s1, float spc=0.5, float slope=1.0, float y_intercept=1.0)
DLL Noncoherent Early minus Late envelope normalized discriminator.