2014-03-28 17:52:51 +00:00
|
|
|
/*!
|
|
|
|
* \file complex_carrier_test.cc
|
|
|
|
* \brief This file implements tests for the generation of complex exponentials.
|
|
|
|
* \author Carles Fernandez-Prades, 2014. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2018-05-13 20:49:11 +00:00
|
|
|
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
2014-03-28 17:52:51 +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
|
2015-01-08 18:49:59 +00:00
|
|
|
* (at your option) any later version.
|
2014-03-28 17:52:51 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
2014-03-28 17:52:51 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2019-03-05 18:31:41 +00:00
|
|
|
#include "GPS_L1_CA.h"
|
2018-12-09 21:00:09 +00:00
|
|
|
#include "gnss_signal_processing.h"
|
|
|
|
#include <armadillo>
|
2017-08-11 03:18:38 +00:00
|
|
|
#include <chrono>
|
2014-03-28 17:52:51 +00:00
|
|
|
#include <complex>
|
2019-06-28 23:28:30 +00:00
|
|
|
#if HAS_SPAN
|
|
|
|
#include <span>
|
|
|
|
namespace gsl = std;
|
|
|
|
#else
|
|
|
|
#include <gsl/gsl>
|
|
|
|
#endif
|
2014-03-28 17:52:51 +00:00
|
|
|
|
|
|
|
DEFINE_int32(size_carrier_test, 100000, "Size of the arrays used for complex carrier testing");
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(ComplexCarrierTest, StandardComplexImplementation)
|
2014-03-28 17:52:51 +00:00
|
|
|
{
|
2014-03-29 19:11:32 +00:00
|
|
|
// Dynamic allocation creates new usable space on the program STACK
|
|
|
|
// (an area of RAM specifically allocated to the program)
|
2019-02-11 14:33:24 +00:00
|
|
|
auto* output = new std::complex<float>[FLAGS_size_carrier_test];
|
2017-08-18 10:45:47 +00:00
|
|
|
const double _f = 2000.0;
|
|
|
|
const double _fs = 2000000.0;
|
2019-02-11 14:33:24 +00:00
|
|
|
const auto phase_step = static_cast<double>((GPS_TWO_PI * _f) / _fs);
|
2017-08-18 10:45:47 +00:00
|
|
|
double phase = 0.0;
|
2014-03-29 19:11:32 +00:00
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2014-03-28 17:52:51 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < FLAGS_size_carrier_test; i++)
|
|
|
|
{
|
|
|
|
output[i] = std::complex<float>(cos(phase), sin(phase));
|
|
|
|
phase += phase_step;
|
|
|
|
}
|
2014-03-28 17:52:51 +00:00
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
2014-03-28 17:52:51 +00:00
|
|
|
std::cout << "A " << FLAGS_size_carrier_test
|
2018-03-03 01:03:39 +00:00
|
|
|
<< "-length complex carrier in standard C++ (dynamic allocation) generated in " << elapsed_seconds.count() * 1e6
|
2014-03-28 17:52:51 +00:00
|
|
|
<< " microseconds" << std::endl;
|
2015-05-13 14:40:46 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
std::complex<float> expected(1, 0);
|
2014-03-29 19:11:32 +00:00
|
|
|
std::vector<std::complex<float>> mag(FLAGS_size_carrier_test);
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < FLAGS_size_carrier_test; i++)
|
2014-03-29 19:11:32 +00:00
|
|
|
{
|
|
|
|
mag[i] = output[i] * std::conj(output[i]);
|
2015-05-13 14:40:46 +00:00
|
|
|
}
|
|
|
|
delete[] output;
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < FLAGS_size_carrier_test; i++)
|
2015-05-13 14:40:46 +00:00
|
|
|
{
|
2014-03-29 19:11:32 +00:00
|
|
|
ASSERT_FLOAT_EQ(std::norm(expected), std::norm(mag[i]));
|
|
|
|
}
|
2015-05-13 14:40:46 +00:00
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
ASSERT_LE(0, elapsed_seconds.count() * 1e6);
|
2014-03-28 17:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(ComplexCarrierTest, C11ComplexImplementation)
|
2014-03-29 19:11:32 +00:00
|
|
|
{
|
|
|
|
// declaration: load data onto the program data segment
|
|
|
|
std::vector<std::complex<float>> output(FLAGS_size_carrier_test);
|
2017-08-18 10:45:47 +00:00
|
|
|
const double _f = 2000.0;
|
|
|
|
const double _fs = 2000000.0;
|
2019-02-11 14:33:24 +00:00
|
|
|
const auto phase_step = static_cast<double>((GPS_TWO_PI * _f) / _fs);
|
2017-08-18 10:45:47 +00:00
|
|
|
double phase = 0.0;
|
2014-03-29 19:11:32 +00:00
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
|
|
|
|
2014-03-29 19:11:32 +00:00
|
|
|
for (int i = 0; i < FLAGS_size_carrier_test; i++)
|
|
|
|
{
|
|
|
|
output[i] = std::complex<float>(cos(phase), sin(phase));
|
|
|
|
phase += phase_step;
|
|
|
|
}
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
2014-03-29 19:11:32 +00:00
|
|
|
std::cout << "A " << FLAGS_size_carrier_test
|
2017-08-11 03:18:38 +00:00
|
|
|
<< "-length complex carrier in standard C++ (declaration) generated in " << elapsed_seconds.count() * 1e6
|
2014-03-29 19:11:32 +00:00
|
|
|
<< " microseconds" << std::endl;
|
2017-08-11 03:18:38 +00:00
|
|
|
ASSERT_LE(0, elapsed_seconds.count() * 1e6);
|
2018-03-03 01:03:39 +00:00
|
|
|
std::complex<float> expected(1, 0);
|
2014-03-29 19:11:32 +00:00
|
|
|
std::vector<std::complex<float>> mag(FLAGS_size_carrier_test);
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < FLAGS_size_carrier_test; i++)
|
2014-03-29 19:11:32 +00:00
|
|
|
{
|
|
|
|
mag[i] = output[i] * std::conj(output[i]);
|
|
|
|
ASSERT_FLOAT_EQ(std::norm(expected), std::norm(mag[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(ComplexCarrierTest, OwnComplexImplementation)
|
2014-03-28 17:52:51 +00:00
|
|
|
{
|
2019-02-11 14:33:24 +00:00
|
|
|
auto* output = new std::complex<float>[FLAGS_size_carrier_test];
|
2017-08-18 10:45:47 +00:00
|
|
|
double _f = 2000.0;
|
|
|
|
double _fs = 2000000.0;
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2014-03-28 17:52:51 +00:00
|
|
|
|
2019-06-28 23:28:30 +00:00
|
|
|
complex_exp_gen(gsl::span<std::complex<float>>(output, static_cast<unsigned int>(FLAGS_size_carrier_test)), _f, _fs);
|
2014-03-28 17:52:51 +00:00
|
|
|
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
2014-03-28 17:52:51 +00:00
|
|
|
std::cout << "A " << FLAGS_size_carrier_test
|
2017-08-11 03:18:38 +00:00
|
|
|
<< "-length complex carrier using fixed point generated in " << elapsed_seconds.count() * 1e6
|
2014-03-28 17:52:51 +00:00
|
|
|
<< " microseconds" << std::endl;
|
2015-05-13 14:40:46 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
std::complex<float> expected(1, 0);
|
2014-03-29 19:11:32 +00:00
|
|
|
std::vector<std::complex<float>> mag(FLAGS_size_carrier_test);
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < FLAGS_size_carrier_test; i++)
|
2014-03-29 19:11:32 +00:00
|
|
|
{
|
|
|
|
mag[i] = output[i] * std::conj(output[i]);
|
2015-05-13 14:40:46 +00:00
|
|
|
}
|
|
|
|
delete[] output;
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int i = 0; i < FLAGS_size_carrier_test; i++)
|
2015-05-13 14:40:46 +00:00
|
|
|
{
|
2014-03-29 19:11:32 +00:00
|
|
|
ASSERT_NEAR(std::norm(expected), std::norm(mag[i]), 0.0001);
|
|
|
|
}
|
2017-08-11 03:18:38 +00:00
|
|
|
ASSERT_LE(0, elapsed_seconds.count() * 1e6);
|
2014-03-28 17:52:51 +00:00
|
|
|
}
|