2015-04-23 14:20:06 +00:00
|
|
|
/*!
|
2020-11-07 21:43:19 +00:00
|
|
|
* \file gps_l2c_signal_replica.cc
|
|
|
|
* \brief This file implements signal generators for GPS L2C signals
|
2015-04-23 14:20:06 +00:00
|
|
|
* \author Javier Arribas, 2015. jarribas(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2015-04-23 14:20:06 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2015-04-23 14:20:06 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2015-04-23 14:20:06 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2015-04-23 14:20:06 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-07 21:43:19 +00:00
|
|
|
#include "gps_l2c_signal_replica.h"
|
2018-02-26 02:15:53 +00:00
|
|
|
#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
|
|
|
{
|
2023-11-15 13:21:07 +00:00
|
|
|
return ((x >> 1U) xor ((x & 1U) * 0445112474U));
|
2015-04-23 14:20:06 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 14:22:52 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void gps_l2c_m_code(own::span<int32_t> dest, uint32_t prn)
|
2015-04-23 14:20:06 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
uint32_t 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
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[n] = static_cast<int32_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
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void gps_l2c_m_code_gen_complex(own::span<std::complex<float>> dest, uint32_t prn)
|
2015-04-30 15:48:21 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
std::array<int32_t, GPS_L2_M_CODE_LENGTH_CHIPS> code_aux{};
|
|
|
|
if (prn > 0 and prn < 51)
|
2015-05-14 11:06:19 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
gps_l2c_m_code(code_aux, 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
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i] = std::complex<float>(0.0, 1.0F - 2.0F * code_aux[i]);
|
2015-04-30 15:48:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void gps_l2c_m_code_gen_float(own::span<float> dest, uint32_t prn)
|
2018-03-13 11:38:33 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
std::array<int32_t, GPS_L2_M_CODE_LENGTH_CHIPS> code_aux{};
|
|
|
|
if (prn > 0 and prn < 51)
|
2018-03-13 11:38:33 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
gps_l2c_m_code(code_aux, 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
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i] = 1.0 - 2.0 * static_cast<float>(code_aux[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
|
|
|
*/
|
2020-12-29 13:47:28 +00:00
|
|
|
void gps_l2c_m_code_gen_complex_sampled(own::span<std::complex<float>> dest, uint32_t prn, int32_t sampling_freq)
|
2015-04-23 14:20:06 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
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
|
2020-07-03 09:36:38 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
const auto samplesPerCode = static_cast<int32_t>(static_cast<double>(sampling_freq) / (static_cast<double>(GPS_L2_M_CODE_RATE_CPS) / static_cast<double>(codeLength)));
|
|
|
|
const float ts = 1.0F / static_cast<float>(sampling_freq); // Sampling period in sec
|
|
|
|
int32_t codeValueIndex;
|
2020-07-03 09:36:38 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
std::array<int32_t, GPS_L2_M_CODE_LENGTH_CHIPS> code_aux{};
|
|
|
|
if (prn > 0 and prn < 51)
|
2015-05-14 11:06:19 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
gps_l2c_m_code(code_aux, prn);
|
2015-05-14 11:06:19 +00:00
|
|
|
}
|
2015-04-23 14:20:06 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
for (int32_t i = 0; i < samplesPerCode; i++)
|
2015-04-23 14:20:06 +00:00
|
|
|
{
|
2019-07-28 10:01:11 +00:00
|
|
|
// === Digitizing ==================================================
|
2015-04-23 14:20:06 +00:00
|
|
|
|
2019-07-28 10:01:11 +00:00
|
|
|
// --- Make index array to read L2C code values --------------------
|
2020-12-29 13:47:28 +00:00
|
|
|
codeValueIndex = std::ceil((ts * (static_cast<float>(i) + 1.0F)) / tc) - 1;
|
2015-04-23 14:20:06 +00:00
|
|
|
|
2019-07-28 10:01:11 +00:00
|
|
|
// --- Make the digitized version of the L2C code ------------------
|
2020-12-29 13:47:28 +00:00
|
|
|
if (i == samplesPerCode - 1)
|
2015-04-23 14:20:06 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
// Correct the last index (due to number rounding issues)
|
|
|
|
dest[i] = std::complex<float>(0.0, 1.0F - 2.0F * code_aux[codeLength - 1]);
|
2015-04-23 14:20:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i] = std::complex<float>(0.0, 1.0F - 2.0F * code_aux[codeValueIndex]); // repeat the chip -> upsample
|
2015-04-23 14:20:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|