2015-04-23 14:20:06 +00:00
|
|
|
/*!
|
|
|
|
* \file gps_l2c_signal.cc
|
|
|
|
* \brief This class implements signal generators for the GPS L2C signals
|
|
|
|
* \author Javier Arribas, 2015. 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)
|
2015-04-23 14:20:06 +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
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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/>.
|
2015-04-23 14:20:06 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2018-02-26 02:15:53 +00:00
|
|
|
#include "gps_l2c_signal.h"
|
|
|
|
#include "GPS_L2C.h"
|
2019-07-18 20:03:56 +00:00
|
|
|
#include <array>
|
2015-04-23 14:20:06 +00:00
|
|
|
#include <cmath>
|
2019-06-30 02:47:15 +00:00
|
|
|
#include <memory>
|
2015-04-23 14:20:06 +00:00
|
|
|
|
|
|
|
|
2019-07-14 21:34:07 +00:00
|
|
|
uint32_t gps_l2c_m_shift(uint32_t x)
|
2015-04-23 14:20:06 +00:00
|
|
|
{
|
2019-07-18 17:47:27 +00:00
|
|
|
return static_cast<uint32_t>((x >> 1U) xor ((x & 1U) * 0445112474U));
|
2015-04-23 14:20:06 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 14:22:52 +00:00
|
|
|
|
2019-06-28 23:28:30 +00:00
|
|
|
void gps_l2c_m_code(gsl::span<int32_t> _dest, uint32_t _prn)
|
2015-04-23 14:20:06 +00:00
|
|
|
{
|
2019-07-14 21:34:07 +00:00
|
|
|
uint32_t x;
|
2018-03-03 01:03:39 +00:00
|
|
|
x = GPS_L2C_M_INIT_REG[_prn - 1];
|
2018-08-13 08:18:05 +00:00
|
|
|
for (int32_t n = 0; n < GPS_L2_M_CODE_LENGTH_CHIPS; n++)
|
2016-01-10 21:21:31 +00:00
|
|
|
{
|
2019-07-14 21:34:07 +00:00
|
|
|
_dest[n] = static_cast<int8_t>(x & 1U);
|
2016-01-10 21:21:31 +00:00
|
|
|
x = gps_l2c_m_shift(x);
|
|
|
|
}
|
2015-04-23 14:20:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 15:48:21 +00:00
|
|
|
|
2019-06-28 23:28:30 +00:00
|
|
|
void gps_l2c_m_code_gen_complex(gsl::span<std::complex<float>> _dest, uint32_t _prn)
|
2015-04-30 15:48:21 +00:00
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
std::array<int32_t, GPS_L2_M_CODE_LENGTH_CHIPS> _code{};
|
2015-05-14 11:06:19 +00:00
|
|
|
if (_prn > 0 and _prn < 51)
|
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
gps_l2c_m_code(_code, _prn);
|
2015-05-14 11:06:19 +00:00
|
|
|
}
|
2015-04-30 15:48:21 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
for (int32_t i = 0; i < GPS_L2_M_CODE_LENGTH_CHIPS; i++)
|
2015-04-30 15:48:21 +00:00
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
_dest[i] = std::complex<float>(1.0 - 2.0 * _code[i], 0.0);
|
2015-04-30 15:48:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
|
2019-06-28 23:28:30 +00:00
|
|
|
void gps_l2c_m_code_gen_float(gsl::span<float> _dest, uint32_t _prn)
|
2018-03-13 11:38:33 +00:00
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
std::array<int32_t, GPS_L2_M_CODE_LENGTH_CHIPS> _code{};
|
2018-03-13 11:38:33 +00:00
|
|
|
if (_prn > 0 and _prn < 51)
|
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
gps_l2c_m_code(_code, _prn);
|
2018-03-13 11:38:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
for (int32_t i = 0; i < GPS_L2_M_CODE_LENGTH_CHIPS; i++)
|
2018-03-13 11:38:33 +00:00
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
_dest[i] = 1.0 - 2.0 * static_cast<float>(_code[i]);
|
2018-03-13 11:38:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 15:48:21 +00:00
|
|
|
|
2015-04-23 14:20:06 +00:00
|
|
|
/*
|
2015-04-24 17:11:45 +00:00
|
|
|
* Generates complex GPS L2C M code for the desired SV ID and sampled to specific sampling frequency
|
2015-04-23 14:20:06 +00:00
|
|
|
*/
|
2019-06-28 23:28:30 +00:00
|
|
|
void gps_l2c_m_code_gen_complex_sampled(gsl::span<std::complex<float>> _dest, uint32_t _prn, int32_t _fs)
|
2015-04-23 14:20:06 +00:00
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
std::array<int32_t, GPS_L2_M_CODE_LENGTH_CHIPS> _code{};
|
2015-05-14 11:06:19 +00:00
|
|
|
if (_prn > 0 and _prn < 51)
|
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
gps_l2c_m_code(_code, _prn);
|
2015-05-14 11:06:19 +00:00
|
|
|
}
|
2015-04-23 14:20:06 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
int32_t _samplesPerCode, _codeValueIndex;
|
2015-04-23 14:20:06 +00:00
|
|
|
float _ts;
|
|
|
|
float _tc;
|
2018-08-13 08:18:05 +00:00
|
|
|
const int32_t _codeLength = GPS_L2_M_CODE_LENGTH_CHIPS;
|
2015-04-23 14:20:06 +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>(GPS_L2_M_CODE_RATE_HZ) / static_cast<double>(_codeLength)));
|
2015-04-23 14:20:06 +00:00
|
|
|
|
|
|
|
//--- Find time constants --------------------------------------------------
|
2018-03-03 01:03:39 +00:00
|
|
|
_ts = 1.0 / static_cast<float>(_fs); // Sampling period in sec
|
2015-06-12 17:28:56 +00:00
|
|
|
_tc = 1.0 / static_cast<float>(GPS_L2_M_CODE_RATE_HZ); // C/A chip period in sec
|
2015-04-23 14:20:06 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
for (int32_t i = 0; i < _samplesPerCode; i++)
|
2015-04-23 14:20:06 +00:00
|
|
|
{
|
|
|
|
//=== Digitizing =======================================================
|
|
|
|
|
2016-01-03 14:22:52 +00:00
|
|
|
//--- Make index array to read L2C code values -------------------------
|
2019-02-21 11:09:18 +00:00
|
|
|
_codeValueIndex = std::ceil((_ts * (static_cast<float>(i) + 1)) / _tc) - 1;
|
2015-04-23 14:20:06 +00:00
|
|
|
|
2016-01-03 14:22:52 +00:00
|
|
|
//--- Make the digitized version of the L2C code -----------------------
|
2015-04-23 14:20:06 +00:00
|
|
|
if (i == _samplesPerCode - 1)
|
|
|
|
{
|
|
|
|
//--- Correct the last index (due to number rounding issues) -----------
|
2019-07-18 20:03:56 +00:00
|
|
|
_dest[i] = std::complex<float>(1.0 - 2.0 * _code[_codeLength - 1], 0);
|
2015-04-23 14:20:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
_dest[i] = std::complex<float>(1.0 - 2.0 * _code[_codeValueIndex], 0); //repeat the chip -> upsample
|
2015-04-23 14:20:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|