2018-06-15 02:19:32 +00:00
|
|
|
/*!
|
2018-10-22 20:12:50 +00:00
|
|
|
* \file beidou_b1i_signal_processing.cc
|
2018-06-15 02:19:32 +00:00
|
|
|
* \brief This class implements various functions for BeiDou B1I signal
|
|
|
|
* \author Sergi Segura, 2018. sergi.segura.munoz(at)gmail.com
|
|
|
|
*
|
|
|
|
* Detailed description of the file here if needed.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2019-02-10 11:45:23 +00:00
|
|
|
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
|
2018-06-15 02:19:32 +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
|
2018-06-15 02:19:32 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2018-10-22 20:12:50 +00:00
|
|
|
#include "beidou_b1i_signal_processing.h"
|
2019-07-14 12:09:12 +00:00
|
|
|
#include <array>
|
2019-07-15 13:13:18 +00:00
|
|
|
#include <bitset>
|
|
|
|
#include <string>
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-02-10 11:45:23 +00:00
|
|
|
auto auxCeil = [](float x) { return static_cast<int32_t>(static_cast<int64_t>((x) + 1)); };
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-06-28 23:28:30 +00:00
|
|
|
void beidou_b1i_code_gen_int(gsl::span<int32_t> _dest, int32_t _prn, uint32_t _chip_shift)
|
2018-06-15 02:19:32 +00:00
|
|
|
{
|
2019-02-10 11:45:23 +00:00
|
|
|
const uint32_t _code_length = 2046;
|
2019-07-15 13:13:18 +00:00
|
|
|
std::bitset<_code_length> G1{};
|
|
|
|
std::bitset<_code_length> G2{};
|
|
|
|
|
|
|
|
std::bitset<11> G1_register(std::string("01010101010"));
|
|
|
|
std::bitset<11> G2_register(std::string("01010101010"));
|
2019-07-14 12:09:12 +00:00
|
|
|
|
2019-08-12 22:19:31 +00:00
|
|
|
bool feedback1;
|
|
|
|
bool feedback2;
|
2018-06-15 02:19:32 +00:00
|
|
|
bool aux;
|
2019-08-12 22:19:31 +00:00
|
|
|
uint32_t lcv;
|
|
|
|
uint32_t lcv2;
|
2019-02-10 11:45:23 +00:00
|
|
|
uint32_t delay;
|
|
|
|
int32_t prn_idx;
|
2019-07-14 12:09:12 +00:00
|
|
|
|
|
|
|
const std::array<int32_t, 33> delays = {712 /*PRN1*/, 1581, 1414, 1550, 581, 771, 1311, 1043, 1549, 359, 710, 1579, 1548, 1103, 579, 769, 358, 709, 1411, 1547,
|
2018-07-06 12:42:13 +00:00
|
|
|
1102, 578, 357, 1577, 1410, 1546, 1101, 707, 1576, 1409, 1545, 354 /*PRN32*/,
|
|
|
|
705};
|
2019-07-14 12:09:12 +00:00
|
|
|
const std::array<int32_t, 37> phase1 = {1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 8, 8, 8, 9, 9, 10};
|
|
|
|
const std::array<int32_t, 37> phase2 = {3, 4, 5, 6, 8, 9, 10, 11, 7, 4, 5, 6, 8, 9, 10, 11, 5, 6, 8, 9, 10, 11, 6, 8, 9, 10, 11, 8, 9, 10, 11, 9, 10, 11, 10, 11, 11};
|
2018-07-06 12:58:32 +00:00
|
|
|
|
2018-06-15 02:19:32 +00:00
|
|
|
// compute delay array index for given PRN number
|
2018-07-06 12:58:32 +00:00
|
|
|
prn_idx = _prn - 1;
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-07-14 12:09:12 +00:00
|
|
|
// A simple error check
|
2019-02-14 22:44:38 +00:00
|
|
|
if ((prn_idx < 0) || (prn_idx > 32))
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-07-14 12:09:12 +00:00
|
|
|
// Generate G1 & G2 Register
|
2018-06-15 02:19:32 +00:00
|
|
|
for (lcv = 0; lcv < _code_length; lcv++)
|
|
|
|
{
|
|
|
|
G1[lcv] = G1_register[0];
|
2019-07-18 17:47:27 +00:00
|
|
|
G2[lcv] = G2_register[-(phase1[prn_idx] - 11)] xor G2_register[-(phase2[prn_idx] - 11)];
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-07-14 21:34:07 +00:00
|
|
|
feedback1 = G1_register[0] xor G1_register[1] xor G1_register[2] xor G1_register[3] xor G1_register[4] xor G1_register[10];
|
|
|
|
feedback2 = G2_register[0] xor G2_register[2] xor G2_register[3] xor G2_register[6] xor G2_register[7] xor G2_register[8] xor G2_register[9] xor G2_register[10];
|
2018-06-15 02:19:32 +00:00
|
|
|
|
|
|
|
for (lcv2 = 0; lcv2 < 10; lcv2++)
|
|
|
|
{
|
|
|
|
G1_register[lcv2] = G1_register[lcv2 + 1];
|
|
|
|
G2_register[lcv2] = G2_register[lcv2 + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
G1_register[10] = feedback1;
|
|
|
|
G2_register[10] = feedback2;
|
|
|
|
}
|
|
|
|
|
2019-07-14 12:09:12 +00:00
|
|
|
// Set the delay
|
2019-01-28 01:29:43 +00:00
|
|
|
delay = _code_length - delays[prn_idx] * 0; //**********************************
|
2018-06-15 02:19:32 +00:00
|
|
|
delay += _chip_shift;
|
|
|
|
delay %= _code_length;
|
|
|
|
|
2019-07-14 12:09:12 +00:00
|
|
|
// Generate PRN from G1 and G2 Registers
|
2018-06-15 02:19:32 +00:00
|
|
|
for (lcv = 0; lcv < _code_length; lcv++)
|
|
|
|
{
|
2019-07-18 17:47:27 +00:00
|
|
|
aux = G1[(lcv + _chip_shift) % _code_length] xor G2[delay];
|
2018-06-15 02:19:32 +00:00
|
|
|
if (aux == true)
|
|
|
|
{
|
|
|
|
_dest[lcv] = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_dest[lcv] = -1;
|
|
|
|
}
|
2018-07-06 13:55:00 +00:00
|
|
|
|
2018-06-15 02:19:32 +00:00
|
|
|
delay++;
|
|
|
|
delay %= _code_length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-28 23:28:30 +00:00
|
|
|
void beidou_b1i_code_gen_float(gsl::span<float> _dest, int32_t _prn, uint32_t _chip_shift)
|
2018-06-15 02:19:32 +00:00
|
|
|
{
|
2019-07-14 12:09:12 +00:00
|
|
|
const uint32_t _code_length = 2046;
|
|
|
|
std::array<int32_t, _code_length> b1i_code_int{};
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-07-14 12:09:12 +00:00
|
|
|
beidou_b1i_code_gen_int(gsl::span<int32_t>(b1i_code_int.data(), _code_length), _prn, _chip_shift);
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-02-10 11:45:23 +00:00
|
|
|
for (uint32_t ii = 0; ii < _code_length; ++ii)
|
2018-06-15 02:19:32 +00:00
|
|
|
{
|
|
|
|
_dest[ii] = static_cast<float>(b1i_code_int[ii]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-28 23:28:30 +00:00
|
|
|
void beidou_b1i_code_gen_complex(gsl::span<std::complex<float>> _dest, int32_t _prn, uint32_t _chip_shift)
|
2018-06-15 02:19:32 +00:00
|
|
|
{
|
2019-07-14 12:09:12 +00:00
|
|
|
const uint32_t _code_length = 2046;
|
|
|
|
std::array<int32_t, _code_length> b1i_code_int{};
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-07-14 12:09:12 +00:00
|
|
|
beidou_b1i_code_gen_int(gsl::span<int32_t>(b1i_code_int.data(), _code_length), _prn, _chip_shift);
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-02-10 11:45:23 +00:00
|
|
|
for (uint32_t ii = 0; ii < _code_length; ++ii)
|
2018-06-15 02:19:32 +00:00
|
|
|
{
|
2019-06-29 12:22:15 +00:00
|
|
|
_dest[ii] = std::complex<float>(static_cast<float>(b1i_code_int[ii]), 0.0F);
|
2018-06-15 02:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generates complex GPS L1 C/A code for the desired SV ID and sampled to specific sampling frequency
|
|
|
|
*/
|
2019-06-28 23:28:30 +00:00
|
|
|
void beidou_b1i_code_gen_complex_sampled(gsl::span<std::complex<float>> _dest, uint32_t _prn, int32_t _fs, uint32_t _chip_shift)
|
2018-06-15 02:19:32 +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>, 2046> _code{};
|
2019-08-12 22:19:31 +00:00
|
|
|
int32_t _samplesPerCode;
|
|
|
|
int32_t _codeValueIndex;
|
2018-06-15 02:19:32 +00:00
|
|
|
float _ts;
|
|
|
|
float _tc;
|
|
|
|
float aux;
|
2019-07-14 12:09:12 +00:00
|
|
|
const int32_t _codeFreqBasis = 2046000; // Hz
|
2019-02-10 11:45:23 +00:00
|
|
|
const int32_t _codeLength = 2046;
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-07-28 10:01:11 +00:00
|
|
|
// --- Find number of samples per spreading code ---------------------------
|
2019-08-24 15:34:12 +00:00
|
|
|
_samplesPerCode = static_cast<int32_t>(static_cast<double>(_fs) / (static_cast<double>(_codeFreqBasis) / static_cast<double>(_codeLength)));
|
2018-06-15 02:19:32 +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
|
|
|
|
|
|
|
|
beidou_b1i_code_gen_complex(_code, _prn, _chip_shift); // generate C/A code 1 sample per chip
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-02-10 11:45:23 +00:00
|
|
|
for (int32_t i = 0; i < _samplesPerCode; i++)
|
2018-06-15 02:19:32 +00:00
|
|
|
{
|
2019-07-28 10:01:11 +00:00
|
|
|
// === Digitizing ==================================================
|
2018-06-15 02:19:32 +00:00
|
|
|
|
2019-07-28 10:01:11 +00:00
|
|
|
// --- Make index array to read C/A code values --------------------
|
2018-06-15 02:19:32 +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-06-15 02:19:32 +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-06-15 02:19:32 +00:00
|
|
|
_dest[i] = _code[_codeLength - 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-28 10:01:11 +00:00
|
|
|
_dest[i] = _code[_codeValueIndex]; // repeat the chip -> upsample
|
2018-06-15 02:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|