2018-03-24 18:42:04 +00:00
|
|
|
/*!
|
|
|
|
* \file glonass_l2_signal_processing.cc
|
|
|
|
* \brief This class implements various functions for GLONASS L2 CA signals
|
|
|
|
* \author Damian Miralles, 2018, dmiralles2009(at)gmail.com
|
|
|
|
*
|
|
|
|
* Detailed description of the file here if needed.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2019-07-26 10:38:20 +00:00
|
|
|
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
|
2018-03-24 18:42:04 +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/>.
|
2018-03-24 18:42:04 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "glonass_l2_signal_processing.h"
|
2019-07-14 12:09:12 +00:00
|
|
|
#include <array>
|
2019-07-18 18:01:54 +00:00
|
|
|
#include <bitset>
|
2018-03-24 18:42:04 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
auto auxCeil = [](float x) { return static_cast<int32_t>(static_cast<int64_t>((x) + 1)); };
|
2018-03-24 18:42:04 +00:00
|
|
|
|
2019-07-25 23:38:53 +00:00
|
|
|
void glonass_l2_ca_code_gen_complex(gsl::span<std::complex<float>> _dest, uint32_t _chip_shift)
|
2018-03-24 18:42:04 +00:00
|
|
|
{
|
2018-08-13 08:18:05 +00:00
|
|
|
const uint32_t _code_length = 511;
|
2019-07-18 18:01:54 +00:00
|
|
|
std::bitset<_code_length> G1{};
|
|
|
|
auto G1_register = std::bitset<9>{}.set(); // All true
|
2018-03-24 18:42:04 +00:00
|
|
|
bool feedback1;
|
|
|
|
bool aux;
|
2018-08-13 08:18:05 +00:00
|
|
|
uint32_t delay;
|
2019-08-12 22:19:31 +00:00
|
|
|
uint32_t lcv;
|
|
|
|
uint32_t lcv2;
|
2018-03-24 18:42:04 +00:00
|
|
|
|
|
|
|
/* Generate G1 Register */
|
|
|
|
for (lcv = 0; lcv < _code_length; lcv++)
|
|
|
|
{
|
|
|
|
G1[lcv] = G1_register[2];
|
|
|
|
|
2019-07-18 18:01:54 +00:00
|
|
|
feedback1 = G1_register[4] xor G1_register[0];
|
2018-03-24 18:42:04 +00:00
|
|
|
|
|
|
|
for (lcv2 = 0; lcv2 < 8; lcv2++)
|
|
|
|
{
|
|
|
|
G1_register[lcv2] = G1_register[lcv2 + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
G1_register[8] = feedback1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate PRN from G1 Register */
|
|
|
|
for (lcv = 0; lcv < _code_length; lcv++)
|
|
|
|
{
|
|
|
|
aux = G1[lcv];
|
|
|
|
if (aux == true)
|
|
|
|
{
|
|
|
|
_dest[lcv] = std::complex<float>(1, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_dest[lcv] = std::complex<float>(-1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the delay */
|
|
|
|
delay = _code_length;
|
|
|
|
delay += _chip_shift;
|
|
|
|
delay %= _code_length;
|
|
|
|
|
|
|
|
/* Generate PRN from G1 and G2 Registers */
|
|
|
|
for (lcv = 0; lcv < _code_length; lcv++)
|
|
|
|
{
|
|
|
|
aux = G1[(lcv + _chip_shift) % _code_length];
|
|
|
|
if (aux == true)
|
|
|
|
{
|
|
|
|
_dest[lcv] = std::complex<float>(1, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_dest[lcv] = std::complex<float>(-1, 0);
|
|
|
|
}
|
|
|
|
delay++;
|
|
|
|
delay %= _code_length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generates complex GLONASS L2 C/A code for the desired SV ID and sampled to specific sampling frequency
|
|
|
|
*/
|
2019-07-25 23:38:53 +00:00
|
|
|
void glonass_l2_ca_code_gen_complex_sampled(gsl::span<std::complex<float>> _dest, int32_t _fs, uint32_t _chip_shift)
|
2018-03-24 18:42:04 +00:00
|
|
|
{
|
|
|
|
// This function is based on the GNU software GPS for MATLAB in the Kay Borre book
|
2019-07-14 12:09:12 +00:00
|
|
|
std::array<std::complex<float>, 511> _code{};
|
2019-08-12 22:19:31 +00:00
|
|
|
int32_t _samplesPerCode;
|
|
|
|
int32_t _codeValueIndex;
|
2018-03-24 18:42:04 +00:00
|
|
|
float _ts;
|
|
|
|
float _tc;
|
|
|
|
float aux;
|
2019-07-14 12:09:12 +00:00
|
|
|
const int32_t _codeFreqBasis = 511000; // Hz
|
2018-08-13 08:18:05 +00:00
|
|
|
const int32_t _codeLength = 511;
|
2018-03-24 18:42:04 +00:00
|
|
|
|
2019-07-28 10:01:11 +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));
|
2018-03-24 18:42:04 +00:00
|
|
|
|
2019-07-28 10:01:11 +00:00
|
|
|
// --- Find time constants -------------------------------------------------
|
2019-07-14 12:09:12 +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
|
|
|
|
|
2019-07-18 20:03:56 +00:00
|
|
|
glonass_l2_ca_code_gen_complex(_code, _chip_shift); // generate C/A code 1 sample per chip
|
2018-03-24 18:42:04 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
for (int32_t i = 0; i < _samplesPerCode; i++)
|
2018-03-24 18:42:04 +00:00
|
|
|
{
|
2019-07-28 10:01:11 +00:00
|
|
|
// === Digitizing ==================================================
|
2018-03-24 18:42:04 +00:00
|
|
|
|
2019-07-28 10:01:11 +00:00
|
|
|
// --- Make index array to read C/A code values --------------------
|
2018-03-24 18:42:04 +00:00
|
|
|
// 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).
|
|
|
|
|
|
|
|
aux = (_ts * (i + 1)) / _tc;
|
|
|
|
_codeValueIndex = auxCeil(aux) - 1;
|
|
|
|
|
2019-07-28 10:01:11 +00:00
|
|
|
// --- Make the digitized version of the C/A code ------------------
|
2018-03-24 18:42:04 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2019-07-28 10:01:11 +00:00
|
|
|
// --- Correct the last index (due to number rounding issues) -----------
|
2018-03-24 18:42:04 +00:00
|
|
|
_dest[i] = _code[_codeLength - 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-18 20:03:56 +00:00
|
|
|
_dest[i] = _code[_codeValueIndex]; // repeat the chip -> upsample
|
2018-03-24 18:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|