2019-01-25 21:43:00 +00:00
|
|
|
/*!
|
2020-11-07 21:43:19 +00:00
|
|
|
* \file beidou_b3i_signal_replica.cc
|
|
|
|
* \brief This file implements various functions for BeiDou B3I signal replica
|
|
|
|
* generation
|
2019-01-25 21:43:00 +00:00
|
|
|
* \author Damian Miralles, 2019. dmiralles2009@gmail.com
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2019-01-25 21:43:00 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2019-01-25 21:43:00 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2019-01-25 21:43:00 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2019-01-25 21:43:00 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-07 21:43:19 +00:00
|
|
|
#include "beidou_b3i_signal_replica.h"
|
2019-07-14 12:09:12 +00:00
|
|
|
#include <array>
|
2019-07-15 13:13:18 +00:00
|
|
|
#include <bitset>
|
|
|
|
#include <string>
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-05-07 10:13:49 +00:00
|
|
|
const auto AUX_CEIL = [](float x) { return static_cast<int32_t>(static_cast<int64_t>((x) + 1)); };
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void beidou_b3i_code_gen_int(own::span<int> dest, int32_t prn, uint32_t chip_shift)
|
2019-01-25 21:43:00 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
constexpr uint32_t code_length = 10230;
|
|
|
|
std::bitset<code_length> G1{};
|
|
|
|
std::bitset<code_length> G2{};
|
2019-07-18 17:43:08 +00:00
|
|
|
auto G1_register = std::bitset<13>{}.set(); // All true
|
|
|
|
auto G2_register = std::bitset<13>{}.set(); // All true
|
|
|
|
auto G1_register_reset = std::bitset<13>{}.set();
|
2019-07-15 13:13:18 +00:00
|
|
|
G1_register_reset.reset(0);
|
|
|
|
G1_register_reset.reset(1); // {false, false, true, true, true, true, true, true, true, true, true, true, true};
|
|
|
|
|
2019-08-12 22:19:31 +00:00
|
|
|
bool feedback1;
|
|
|
|
bool feedback2;
|
|
|
|
bool aux;
|
|
|
|
uint32_t lcv;
|
|
|
|
uint32_t lcv2;
|
|
|
|
uint32_t delay;
|
2020-12-29 13:47:28 +00:00
|
|
|
int32_t prn_idx = prn - 1;
|
2019-03-18 21:23:51 +00:00
|
|
|
|
2019-07-15 13:13:18 +00:00
|
|
|
const std::array<std::bitset<13>, 63> G2_register_shifted =
|
|
|
|
{std::bitset<13>(std::string("1010111111111")),
|
|
|
|
std::bitset<13>(std::string("1111000101011")),
|
|
|
|
std::bitset<13>(std::string("1011110001010")),
|
|
|
|
std::bitset<13>(std::string("1111111111011")),
|
|
|
|
std::bitset<13>(std::string("1100100011111")),
|
|
|
|
std::bitset<13>(std::string("1001001100100")),
|
|
|
|
std::bitset<13>(std::string("1111111010010")),
|
|
|
|
std::bitset<13>(std::string("1110111111101")),
|
|
|
|
std::bitset<13>(std::string("1010000000010")),
|
|
|
|
std::bitset<13>(std::string("0010000011011")),
|
|
|
|
std::bitset<13>(std::string("1110101110000")),
|
|
|
|
std::bitset<13>(std::string("0010110011110")),
|
|
|
|
std::bitset<13>(std::string("0110010010101")),
|
|
|
|
std::bitset<13>(std::string("0111000100110")),
|
|
|
|
std::bitset<13>(std::string("1000110001001")),
|
|
|
|
std::bitset<13>(std::string("1110001111100")),
|
|
|
|
std::bitset<13>(std::string("0010011000101")),
|
|
|
|
std::bitset<13>(std::string("0000011101100")),
|
|
|
|
std::bitset<13>(std::string("1000101010111")),
|
|
|
|
std::bitset<13>(std::string("0001011011110")),
|
|
|
|
std::bitset<13>(std::string("0010000101101")),
|
|
|
|
std::bitset<13>(std::string("0010110001010")),
|
|
|
|
std::bitset<13>(std::string("0001011001111")),
|
|
|
|
std::bitset<13>(std::string("0011001100010")),
|
|
|
|
std::bitset<13>(std::string("0011101001000")),
|
|
|
|
std::bitset<13>(std::string("0100100101001")),
|
|
|
|
std::bitset<13>(std::string("1011011010011")),
|
|
|
|
std::bitset<13>(std::string("1010111100010")),
|
|
|
|
std::bitset<13>(std::string("0001011110101")),
|
|
|
|
std::bitset<13>(std::string("0111111111111")),
|
|
|
|
std::bitset<13>(std::string("0110110001111")),
|
|
|
|
std::bitset<13>(std::string("1010110001001")),
|
|
|
|
std::bitset<13>(std::string("1001010101011")),
|
|
|
|
std::bitset<13>(std::string("1100110100101")),
|
|
|
|
std::bitset<13>(std::string("1101001011101")),
|
|
|
|
std::bitset<13>(std::string("1111101110100")),
|
|
|
|
std::bitset<13>(std::string("0010101100111")),
|
|
|
|
std::bitset<13>(std::string("1110100010000")),
|
|
|
|
std::bitset<13>(std::string("1101110010000")),
|
|
|
|
std::bitset<13>(std::string("1101011001110")),
|
|
|
|
std::bitset<13>(std::string("1000000110100")),
|
|
|
|
std::bitset<13>(std::string("0101111011001")),
|
|
|
|
std::bitset<13>(std::string("0110110111100")),
|
|
|
|
std::bitset<13>(std::string("1101001110001")),
|
|
|
|
std::bitset<13>(std::string("0011100100010")),
|
|
|
|
std::bitset<13>(std::string("0101011000101")),
|
|
|
|
std::bitset<13>(std::string("1001111100110")),
|
|
|
|
std::bitset<13>(std::string("1111101001000")),
|
|
|
|
std::bitset<13>(std::string("0000101001001")),
|
|
|
|
std::bitset<13>(std::string("1000010101100")),
|
|
|
|
std::bitset<13>(std::string("1111001001100")),
|
|
|
|
std::bitset<13>(std::string("0100110001111")),
|
|
|
|
std::bitset<13>(std::string("0000000011000")),
|
|
|
|
std::bitset<13>(std::string("1000000000100")),
|
|
|
|
std::bitset<13>(std::string("0011010100110")),
|
|
|
|
std::bitset<13>(std::string("1011001000110")),
|
|
|
|
std::bitset<13>(std::string("0111001111000")),
|
|
|
|
std::bitset<13>(std::string("0010111001010")),
|
|
|
|
std::bitset<13>(std::string("1100111110110")),
|
|
|
|
std::bitset<13>(std::string("1001001000101")),
|
|
|
|
std::bitset<13>(std::string("0111000100000")),
|
|
|
|
std::bitset<13>(std::string("0011001000010")),
|
|
|
|
std::bitset<13>(std::string("0010001001110"))};
|
2019-03-18 21:23:51 +00:00
|
|
|
|
2019-01-28 01:05:41 +00:00
|
|
|
// A simple error check
|
|
|
|
if ((prn_idx < 0) || (prn_idx > 63))
|
2019-06-29 20:47:21 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2019-01-28 01:05:41 +00:00
|
|
|
// Assign shifted G2 register based on prn number
|
2019-01-25 21:43:00 +00:00
|
|
|
G2_register = G2_register_shifted[prn_idx];
|
2019-07-15 13:13:18 +00:00
|
|
|
|
2019-01-28 01:05:41 +00:00
|
|
|
// Generate G1 and G2 Register
|
2020-12-29 13:47:28 +00:00
|
|
|
for (lcv = 0; lcv < code_length; lcv++)
|
2019-03-18 07:43:38 +00:00
|
|
|
{
|
|
|
|
G1[lcv] = G1_register[0];
|
|
|
|
G2[lcv] = G2_register[0];
|
|
|
|
|
2019-07-14 21:34:07 +00:00
|
|
|
feedback1 = G1_register[0] xor G1_register[9] xor G1_register[10] xor G1_register[12];
|
|
|
|
feedback2 = G2_register[0] xor G2_register[1] xor G2_register[3] xor G2_register[4] xor
|
|
|
|
G2_register[6] xor G2_register[7] xor G2_register[8] xor G2_register[12];
|
2019-03-18 07:43:38 +00:00
|
|
|
|
|
|
|
for (lcv2 = 0; lcv2 < 12; lcv2++)
|
|
|
|
{
|
|
|
|
G1_register[lcv2] = G1_register[lcv2 + 1];
|
|
|
|
G2_register[lcv2] = G2_register[lcv2 + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
G1_register[12] = feedback1;
|
|
|
|
G2_register[12] = feedback2;
|
|
|
|
|
|
|
|
// Reset G1 register if sequence found
|
|
|
|
if (G1_register == G1_register_reset)
|
|
|
|
{
|
2019-07-18 17:43:08 +00:00
|
|
|
G1_register = std::bitset<13>{}.set(); // All true
|
2019-03-18 07:43:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-28 01:05:41 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
delay = code_length;
|
|
|
|
delay += chip_shift;
|
|
|
|
delay %= code_length;
|
2019-01-28 01:05:41 +00:00
|
|
|
|
2019-07-14 12:09:12 +00:00
|
|
|
// Generate PRN from G1 and G2 Registers
|
2020-12-29 13:47:28 +00:00
|
|
|
for (lcv = 0; lcv < code_length; lcv++)
|
2019-01-28 01:05:41 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
aux = G1[(lcv + chip_shift) % code_length] xor G2[delay];
|
2019-01-28 01:05:41 +00:00
|
|
|
if (aux == true)
|
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[lcv] = 1;
|
2019-01-28 01:05:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[lcv] = -1;
|
2019-01-28 01:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delay++;
|
2020-12-29 13:47:28 +00:00
|
|
|
delay %= code_length;
|
2019-01-28 01:05:41 +00:00
|
|
|
}
|
2019-01-25 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void beidou_b3i_code_gen_float(own::span<float> dest, int32_t prn, uint32_t chip_shift)
|
2019-01-25 21:43:00 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
constexpr uint32_t code_length = 10230;
|
|
|
|
std::array<int, code_length> b3i_code_int{};
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
beidou_b3i_code_gen_int(b3i_code_int, prn, chip_shift);
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t ii = 0; ii < code_length; ++ii)
|
2019-01-25 21:43:00 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[ii] = static_cast<float>(b3i_code_int[ii]);
|
2019-01-25 21:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void beidou_b3i_code_gen_complex(own::span<std::complex<float>> dest, int32_t prn, uint32_t chip_shift)
|
2019-01-25 21:43:00 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
constexpr uint32_t code_length = 10230;
|
|
|
|
std::array<int, code_length> b3i_code_int{};
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
beidou_b3i_code_gen_int(b3i_code_int, prn, chip_shift);
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
for (uint32_t ii = 0; ii < code_length; ++ii)
|
2019-01-25 21:43:00 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[ii] = std::complex<float>(static_cast<float>(b3i_code_int[ii]), 0.0F);
|
2019-01-25 21:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
void beidou_b3i_code_gen_complex_sampled(own::span<std::complex<float>> dest, uint32_t prn, int sampling_freq, uint32_t chip_shift)
|
2019-01-25 21:43:00 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
constexpr int32_t codeFreqBasis = 10230000; // chips per second
|
|
|
|
constexpr int32_t codeLength = 10230;
|
|
|
|
constexpr float tc = 1.0 / static_cast<float>(codeFreqBasis); // B3I chip period in sec
|
2020-07-03 09:36:38 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
const float ts = 1.0F / static_cast<float>(sampling_freq); // Sampling period in secs
|
|
|
|
const auto samplesPerCode = static_cast<int32_t>(static_cast<double>(sampling_freq) / (static_cast<double>(codeFreqBasis) / static_cast<double>(codeLength)));
|
2020-07-03 09:36:38 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
std::array<std::complex<float>, 10230> code_aux{};
|
2020-07-03 09:36:38 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
int32_t codeValueIndex;
|
2019-01-25 21:43:00 +00:00
|
|
|
float aux;
|
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
beidou_b3i_code_gen_complex(code_aux, prn, chip_shift); // generate B3I code 1 sample per chip
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
for (int32_t i = 0; i < samplesPerCode; i++)
|
2019-01-25 21:43:00 +00:00
|
|
|
{
|
2019-07-28 10:01:11 +00:00
|
|
|
// === Digitizing ==================================================
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-07-03 09:36:38 +00:00
|
|
|
// --- Make index array to read B3I code values --------------------
|
2019-01-25 21:43:00 +00:00
|
|
|
// The length of the index array depends on the sampling frequency -
|
2020-07-03 09:36:38 +00:00
|
|
|
// number of samples per millisecond (because one B3I code period is
|
|
|
|
// one millisecond).
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-12-29 13:47:28 +00:00
|
|
|
aux = (ts * (static_cast<float>(i) + 1)) / tc;
|
|
|
|
codeValueIndex = AUX_CEIL(aux) - 1;
|
2019-01-25 21:43:00 +00:00
|
|
|
|
2020-07-03 09:36:38 +00:00
|
|
|
// --- Make the digitized version of the B3I code ------------------
|
2020-12-29 13:47:28 +00:00
|
|
|
// The upsampled code is made by selecting values from the B3I code
|
|
|
|
// chip array for the time instances of each sample.
|
|
|
|
if (i == samplesPerCode - 1)
|
2019-01-25 21:43:00 +00:00
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
// Correct the last index (due to number rounding issues)
|
|
|
|
dest[i] = code_aux[codeLength - 1];
|
2019-01-25 21:43:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-29 13:47:28 +00:00
|
|
|
dest[i] = code_aux[codeValueIndex]; // repeat the chip -> upsample
|
2019-01-25 21:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|