1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-27 17:34:53 +00:00

Adding fir_filter tests for different data types

This commit is contained in:
Carles Fernandez 2015-02-06 01:09:53 +01:00
parent 6b258c68ac
commit 88789b0717
2 changed files with 213 additions and 9 deletions

View File

@ -125,6 +125,8 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-rrlp
${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-supl
${CMAKE_SOURCE_DIR}/src/algorithms/libs
${CMAKE_SOURCE_DIR}/src/algorithms/data_type_adapter/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/data_type_adapter/gnuradio_blocks
${CMAKE_SOURCE_DIR}/src/algorithms/resampler/gnuradio_blocks
${CMAKE_SOURCE_DIR}/src/algorithms/channel/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/channel/libs

View File

@ -28,12 +28,15 @@
* -------------------------------------------------------------------------
*/
#include <complex>
#include <ctime>
#include <iostream>
#include <stdint.h>
#include <gflags/gflags.h>
#include <gnuradio/top_block.h>
#include <gnuradio/analog/sig_source_waveform.h>
#include <gnuradio/analog/sig_source_c.h>
#include <gnuradio/analog/sig_source_i.h>
#include <gnuradio/msg_queue.h>
#include <gnuradio/blocks/null_sink.h>
#include <gtest/gtest.h>
@ -41,8 +44,11 @@
#include "gnss_block_interface.h"
#include "in_memory_configuration.h"
#include "gnss_sdr_valve.h"
#include "interleaved_byte_to_complex_byte.h"
#include "interleaved_short_to_complex_short.h"
#include "fir_filter.h"
DEFINE_string(filter_test_output_filename, std::string(TEST_PATH) + "data/fir_filter_test_output.dat", "Dump filename");
class Fir_Filter_Test: public ::testing::Test
@ -51,24 +57,27 @@ protected:
Fir_Filter_Test()
{
queue = gr::msg_queue::make(0);
top_block = gr::make_top_block("Fir filter test");
config = std::make_shared<InMemoryConfiguration>();
item_size = sizeof(gr_complex);
}
~Fir_Filter_Test()
{}
void init();
void configure_cbyte_cbyte();
void configure_cbyte_gr_complex();
void configure_gr_complex_gr_complex();
void configure_cshort_cshort();
boost::shared_ptr<gr::msg_queue> queue;
gr::top_block_sptr top_block;
std::shared_ptr<InMemoryConfiguration> config;
size_t item_size;
int nsamples = 10000000;
};
void Fir_Filter_Test::init()
{
config->set_property("InputFilter.number_of_taps", "4");
config->set_property("InputFilter.taps_item_type", "float");
config->set_property("InputFilter.number_of_taps", "5");
config->set_property("InputFilter.number_of_bands", "2");
config->set_property("InputFilter.band1_begin", "0.0");
@ -89,29 +98,83 @@ void Fir_Filter_Test::init()
//config->set_property("InputFilter.dump", "true");
}
void Fir_Filter_Test::configure_cbyte_cbyte()
{
config->set_property("InputFilter.input_item_type", "cbyte");
config->set_property("InputFilter.output_item_type", "cbyte");
}
TEST_F(Fir_Filter_Test, Instantiate)
void Fir_Filter_Test::configure_gr_complex_gr_complex()
{
config->set_property("InputFilter.input_item_type", "gr_complex");
config->set_property("InputFilter.output_item_type", "gr_complex");
}
void Fir_Filter_Test::configure_cshort_cshort()
{
config->set_property("InputFilter.input_item_type", "cshort");
config->set_property("InputFilter.output_item_type", "cshort");
}
void Fir_Filter_Test::configure_cbyte_gr_complex()
{
config->set_property("InputFilter.input_item_type", "cbyte");
config->set_property("InputFilter.output_item_type", "gr_complex");
}
TEST_F(Fir_Filter_Test, Instantiate_gr_complex_gr_complex)
{
init();
configure_gr_complex_gr_complex();
std::unique_ptr<FirFilter> filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue));
int res = 0;
if (filter) res = 1;
ASSERT_EQ(1, res);
}
TEST_F(Fir_Filter_Test, Instantiate_cshort_cshort)
{
init();
configure_cshort_cshort();
std::unique_ptr<FirFilter> filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue));
int res = 0;
if (filter) res = 1;
ASSERT_EQ(1, res);
}
TEST_F(Fir_Filter_Test, Instantiate_cbyte_cbyte)
{
init();
configure_cbyte_cbyte();
std::unique_ptr<FirFilter> filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue));
int res = 0;
if (filter) res = 1;
ASSERT_EQ(1, res);
}
TEST_F(Fir_Filter_Test, Instantiate_cbyte_gr_complex)
{
init();
configure_cbyte_gr_complex();
std::unique_ptr<FirFilter> filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue));
int res = 0;
if (filter) res = 1;
ASSERT_EQ(1, res);
}
TEST_F(Fir_Filter_Test, ConnectAndRun)
{
int fs_in = 8000000;
int nsamples = 10000000;
int fs_in = 4000000;
struct timeval tv;
long long int begin = 0;
long long int end = 0;
top_block = gr::make_top_block("Fir filter test");
init();
configure_gr_complex_gr_complex();
std::shared_ptr<FirFilter> filter = std::make_shared<FirFilter>(config.get(), "InputFilter", 1, 1, queue);
item_size = sizeof(gr_complex);
ASSERT_NO_THROW( {
filter->connect(top_block);
boost::shared_ptr<gr::block> source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0));
@ -132,3 +195,142 @@ TEST_F(Fir_Filter_Test, ConnectAndRun)
}) << "Failure running the top_block." << std::endl;
std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl;
}
TEST_F(Fir_Filter_Test, ConnectAndRunCshorts)
{
struct timeval tv;
long long int begin = 0;
long long int end = 0;
top_block = gr::make_top_block("Fir filter test");
init();
configure_cshort_cshort();
std::shared_ptr<FirFilter> filter = std::make_shared<FirFilter>(config.get(), "InputFilter", 1, 1, queue);
std::shared_ptr<InMemoryConfiguration> config2 = std::make_shared<InMemoryConfiguration>();
config2->set_property("Test_Source.samples", "1000000");
config2->set_property("Test_Source.sampling_frequency", "4000000");
std::string path = std::string(TEST_PATH);
std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
config2->set_property("Test_Source.filename", filename);
config2->set_property("Test_Source.item_type", "ishort");
config2->set_property("Test_Source.repeat", "true");
item_size = sizeof(std::complex<int16_t>);
ASSERT_NO_THROW( {
filter->connect(top_block);
boost::shared_ptr<FileSignalSource> source(new FileSignalSource(config2.get(), "Test_Source", 1, 1, queue));
source->connect(top_block);
interleaved_short_to_complex_short_sptr ishort_to_cshort_ = make_interleaved_short_to_complex_short();
boost::shared_ptr<gr::block> null_sink = gr::blocks::null_sink::make(item_size);
top_block->connect(source->get_right_block(), 0, ishort_to_cshort_, 0);
top_block->connect(ishort_to_cshort_, 0, filter->get_left_block(), 0);
top_block->connect(filter->get_right_block(), 0, null_sink, 0);
}) << "Failure connecting the top_block."<< std::endl;
EXPECT_NO_THROW( {
gettimeofday(&tv, NULL);
begin = tv.tv_sec *1000000 + tv.tv_usec;
top_block->run(); // Start threads and wait
gettimeofday(&tv, NULL);
end = tv.tv_sec *1000000 + tv.tv_usec;
}) << "Failure running the top_block." << std::endl;
std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl;
}
TEST_F(Fir_Filter_Test, ConnectAndRunCbytes)
{
struct timeval tv;
long long int begin = 0;
long long int end = 0;
top_block = gr::make_top_block("Fir filter test");
init();
configure_cbyte_cbyte();
std::shared_ptr<FirFilter> filter = std::make_shared<FirFilter>(config.get(), "InputFilter", 1, 1, queue);
std::shared_ptr<InMemoryConfiguration> config2 = std::make_shared<InMemoryConfiguration>();
config2->set_property("Test_Source.samples", "1000000");
config2->set_property("Test_Source.sampling_frequency", "4000000");
std::string path = std::string(TEST_PATH);
std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
config2->set_property("Test_Source.filename", filename);
config2->set_property("Test_Source.item_type", "ibyte");
config2->set_property("Test_Source.repeat", "true");
item_size = sizeof(std::complex<int8_t>);
ASSERT_NO_THROW( {
filter->connect(top_block);
boost::shared_ptr<FileSignalSource> source(new FileSignalSource(config2.get(), "Test_Source", 1, 1, queue));
source->connect(top_block);
interleaved_byte_to_complex_byte_sptr ibyte_to_cbyte_ = make_interleaved_byte_to_complex_byte();
boost::shared_ptr<gr::block> null_sink = gr::blocks::null_sink::make(item_size);
top_block->connect(source->get_right_block(), 0, ibyte_to_cbyte_, 0);
top_block->connect(ibyte_to_cbyte_, 0, filter->get_left_block(), 0);
top_block->connect(filter->get_right_block(), 0, null_sink, 0);
}) << "Failure connecting the top_block."<< std::endl;
EXPECT_NO_THROW( {
gettimeofday(&tv, NULL);
begin = tv.tv_sec *1000000 + tv.tv_usec;
top_block->run(); // Start threads and wait
gettimeofday(&tv, NULL);
end = tv.tv_sec *1000000 + tv.tv_usec;
}) << "Failure running the top_block." << std::endl;
std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl;
}
TEST_F(Fir_Filter_Test, ConnectAndRunCbyteGrcomplex)
{
struct timeval tv;
long long int begin = 0;
long long int end = 0;
top_block = gr::make_top_block("Fir filter test");
init();
configure_cbyte_gr_complex();
std::shared_ptr<FirFilter> filter = std::make_shared<FirFilter>(config.get(), "InputFilter", 1, 1, queue);
std::shared_ptr<InMemoryConfiguration> config2 = std::make_shared<InMemoryConfiguration>();
config2->set_property("Test_Source.samples", "1000000");
config2->set_property("Test_Source.sampling_frequency", "4000000");
std::string path = std::string(TEST_PATH);
std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
config2->set_property("Test_Source.filename", filename);
config2->set_property("Test_Source.item_type", "ibyte");
config2->set_property("Test_Source.repeat", "true");
item_size = sizeof(gr_complex);
ASSERT_NO_THROW( {
filter->connect(top_block);
boost::shared_ptr<FileSignalSource> source(new FileSignalSource(config2.get(), "Test_Source", 1, 1, queue));
source->connect(top_block);
interleaved_byte_to_complex_byte_sptr ibyte_to_cbyte_ = make_interleaved_byte_to_complex_byte();
boost::shared_ptr<gr::block> null_sink = gr::blocks::null_sink::make(item_size);
top_block->connect(source->get_right_block(), 0, ibyte_to_cbyte_, 0);
top_block->connect(ibyte_to_cbyte_, 0, filter->get_left_block(), 0);
top_block->connect(filter->get_right_block(), 0, null_sink, 0);
}) << "Failure connecting the top_block."<< std::endl;
EXPECT_NO_THROW( {
gettimeofday(&tv, NULL);
begin = tv.tv_sec *1000000 + tv.tv_usec;
top_block->run(); // Start threads and wait
gettimeofday(&tv, NULL);
end = tv.tv_sec *1000000 + tv.tv_usec;
}) << "Failure running the top_block." << std::endl;
std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl;
}