1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-17 05:30:34 +00:00
gnss-sdr/src/algorithms/libs/glonass_l2_signal_replica.cc

132 lines
4.3 KiB
C++
Raw Normal View History

/*!
* \file glonass_l2_signal_replica.cc
* \brief This file implements various functions for GLONASS L2 CA signal
* replica generation
* \author Damian Miralles, 2018, dmiralles2009(at)gmail.com
*
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
*
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
*/
#include "glonass_l2_signal_replica.h"
#include <array>
#include <bitset>
const auto AUX_CEIL = [](float x) { return static_cast<int32_t>(static_cast<int64_t>((x) + 1)); };
2020-12-29 13:47:28 +00:00
void glonass_l2_ca_code_gen_complex(own::span<std::complex<float>> dest, uint32_t chip_shift)
{
2020-12-29 13:47:28 +00:00
const uint32_t code_length = 511;
std::bitset<code_length> G1{};
auto G1_register = std::bitset<9>{}.set(); // All true
bool feedback1;
bool aux;
uint32_t delay;
uint32_t lcv;
uint32_t lcv2;
/* Generate G1 Register */
2020-12-29 13:47:28 +00:00
for (lcv = 0; lcv < code_length; lcv++)
{
G1[lcv] = G1_register[2];
feedback1 = G1_register[4] xor G1_register[0];
for (lcv2 = 0; lcv2 < 8; lcv2++)
{
G1_register[lcv2] = G1_register[lcv2 + 1];
}
G1_register[8] = feedback1;
}
/* Generate PRN from G1 Register */
2020-12-29 13:47:28 +00:00
for (lcv = 0; lcv < code_length; lcv++)
{
aux = G1[lcv];
if (aux == true)
{
2020-12-29 13:47:28 +00:00
dest[lcv] = std::complex<float>(1, 0);
}
else
{
2020-12-29 13:47:28 +00:00
dest[lcv] = std::complex<float>(-1, 0);
}
}
/* Set the delay */
2020-12-29 13:47:28 +00:00
delay = code_length;
delay += chip_shift;
delay %= code_length;
/* Generate PRN from G1 and G2 Registers */
2020-12-29 13:47:28 +00:00
for (lcv = 0; lcv < code_length; lcv++)
{
2020-12-29 13:47:28 +00:00
aux = G1[(lcv + chip_shift) % code_length];
if (aux == true)
{
2020-12-29 13:47:28 +00:00
dest[lcv] = std::complex<float>(1, 0);
}
else
{
2020-12-29 13:47:28 +00:00
dest[lcv] = std::complex<float>(-1, 0);
}
delay++;
2020-12-29 13:47:28 +00:00
delay %= code_length;
}
}
/*
* Generates complex GLONASS L2 C/A code for the desired SV ID and sampled to specific sampling frequency
*/
2020-12-29 13:47:28 +00:00
void glonass_l2_ca_code_gen_complex_sampled(own::span<std::complex<float>> dest, int32_t sampling_freq, uint32_t chip_shift)
{
2020-12-29 13:47:28 +00:00
constexpr int32_t codeFreqBasis = 511000; // chips per second
constexpr int32_t codeLength = 511;
constexpr float tc = 1.0 / static_cast<float>(codeFreqBasis); // C/A chip period in sec
2020-12-29 13:47:28 +00:00
const auto samplesPerCode = static_cast<int32_t>(static_cast<double>(sampling_freq) / (static_cast<double>(codeFreqBasis) / static_cast<double>(codeLength)));
const float ts = 1.0F / static_cast<float>(sampling_freq); // Sampling period in sec
2020-12-29 13:47:28 +00:00
std::array<std::complex<float>, 511> code_aux{};
int32_t codeValueIndex;
float aux;
2020-12-29 13:47:28 +00:00
glonass_l2_ca_code_gen_complex(code_aux, chip_shift); // generate C/A code 1 sample per chip
2020-12-29 13:47:28 +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 C/A code values --------------------
// The length of the index array depends on the sampling frequency -
2020-12-29 13:47:28 +00:00
// number of samples per millisecond (because one C/A code period is
// one millisecond).
2020-12-29 13:47:28 +00:00
aux = (ts * (static_cast<float>(i) + 1)) / tc;
codeValueIndex = AUX_CEIL(aux) - 1;
2019-07-28 10:01:11 +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.
2020-12-29 13:47:28 +00:00
if (i == samplesPerCode - 1)
{
2020-12-29 13:47:28 +00:00
// Correct the last index (due to number rounding issues)
dest[i] = code_aux[codeLength - 1];
}
else
{
2020-12-29 13:47:28 +00:00
dest[i] = code_aux[codeValueIndex]; // repeat the chip -> upsample
}
}
}