2012-07-12 21:17:37 +00:00
|
|
|
/*!
|
2020-11-07 21:43:19 +00:00
|
|
|
* \file galileo_e1_signal_replica.cc
|
|
|
|
* \brief This library implements various functions for Galileo E1 signal
|
|
|
|
* replica generation
|
2012-07-12 21:17:37 +00:00
|
|
|
* \author Luis Esteve, 2012. luis(at)epsilon-formacion.com
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2012-07-12 21:17:37 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2012-07-12 21:17:37 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2012-07-12 21:17:37 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2012-07-12 21:17:37 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-07 21:43:19 +00:00
|
|
|
#include "galileo_e1_signal_replica.h"
|
2016-01-10 21:21:31 +00:00
|
|
|
#include "Galileo_E1.h"
|
2020-11-07 21:43:19 +00:00
|
|
|
#include "gnss_signal_replica.h"
|
2020-07-10 20:06:29 +00:00
|
|
|
#include <cmath>
|
2020-07-21 12:31:45 +00:00
|
|
|
#include <cstddef> // for size_t
|
2019-06-30 02:47:15 +00:00
|
|
|
#include <memory>
|
2018-02-26 02:15:53 +00:00
|
|
|
#include <string>
|
2019-08-17 11:56:54 +00:00
|
|
|
#include <utility>
|
2019-07-18 20:03:56 +00:00
|
|
|
#include <vector>
|
2014-01-12 20:07:38 +00:00
|
|
|
|
2012-07-12 21:17:37 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_code_gen_int(own::span<int> dest, const std::array<char, 3>& signal_id, int32_t prn)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
const std::string galileo_signal = signal_id.data();
|
|
|
|
const int32_t prn_ = prn - 1;
|
2018-08-13 08:18:05 +00:00
|
|
|
int32_t index = 0;
|
2012-07-12 21:17:37 +00:00
|
|
|
|
2018-08-16 12:16:43 +00:00
|
|
|
// A simple error check
|
2020-12-29 13:47:28 +00:00
|
|
|
if ((prn < 1) || (prn > 50))
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
if (galileo_signal.rfind("1B") != std::string::npos && galileo_signal.length() >= 2)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-07-03 09:36:38 +00:00
|
|
|
for (size_t i = 0; i < GALILEO_E1_B_PRIMARY_CODE_STR_LENGTH; i++)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
hex_to_binary_converter(dest.subspan(index, 4), GALILEO_E1_B_PRIMARY_CODE[prn_][i]);
|
2018-03-16 11:21:13 +00:00
|
|
|
index += 4;
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-29 13:47:28 +00:00
|
|
|
else if (galileo_signal.rfind("1C") != std::string::npos && galileo_signal.length() >= 2)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-07-03 09:36:38 +00:00
|
|
|
for (size_t i = 0; i < GALILEO_E1_C_PRIMARY_CODE_STR_LENGTH; i++)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
hex_to_binary_converter(dest.subspan(index, 4), GALILEO_E1_C_PRIMARY_CODE[prn_][i]);
|
2018-03-16 11:21:13 +00:00
|
|
|
index += 4;
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_sinboc_11_gen_int(own::span<int> dest, own::span<const int> prn)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
constexpr uint32_t length_in = GALILEO_E1_B_CODE_LENGTH_CHIPS;
|
|
|
|
const auto period = static_cast<uint32_t>(dest.size() / length_in);
|
|
|
|
for (uint32_t i = 0; i < length_in; i++)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t j = 0; j < (period / 2); j++)
|
2015-03-16 23:22:20 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i * period + j] = prn[i];
|
2015-03-16 23:22:20 +00:00
|
|
|
}
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t j = (period / 2); j < period; j++)
|
2015-03-16 23:22:20 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i * period + j] = -prn[i];
|
2015-03-16 23:22:20 +00:00
|
|
|
}
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_sinboc_61_gen_int(own::span<int> dest, own::span<const int> prn)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
constexpr uint32_t length_in = GALILEO_E1_B_CODE_LENGTH_CHIPS;
|
|
|
|
const auto period = static_cast<uint32_t>(dest.size() / length_in);
|
2012-07-12 21:17:37 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t i = 0; i < length_in; i++)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t j = 0; j < period; j += 2)
|
2015-03-16 23:22:20 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i * period + j] = prn[i];
|
2015-03-16 23:22:20 +00:00
|
|
|
}
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t j = 1; j < period; j += 2)
|
2015-03-16 23:22:20 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i * period + j] = -prn[i];
|
2015-03-16 23:22:20 +00:00
|
|
|
}
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_code_gen_sinboc11_float(own::span<float> dest, const std::array<char, 3>& signal_id, uint32_t prn)
|
2018-03-16 11:21:13 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
const auto codeLength = static_cast<uint32_t>(GALILEO_E1_B_CODE_LENGTH_CHIPS);
|
2019-07-18 20:03:56 +00:00
|
|
|
std::array<int32_t, 4092> primary_code_E1_chips{};
|
2020-12-29 13:47:28 +00:00
|
|
|
galileo_e1_code_gen_int(primary_code_E1_chips, signal_id, prn); // generate Galileo E1 code, 1 sample per chip
|
|
|
|
for (uint32_t i = 0; i < codeLength; i++)
|
2018-03-16 11:21:13 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[2 * i] = static_cast<float>(primary_code_E1_chips[i]);
|
|
|
|
dest[2 * i + 1] = -dest[2 * i];
|
2018-03-16 11:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2018-08-13 08:18:05 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_gen_float(own::span<float> dest, own::span<int> prn, const std::array<char, 3>& signal_id)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
const auto codeLength = dest.size();
|
2020-07-10 20:06:29 +00:00
|
|
|
const float alpha = std::sqrt(10.0F / 11.0F);
|
|
|
|
const float beta = std::sqrt(1.0F / 11.0F);
|
2020-12-29 13:47:28 +00:00
|
|
|
const std::string galileo_signal = signal_id.data();
|
2020-07-03 09:36:38 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
std::vector<int32_t> sinboc_11(codeLength);
|
|
|
|
std::vector<int32_t> sinboc_61(codeLength);
|
2012-07-12 21:17:37 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
galileo_e1_sinboc_11_gen_int(sinboc_11, prn); // generate sinboc(1,1) 12 samples per chip
|
|
|
|
galileo_e1_sinboc_61_gen_int(sinboc_61, prn); // generate sinboc(6,1) 12 samples per chip
|
2012-07-12 21:17:37 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
if (galileo_signal.rfind("1B") != std::string::npos && galileo_signal.length() >= 2)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
for (size_t i = 0; i < codeLength; i++)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i] = alpha * static_cast<float>(sinboc_11[i]) +
|
|
|
|
beta * static_cast<float>(sinboc_61[i]);
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-29 13:47:28 +00:00
|
|
|
else if (galileo_signal.rfind("1C") != std::string::npos && galileo_signal.length() >= 2)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
for (size_t i = 0; i < codeLength; i++)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i] = alpha * static_cast<float>(sinboc_11[i]) -
|
|
|
|
beta * static_cast<float>(sinboc_61[i]);
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_code_gen_float_sampled(own::span<float> dest, const std::array<char, 3>& signal_id,
|
|
|
|
bool cboc, uint32_t prn, int32_t sampling_freq, uint32_t chip_shift,
|
|
|
|
bool secondary_flag)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
constexpr int32_t codeFreqBasis = GALILEO_E1_CODE_CHIP_RATE_CPS; // chips per second
|
|
|
|
const int32_t samplesPerChip = (cboc == true) ? 12 : 2;
|
|
|
|
const uint32_t codeLength = samplesPerChip * GALILEO_E1_B_CODE_LENGTH_CHIPS;
|
|
|
|
const std::string galileo_signal = signal_id.data();
|
|
|
|
auto samplesPerCode = static_cast<uint32_t>(static_cast<double>(sampling_freq) / (static_cast<double>(codeFreqBasis) / GALILEO_E1_B_CODE_LENGTH_CHIPS));
|
|
|
|
const uint32_t delay = ((static_cast<int32_t>(GALILEO_E1_B_CODE_LENGTH_CHIPS) - chip_shift) % static_cast<int32_t>(GALILEO_E1_B_CODE_LENGTH_CHIPS)) * samplesPerCode / GALILEO_E1_B_CODE_LENGTH_CHIPS;
|
2012-07-12 21:17:37 +00:00
|
|
|
|
2020-07-03 09:36:38 +00:00
|
|
|
std::vector<int32_t> primary_code_E1_chips(static_cast<int32_t>(GALILEO_E1_B_CODE_LENGTH_CHIPS));
|
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
galileo_e1_code_gen_int(primary_code_E1_chips, signal_id, prn); // generate Galileo E1 code, 1 sample per chip
|
2012-07-12 21:17:37 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
std::vector<float> signal_E1(codeLength);
|
2019-06-29 14:49:53 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
if (cboc == true)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
galileo_e1_gen_float(signal_E1, primary_code_E1_chips, signal_id); // generate cboc 12 samples per chip
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
std::vector<int32_t> signal_E1_int(static_cast<int32_t>(codeLength));
|
|
|
|
galileo_e1_sinboc_11_gen_int(signal_E1_int, primary_code_E1_chips); // generate sinboc(1,1) 2 samples per chip
|
2017-09-11 14:21:05 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t ii = 0; ii < codeLength; ++ii)
|
2017-09-11 14:21:05 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
signal_E1[ii] = static_cast<float>(signal_E1_int[ii]);
|
2017-09-11 14:21:05 +00:00
|
|
|
}
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
2013-07-23 18:03:07 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
if (sampling_freq != samplesPerChip * codeFreqBasis)
|
2013-07-23 18:03:07 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
std::vector<float> resampled_signal(samplesPerCode);
|
2018-08-16 12:16:43 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
resampler(signal_E1, resampled_signal, static_cast<float>(samplesPerChip * codeFreqBasis), sampling_freq); // resamples code to fs
|
2013-07-23 18:03:07 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
signal_E1 = std::move(resampled_signal);
|
2013-07-23 18:03:07 +00:00
|
|
|
}
|
2019-11-29 23:31:07 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
if (galileo_signal.rfind("1C") != std::string::npos && galileo_signal.length() >= 2 && secondary_flag)
|
2017-09-15 23:14:15 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
std::vector<float> signal_E1C_secondary(static_cast<int32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH) * samplesPerCode);
|
2019-02-22 09:47:24 +00:00
|
|
|
for (uint32_t i = 0; i < static_cast<uint32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH); i++)
|
2017-09-15 23:14:15 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t k = 0; k < samplesPerCode; k++)
|
2017-09-15 23:14:15 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
signal_E1C_secondary[i * samplesPerCode + k] = signal_E1[k] * (GALILEO_E1_C_SECONDARY_CODE[i] == '0' ? 1.0F : -1.0F);
|
2017-09-15 23:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-23 18:03:07 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
samplesPerCode *= static_cast<int32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH);
|
2013-07-23 18:03:07 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
signal_E1 = std::move(signal_E1C_secondary);
|
2017-09-15 23:14:15 +00:00
|
|
|
}
|
2019-11-29 23:31:07 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t i = 0; i < samplesPerCode; i++)
|
2013-07-23 18:03:07 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[(i + delay) % samplesPerCode] = signal_E1[i];
|
2013-07-23 18:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 23:14:15 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_code_gen_complex_sampled(own::span<std::complex<float>> dest, const std::array<char, 3>& signal_id,
|
|
|
|
bool cboc, uint32_t prn, int32_t sampling_freq, uint32_t chip_shift,
|
|
|
|
bool secondary_flag)
|
2017-09-11 14:21:05 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
constexpr int32_t codeFreqBasis = GALILEO_E1_CODE_CHIP_RATE_CPS; // Hz
|
|
|
|
const std::string galileo_signal = signal_id.data();
|
|
|
|
auto samplesPerCode = static_cast<uint32_t>(static_cast<double>(sampling_freq) /
|
|
|
|
(static_cast<double>(codeFreqBasis) / GALILEO_E1_B_CODE_LENGTH_CHIPS));
|
2017-09-11 14:21:05 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
if (galileo_signal.rfind("1C") != std::string::npos && galileo_signal.length() >= 2 && secondary_flag)
|
2017-09-15 23:14:15 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
samplesPerCode *= static_cast<int32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH);
|
2017-09-15 23:14:15 +00:00
|
|
|
}
|
2017-09-11 14:21:05 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
std::vector<float> real_code(samplesPerCode);
|
|
|
|
galileo_e1_code_gen_float_sampled(real_code, signal_id, cboc, prn, sampling_freq, chip_shift, secondary_flag);
|
2017-09-11 14:21:05 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t ii = 0; ii < samplesPerCode; ++ii)
|
2017-09-11 14:21:05 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[ii] = std::complex<float>(real_code[ii], 0.0F);
|
2017-09-11 14:21:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 23:14:15 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_code_gen_float_sampled(own::span<float> dest, const std::array<char, 3>& signal_id,
|
|
|
|
bool cboc, uint32_t prn, int32_t sampling_freq, uint32_t chip_shift)
|
2017-09-11 14:21:05 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
galileo_e1_code_gen_float_sampled(dest, signal_id, cboc, prn, sampling_freq, chip_shift, false);
|
2017-09-11 14:21:05 +00:00
|
|
|
}
|
2013-07-23 18:03:07 +00:00
|
|
|
|
2017-09-15 23:14:15 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void galileo_e1_code_gen_complex_sampled(own::span<std::complex<float>> dest, const std::array<char, 3>& signal_id,
|
|
|
|
bool cboc, uint32_t prn, int32_t sampling_freq, uint32_t chip_shift)
|
2013-07-23 18:03:07 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
galileo_e1_code_gen_complex_sampled(dest, signal_id, cboc, prn, sampling_freq, chip_shift, false);
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|