1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-16 05:00:35 +00:00
gnss-sdr/src/tests/unit-tests/arithmetic/code_generation_test.cc

146 lines
22 KiB
C++
Raw Normal View History

2015-05-03 08:50:57 +00:00
/*!
* \file code_generation_test.cc
* \brief This file implements tests for the generation of complex exponentials.
* \author Carles Fernandez-Prades, 2014. cfernandez(at)cttc.es
*
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
2015-05-03 08:50:57 +00:00
*
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
2015-05-03 08:50:57 +00:00
* 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
2015-05-03 08:50:57 +00:00
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
2015-05-03 08:50:57 +00:00
*/
#include "Galileo_E6.h"
#include "galileo_e6_signal_replica.h"
#include "gnss_signal_replica.h"
#include "gps_sdr_signal_replica.h"
#include <array>
#include <chrono>
2015-05-03 08:50:57 +00:00
#include <complex>
#include <vector>
2015-05-03 08:50:57 +00:00
2017-07-03 10:43:25 +00:00
TEST(CodeGenerationTest, CodeGenGPSL1Test)
2015-05-03 08:50:57 +00:00
{
std::array<std::complex<float>, 1023> _dest{};
2015-05-03 08:50:57 +00:00
signed int _prn = 1;
unsigned int _chip_shift = 4;
2015-05-10 11:20:52 +00:00
int iterations = 1000;
2015-05-03 08:50:57 +00:00
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
2015-05-03 08:50:57 +00:00
for (int i = 0; i < iterations; i++)
2015-05-03 08:50:57 +00:00
{
gps_l1_ca_code_gen_complex(_dest, _prn, _chip_shift);
2015-05-03 08:50:57 +00:00
}
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
2015-05-03 08:50:57 +00:00
2017-08-14 22:04:51 +00:00
ASSERT_LE(0, elapsed_seconds.count());
std::cout << "Generation completed in " << elapsed_seconds.count() * 1e6 << " microseconds\n";
2015-05-03 08:50:57 +00:00
}
2015-05-05 11:00:24 +00:00
2017-07-03 10:43:25 +00:00
TEST(CodeGenerationTest, CodeGenGPSL1SampledTest)
2015-05-05 11:00:24 +00:00
{
signed int _prn = 1;
unsigned int _chip_shift = 4;
double _fs = 8000000.0;
2020-12-29 13:47:28 +00:00
const signed int codeFreqBasis = 1023000; // Hz
const signed int codeLength = 1023;
int samplesPerCode = round(_fs / static_cast<double>(codeFreqBasis / codeLength));
std::vector<std::complex<float>> _dest(samplesPerCode);
2015-05-05 11:00:24 +00:00
2015-05-10 11:20:52 +00:00
int iterations = 1000;
2015-05-05 11:00:24 +00:00
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
2015-05-05 11:00:24 +00:00
for (int i = 0; i < iterations; i++)
2015-05-05 11:00:24 +00:00
{
gps_l1_ca_code_gen_complex_sampled(_dest, _prn, _fs, _chip_shift);
2015-05-05 11:00:24 +00:00
}
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
2015-05-13 14:40:46 +00:00
2017-08-14 22:04:51 +00:00
ASSERT_LE(0, elapsed_seconds.count());
std::cout << "Generation completed in " << elapsed_seconds.count() * 1e6 << " microseconds\n";
2015-05-05 11:00:24 +00:00
}
2015-05-05 14:14:46 +00:00
2017-07-03 10:43:25 +00:00
TEST(CodeGenerationTest, ComplexConjugateTest)
2015-05-05 14:14:46 +00:00
{
double _fs = 8000000.0;
double _f = 4000.0;
2020-12-29 13:47:28 +00:00
const signed int codeFreqBasis = 1023000; // Hz
const signed int codeLength = 1023;
int samplesPerCode = round(_fs / static_cast<double>(codeFreqBasis / codeLength));
std::vector<std::complex<float>> _dest(samplesPerCode);
2015-05-05 14:14:46 +00:00
2015-05-10 11:20:52 +00:00
int iterations = 1000;
2015-05-05 14:14:46 +00:00
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
2015-05-05 14:14:46 +00:00
for (int i = 0; i < iterations; i++)
2015-05-05 14:14:46 +00:00
{
complex_exp_gen_conj(_dest, _f, _fs);
2015-05-05 14:14:46 +00:00
}
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
2017-08-14 22:04:51 +00:00
ASSERT_LE(0, elapsed_seconds.count());
std::cout << "Generation completed in " << elapsed_seconds.count() * 1e6 << " microseconds\n";
2015-05-05 14:14:46 +00:00
}
TEST(CodeGenerationTest, GalileoE6CSecondaryTest)
{
const auto len = static_cast<int32_t>(GALILEO_E6_C_SECONDARY_CODE_LENGTH_CHIPS);
std::array<float, len> secondary_code{};
int prn = 1;
galileo_e6_c_secondary_code_gen_float(secondary_code, prn);
std::array<float, len> expected_output = {-1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, 1};
for (int i = 0; i < len; i++)
{
ASSERT_FLOAT_EQ(secondary_code[i], expected_output[i]);
}
prn = 2;
std::string generated_string = galileo_e6_c_secondary_code(prn);
std::string expected_string("0110011001010101100010111101001111001110000011000111011110010010111010000011001101010000010100100101");
for (int i = 0; i < len; i++)
{
ASSERT_FLOAT_EQ(generated_string[i], expected_string[i]);
}
}
TEST(CodeGenerationTest, GalileoE6BTest)
{
const auto len = static_cast<int32_t>(GALILEO_E6_B_CODE_LENGTH_CHIPS);
std::array<std::complex<float>, len> gale6b_code{};
int prn = 1;
galileo_e6_b_code_gen_complex_primary(gale6b_code, prn);
std::array<std::complex<float>, len> expected_output = {};
std::array<float, len> expected_bin = {-1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1, 1, -1, 1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
for (int i = 0; i < len; i++)
{
expected_output[i] = std::complex<float>(expected_bin[i], 0.0);
}
for (int i = 0; i < len; i++)
{
ASSERT_FLOAT_EQ(gale6b_code[i].real(), expected_output[i].real());
}
}