1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-16 21:20:34 +00:00
gnss-sdr/src/algorithms/libs/gps_l2c_signal.cc

112 lines
3.5 KiB
C++
Raw Normal View History

/*!
* \file gps_l2c_signal.cc
* \brief This class implements signal generators for the GPS L2C signals
* \author Javier Arribas, 2015. jarribas(at)cttc.es
*
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
*
2020-07-28 14:57:15 +00:00
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
*/
#include "gps_l2c_signal.h"
#include "GPS_L2C.h"
2019-07-18 20:03:56 +00:00
#include <array>
#include <cmath>
#include <memory>
uint32_t gps_l2c_m_shift(uint32_t x)
{
2019-07-18 17:47:27 +00:00
return static_cast<uint32_t>((x >> 1U) xor ((x & 1U) * 0445112474U));
}
2016-01-03 14:22:52 +00:00
void gps_l2c_m_code(own::span<int32_t> _dest, uint32_t _prn)
{
uint32_t x = GPS_L2C_M_INIT_REG[_prn - 1];
for (int32_t n = 0; n < GPS_L2_M_CODE_LENGTH_CHIPS; n++)
2016-01-10 21:21:31 +00:00
{
_dest[n] = static_cast<int8_t>(x & 1U);
2016-01-10 21:21:31 +00:00
x = gps_l2c_m_shift(x);
}
}
void gps_l2c_m_code_gen_complex(own::span<std::complex<float>> _dest, uint32_t _prn)
{
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
}
for (int32_t i = 0; i < GPS_L2_M_CODE_LENGTH_CHIPS; i++)
{
_dest[i] = std::complex<float>(0.0, 1.0F - 2.0F * _code[i]);
}
}
void gps_l2c_m_code_gen_float(own::span<float> _dest, uint32_t _prn)
{
2019-07-18 20:03:56 +00:00
std::array<int32_t, GPS_L2_M_CODE_LENGTH_CHIPS> _code{};
if (_prn > 0 and _prn < 51)
{
2019-07-18 20:03:56 +00:00
gps_l2c_m_code(_code, _prn);
}
for (int32_t i = 0; i < GPS_L2_M_CODE_LENGTH_CHIPS; i++)
{
2019-07-18 20:03:56 +00:00
_dest[i] = 1.0 - 2.0 * static_cast<float>(_code[i]);
}
}
/*
* Generates complex GPS L2C M code for the desired SV ID and sampled to specific sampling frequency
*/
void gps_l2c_m_code_gen_complex_sampled(own::span<std::complex<float>> _dest, uint32_t _prn, int32_t _fs)
{
constexpr int32_t _codeLength = GPS_L2_M_CODE_LENGTH_CHIPS;
constexpr float _tc = 1.0F / static_cast<float>(GPS_L2_M_CODE_RATE_CPS); // L2C chip period in sec
const auto _samplesPerCode = static_cast<int32_t>(static_cast<double>(_fs) / (static_cast<double>(GPS_L2_M_CODE_RATE_CPS) / static_cast<double>(_codeLength)));
const float _ts = 1.0F / static_cast<float>(_fs); // Sampling period in sec
int32_t _codeValueIndex;
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
}
for (int32_t i = 0; i < _samplesPerCode; i++)
{
2019-07-28 10:01:11 +00:00
// === Digitizing ==================================================
2019-07-28 10:01:11 +00:00
// --- Make index array to read L2C code values --------------------
_codeValueIndex = std::ceil((_ts * (static_cast<float>(i) + 1.0F)) / _tc) - 1;
2019-07-28 10:01:11 +00:00
// --- Make the digitized version of the L2C code ------------------
if (i == _samplesPerCode - 1)
{
2019-07-28 10:01:11 +00:00
// --- Correct the last index (due to number rounding issues) -----------
_dest[i] = std::complex<float>(0.0, 1.0F - 2.0F * _code[_codeLength - 1]);
}
else
{
_dest[i] = std::complex<float>(0.0, 1.0F - 2.0F * _code[_codeValueIndex]); // repeat the chip -> upsample
}
}
}