2012-07-12 21:17:37 +00:00
|
|
|
/*!
|
|
|
|
* \file gps_sdr_signal_processing.cc
|
|
|
|
* \brief This class implements various functions for GPS L1 CA signals
|
|
|
|
* \author Javier Arribas, 2011. jarribas(at)cttc.es
|
|
|
|
*
|
|
|
|
* Detailed description of the file here if needed.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2018-05-13 20:49:11 +00:00
|
|
|
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
2012-07-12 21:17:37 +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.
|
2012-07-12 21:17:37 +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/>.
|
2012-07-12 21:17:37 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
#include "gps_sdr_signal_processing.h"
|
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
auto auxCeil = [](float x) { return static_cast<int32_t>(static_cast<int64_t>((x) + 1)); };
|
2012-07-12 21:17:37 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
void gps_l1_ca_code_gen_int(int32_t* _dest, int32_t _prn, uint32_t _chip_shift)
|
2012-01-16 18:27:31 +00:00
|
|
|
{
|
2018-08-13 08:18:05 +00:00
|
|
|
const uint32_t _code_length = 1023;
|
2015-05-05 11:00:24 +00:00
|
|
|
bool G1[_code_length];
|
|
|
|
bool G2[_code_length];
|
2015-05-03 08:50:57 +00:00
|
|
|
bool G1_register[10], G2_register[10];
|
|
|
|
bool feedback1, feedback2;
|
|
|
|
bool aux;
|
2018-08-13 08:18:05 +00:00
|
|
|
uint32_t lcv, lcv2;
|
|
|
|
uint32_t delay;
|
|
|
|
int32_t prn_idx;
|
2012-10-28 12:38:11 +00:00
|
|
|
|
|
|
|
/* G2 Delays as defined in GPS-ISD-200D */
|
2018-08-13 08:18:05 +00:00
|
|
|
const int32_t delays[51] = {5 /*PRN1*/, 6, 7, 8, 17, 18, 139, 140, 141, 251, 252, 254, 255, 256, 257, 258, 469, 470, 471, 472,
|
2018-03-03 01:03:39 +00:00
|
|
|
473, 474, 509, 512, 513, 514, 515, 516, 859, 860, 861, 862 /*PRN32*/,
|
|
|
|
145 /*PRN120*/, 175, 52, 21, 237, 235, 886, 657, 634, 762,
|
|
|
|
355, 1012, 176, 603, 130, 359, 595, 68, 386 /*PRN138*/};
|
2013-07-20 07:58:59 +00:00
|
|
|
|
|
|
|
// compute delay array index for given PRN number
|
2018-03-03 01:03:39 +00:00
|
|
|
if (120 <= _prn && _prn <= 138)
|
2016-05-02 21:46:30 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
prn_idx = _prn - 88; // SBAS PRNs are at array indices 31 to 50 (offset: -120+33-1 =-88)
|
2016-05-02 21:46:30 +00:00
|
|
|
}
|
2013-07-20 07:58:59 +00:00
|
|
|
else
|
2016-05-02 21:46:30 +00:00
|
|
|
{
|
|
|
|
prn_idx = _prn - 1;
|
|
|
|
}
|
2012-10-28 12:38:11 +00:00
|
|
|
|
|
|
|
/* A simple error check */
|
2018-03-03 01:03:39 +00:00
|
|
|
if ((prn_idx < 0) || (prn_idx > 51))
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (lcv = 0; lcv < 10; lcv++)
|
2012-10-28 12:38:11 +00:00
|
|
|
{
|
2018-12-11 11:08:54 +00:00
|
|
|
G1_register[lcv] = true;
|
|
|
|
G2_register[lcv] = true;
|
2012-10-28 12:38:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate G1 & G2 Register */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (lcv = 0; lcv < _code_length; lcv++)
|
2012-10-28 12:38:11 +00:00
|
|
|
{
|
|
|
|
G1[lcv] = G1_register[0];
|
|
|
|
G2[lcv] = G2_register[0];
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
feedback1 = G1_register[7] ^ G1_register[0];
|
2012-10-28 12:38:11 +00:00
|
|
|
feedback2 = (G2_register[8] + G2_register[7] + G2_register[4] + G2_register[2] + G2_register[1] + G2_register[0]) & 0x1;
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (lcv2 = 0; lcv2 < 9; lcv2++)
|
2012-10-28 12:38:11 +00:00
|
|
|
{
|
|
|
|
G1_register[lcv2] = G1_register[lcv2 + 1];
|
|
|
|
G2_register[lcv2] = G2_register[lcv2 + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
G1_register[9] = feedback1;
|
|
|
|
G2_register[9] = feedback2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the delay */
|
2015-05-05 11:00:24 +00:00
|
|
|
delay = _code_length - delays[prn_idx];
|
2012-10-28 12:38:11 +00:00
|
|
|
delay += _chip_shift;
|
2015-05-05 11:00:24 +00:00
|
|
|
delay %= _code_length;
|
2015-05-03 08:50:57 +00:00
|
|
|
|
2012-10-28 12:38:11 +00:00
|
|
|
/* Generate PRN from G1 and G2 Registers */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (lcv = 0; lcv < _code_length; lcv++)
|
2012-10-28 12:38:11 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
aux = G1[(lcv + _chip_shift) % _code_length] ^ G2[delay];
|
|
|
|
if (aux == true)
|
2015-05-03 08:50:57 +00:00
|
|
|
{
|
2017-09-11 14:21:05 +00:00
|
|
|
_dest[lcv] = 1;
|
2015-05-03 08:50:57 +00:00
|
|
|
}
|
|
|
|
else
|
2012-10-28 12:38:11 +00:00
|
|
|
{
|
2017-09-11 14:21:05 +00:00
|
|
|
_dest[lcv] = -1;
|
2012-10-28 12:38:11 +00:00
|
|
|
}
|
|
|
|
delay++;
|
2015-05-05 11:00:24 +00:00
|
|
|
delay %= _code_length;
|
2012-10-28 12:38:11 +00:00
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 23:14:15 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
void gps_l1_ca_code_gen_float(float* _dest, int32_t _prn, uint32_t _chip_shift)
|
2017-09-11 14:21:05 +00:00
|
|
|
{
|
2018-08-16 12:16:43 +00:00
|
|
|
const uint32_t _code_length = 1023;
|
2018-08-13 08:18:05 +00:00
|
|
|
int32_t ca_code_int[_code_length];
|
2017-09-11 14:21:05 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
gps_l1_ca_code_gen_int(ca_code_int, _prn, _chip_shift);
|
2017-09-11 14:21:05 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
for (uint32_t ii = 0; ii < _code_length; ++ii)
|
2017-09-15 23:14:15 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
_dest[ii] = static_cast<float>(ca_code_int[ii]);
|
2017-09-15 23:14:15 +00:00
|
|
|
}
|
2017-09-11 14:21:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 23:14:15 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
void gps_l1_ca_code_gen_complex(std::complex<float>* _dest, int32_t _prn, uint32_t _chip_shift)
|
2017-09-11 14:21:05 +00:00
|
|
|
{
|
2018-08-16 12:16:43 +00:00
|
|
|
const uint32_t _code_length = 1023;
|
2018-11-23 15:28:28 +00:00
|
|
|
int32_t ca_code_int[_code_length] = {0};
|
2017-09-11 14:21:05 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
gps_l1_ca_code_gen_int(ca_code_int, _prn, _chip_shift);
|
2017-09-11 14:21:05 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
for (uint32_t ii = 0; ii < _code_length; ++ii)
|
2017-09-15 23:14:15 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
_dest[ii] = std::complex<float>(static_cast<float>(ca_code_int[ii]), 0.0f);
|
2017-09-15 23:14:15 +00:00
|
|
|
}
|
2017-09-11 14:21:05 +00:00
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2015-05-03 08:50:57 +00:00
|
|
|
|
2012-10-28 12:38:11 +00:00
|
|
|
/*
|
2013-01-28 23:50:09 +00:00
|
|
|
* Generates complex GPS L1 C/A code for the desired SV ID and sampled to specific sampling frequency
|
2018-07-19 14:26:51 +00:00
|
|
|
* NOTICE: the number of samples is rounded towards zero (integer truncation)
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
2018-08-13 08:18:05 +00:00
|
|
|
void gps_l1_ca_code_gen_complex_sampled(std::complex<float>* _dest, uint32_t _prn, int32_t _fs, uint32_t _chip_shift)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2012-10-28 12:38:11 +00:00
|
|
|
// This function is based on the GNU software GPS for MATLAB in the Kay Borre book
|
2012-01-23 00:52:05 +00:00
|
|
|
std::complex<float> _code[1023];
|
2018-08-13 08:18:05 +00:00
|
|
|
int32_t _samplesPerCode, _codeValueIndex;
|
2012-01-23 00:52:05 +00:00
|
|
|
float _ts;
|
|
|
|
float _tc;
|
2015-05-05 11:00:24 +00:00
|
|
|
float aux;
|
2018-08-13 08:18:05 +00:00
|
|
|
const int32_t _codeFreqBasis = 1023000; //Hz
|
|
|
|
const int32_t _codeLength = 1023;
|
2012-01-23 00:52:05 +00:00
|
|
|
|
|
|
|
//--- Find number of samples per spreading code ----------------------------
|
2018-08-13 08:18:05 +00:00
|
|
|
_samplesPerCode = static_cast<int32_t>(static_cast<double>(_fs) / static_cast<double>(_codeFreqBasis / _codeLength));
|
2012-01-23 00:52:05 +00:00
|
|
|
|
|
|
|
//--- Find time constants --------------------------------------------------
|
2018-03-03 01:03:39 +00:00
|
|
|
_ts = 1.0 / static_cast<float>(_fs); // Sampling period in sec
|
|
|
|
_tc = 1.0 / static_cast<float>(_codeFreqBasis); // C/A chip period in sec
|
|
|
|
gps_l1_ca_code_gen_complex(_code, _prn, _chip_shift); //generate C/A code 1 sample per chip
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
for (int32_t i = 0; i < _samplesPerCode; i++)
|
2012-01-23 00:52:05 +00:00
|
|
|
{
|
|
|
|
//=== Digitizing =======================================================
|
|
|
|
|
|
|
|
//--- Make index array to read C/A code values -------------------------
|
|
|
|
// The length of the index array depends on the sampling frequency -
|
|
|
|
// number of samples per millisecond (because one C/A code period is one
|
|
|
|
// millisecond).
|
|
|
|
|
2015-05-05 11:00:24 +00:00
|
|
|
// _codeValueIndex = ceil((_ts * ((float)i + 1)) / _tc) - 1;
|
2018-03-03 01:03:39 +00:00
|
|
|
aux = (_ts * (i + 1)) / _tc;
|
|
|
|
_codeValueIndex = auxCeil(aux) - 1;
|
2012-01-23 00:52:05 +00:00
|
|
|
|
|
|
|
//--- Make the digitized version of the C/A code -----------------------
|
|
|
|
// The "upsampled" code is made by selecting values form the CA code
|
|
|
|
// chip array (caCode) for the time instances of each sample.
|
|
|
|
if (i == _samplesPerCode - 1)
|
|
|
|
{
|
|
|
|
//--- Correct the last index (due to number rounding issues) -----------
|
|
|
|
_dest[i] = _code[_codeLength - 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
_dest[i] = _code[_codeValueIndex]; //repeat the chip -> upsample
|
2012-01-23 00:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|