2014-03-28 17:52:51 +00:00
|
|
|
/*!
|
|
|
|
* \file magnitude_squared_test.cc
|
|
|
|
* \brief This file implements tests for the computation of magnitude squared
|
|
|
|
* in long arrays.
|
|
|
|
* \author Carles Fernandez-Prades, 2014. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2015-01-08 18:49:59 +00:00
|
|
|
* Copyright (C) 2010-2015 (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
|
|
|
|
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <complex>
|
|
|
|
#include <ctime>
|
|
|
|
#include <armadillo>
|
|
|
|
#include <volk/volk.h>
|
|
|
|
|
|
|
|
DEFINE_int32(size_magnitude_test, 100000, "Size of the arrays used for magnitude testing");
|
|
|
|
|
|
|
|
|
|
|
|
TEST(MagnitudeSquared_Test, StandardCComplexImplementation)
|
|
|
|
{
|
|
|
|
std::complex<float>* input = new std::complex<float>[FLAGS_size_magnitude_test];
|
|
|
|
float* output = new float[FLAGS_size_magnitude_test];
|
|
|
|
unsigned int number = 0;
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
|
|
|
|
for(number = 0; number < (unsigned int)FLAGS_size_magnitude_test; number++)
|
|
|
|
{
|
2014-04-23 10:31:10 +00:00
|
|
|
output[number] = (input[number].real()*input[number].real()) + (input[number].imag()*input[number].imag());
|
2014-03-28 17:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
|
2014-03-29 19:11:32 +00:00
|
|
|
std::cout << "The squared magnitude of a " << FLAGS_size_magnitude_test
|
|
|
|
<< "-length vector in standard C computed in " << (end - begin)
|
2014-03-28 17:52:51 +00:00
|
|
|
<< " microseconds" << std::endl;
|
|
|
|
ASSERT_LE(0, end - begin);
|
2014-03-29 21:53:56 +00:00
|
|
|
delete [] input;
|
|
|
|
delete [] output;
|
2014-03-28 17:52:51 +00:00
|
|
|
}
|
|
|
|
|
2014-03-29 19:11:32 +00:00
|
|
|
TEST(MagnitudeSquared_Test, C11ComplexImplementation)
|
|
|
|
{
|
|
|
|
const std::vector<std::complex<float>> input(FLAGS_size_magnitude_test);
|
|
|
|
std::vector<std::complex<float>> output(FLAGS_size_magnitude_test);
|
|
|
|
struct timeval tv;
|
2014-03-29 21:53:56 +00:00
|
|
|
int pos = 0;
|
2014-03-29 19:11:32 +00:00
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
|
2014-03-29 21:53:56 +00:00
|
|
|
|
2014-03-29 19:11:32 +00:00
|
|
|
for (const auto &item : input)
|
|
|
|
{
|
2014-03-29 21:53:56 +00:00
|
|
|
output[pos++] = std::norm(item);
|
2014-03-29 19:11:32 +00:00
|
|
|
}
|
2014-03-29 21:53:56 +00:00
|
|
|
|
2014-03-29 19:11:32 +00:00
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
std::cout << "The squared magnitude of a " << FLAGS_size_magnitude_test
|
|
|
|
<< " complex<float> vector (C++11-style) finished in " << (end - begin)
|
|
|
|
<< " microseconds" << std::endl;
|
|
|
|
ASSERT_LE(0, end - begin);
|
|
|
|
|
|
|
|
std::complex<float> expected(0,0);
|
|
|
|
std::complex<float> result(0,0);
|
|
|
|
for (const auto &item : output)
|
|
|
|
{
|
|
|
|
result += item;
|
|
|
|
}
|
|
|
|
ASSERT_EQ(expected, result);
|
|
|
|
}
|
2014-03-28 17:52:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(MagnitudeSquared_Test, ArmadilloComplexImplementation)
|
|
|
|
{
|
|
|
|
arma::cx_fvec input(FLAGS_size_magnitude_test, arma::fill::zeros);
|
|
|
|
arma::fvec output(FLAGS_size_magnitude_test);
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
|
|
|
|
output = arma::abs(arma::square(input));
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
std::cout << "The squared magnitude of a " << FLAGS_size_magnitude_test
|
|
|
|
<< "-length vector using Armadillo computed in " << (end - begin)
|
|
|
|
<< " microseconds" << std::endl;
|
|
|
|
ASSERT_LE(0, end - begin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(MagnitudeSquared_Test, VolkComplexImplementation)
|
|
|
|
{
|
2014-09-12 11:34:43 +00:00
|
|
|
std::complex<float>* input = static_cast<std::complex<float>*>(volk_malloc(FLAGS_size_magnitude_test * sizeof(std::complex<float>), volk_get_alignment()));
|
2014-03-28 17:52:51 +00:00
|
|
|
memset(input, 0, sizeof(std::complex<float>) * FLAGS_size_magnitude_test);
|
2014-09-12 11:34:43 +00:00
|
|
|
float* output = static_cast<float*>(volk_malloc(FLAGS_size_magnitude_test * sizeof(float), volk_get_alignment()));
|
2014-03-28 17:52:51 +00:00
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
|
2014-09-12 11:34:43 +00:00
|
|
|
volk_32fc_magnitude_squared_32f(output, input, static_cast<unsigned int>(FLAGS_size_magnitude_test));
|
2014-03-28 17:52:51 +00:00
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
|
|
|
|
std::cout << "The squared magnitude of a " << FLAGS_size_magnitude_test
|
|
|
|
<< "-length vector using VOLK computed in " << (end - begin)
|
|
|
|
<< " microseconds" << std::endl;
|
|
|
|
ASSERT_LE(0, end - begin);
|
2014-09-09 20:51:47 +00:00
|
|
|
volk_free(input);
|
|
|
|
volk_free(output);
|
2014-03-28 17:52:51 +00:00
|
|
|
}
|
|
|
|
|
2014-03-29 19:11:32 +00:00
|
|
|
// volk_32f_accumulator_s32f(&d_input_power, d_magnitude, d_fft_size);
|
2014-03-28 17:52:51 +00:00
|
|
|
|