1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 20:50:33 +00:00

Add work on acq performance test

This commit is contained in:
Carles Fernandez 2018-06-26 08:43:22 +02:00
parent 60f9df7cd1
commit bc0b267acc
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D

View File

@ -34,6 +34,9 @@
#include "tracking_true_obs_reader.h" #include "tracking_true_obs_reader.h"
#include "true_observables_reader.h" #include "true_observables_reader.h"
#include "display.h" #include "display.h"
#include <boost/filesystem/operations.hpp> // for create_directories, exists
//#include <boost/filesystem/path.hpp> // for path, operator<<
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <gnuradio/top_block.h> #include <gnuradio/top_block.h>
#include <glog/logging.h> #include <glog/logging.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -118,20 +121,24 @@ protected:
stop = false; stop = false;
acquisition = 0; acquisition = 0;
init(); init();
Pd.resize(cn0_.size());
for (int i = 0; i < cn0_.size(); i++) Pd[i].reserve(num_thresholds);
Pfa.resize(cn0_.size());
for (int i = 0; i < cn0_.size(); i++) Pfa[i].reserve(num_thresholds);
} }
~AcquisitionPerformanceTest() ~AcquisitionPerformanceTest()
{ {
} }
std::vector<double> cn0_ = {38.0, 40.0, 43.0}; std::vector<double> cn0_ = {35.0, 38.0, 43.0};
int N_iterations = 1; int N_iterations = 1;
void init(); void init();
//void plot_grid(); //void plot_grid();
int configure_generator(double cn0); int configure_generator(double cn0);
int generate_signal(); int generate_signal();
int configure_receiver(double cn0, unsigned int iter); int configure_receiver(double cn0, float pfa, unsigned int iter);
void start_queue(); void start_queue();
void wait_message(); void wait_message();
void process_message(); void process_message();
@ -173,6 +180,16 @@ protected:
unsigned int realization_counter; unsigned int realization_counter;
unsigned int observed_satellite = FLAGS_acq_test_PRN; unsigned int observed_satellite = FLAGS_acq_test_PRN;
std::string path_str = "./acq-perf-test";
//std::vector<std::vector<double>> meas_Pd;
//std::vector<std::vector<float>> meas_Pd_correct;
//std::vector<std::vector<float>> meas_Pfa;
int num_thresholds = 1;
std::vector<std::vector<float>> Pd;
std::vector<std::vector<float>> Pfa;
private: private:
std::string generator_binary; std::string generator_binary;
@ -293,7 +310,7 @@ int AcquisitionPerformanceTest::generate_signal()
} }
int AcquisitionPerformanceTest::configure_receiver(double cn0, unsigned int iter) int AcquisitionPerformanceTest::configure_receiver(double cn0, float pfa, unsigned int iter)
{ {
if (FLAGS_config_file_ptest.empty()) if (FLAGS_config_file_ptest.empty())
{ {
@ -392,7 +409,7 @@ int AcquisitionPerformanceTest::configure_receiver(double cn0, unsigned int iter
config->set_property("Acquisition_1C.doppler_step", std::to_string(doppler_step)); config->set_property("Acquisition_1C.doppler_step", std::to_string(doppler_step));
config->set_property("Acquisition_1C.threshold", std::to_string(threshold)); config->set_property("Acquisition_1C.threshold", std::to_string(threshold));
if (FLAGS_acq_test_pfa > 0.0) config->set_property("Acquisition_1C.pfa", std::to_string(FLAGS_acq_test_pfa)); if (FLAGS_acq_test_pfa > 0.0) config->force_set_property("Acquisition_1C.pfa", std::to_string(pfa));
config->set_property("Acquisition_1C.use_CFAR_algorithm", "true"); config->set_property("Acquisition_1C.use_CFAR_algorithm", "true");
@ -416,7 +433,7 @@ int AcquisitionPerformanceTest::configure_receiver(double cn0, unsigned int iter
config->set_property("Acquisition_1C.second_doppler_step", std::to_string(125)); config->set_property("Acquisition_1C.second_doppler_step", std::to_string(125));
config->set_property("Acquisition_1C.dump", "true"); config->set_property("Acquisition_1C.dump", "true");
std::string dump_file = std::string("./acquisition_") + std::to_string(cn0) + "_" + std::to_string(iter); std::string dump_file = path_str + std::string("/acquisition_") + std::to_string(cn0) + "_" + std::to_string(iter) + "_" + std::to_string(pfa);
config->set_property("Acquisition_1C.dump_filename", dump_file); config->set_property("Acquisition_1C.dump_filename", dump_file);
config->set_property("Acquisition_1C.dump_channel", std::to_string(dump_channel)); config->set_property("Acquisition_1C.dump_channel", std::to_string(dump_channel));
@ -477,8 +494,6 @@ int AcquisitionPerformanceTest::configure_receiver(double cn0, unsigned int iter
int AcquisitionPerformanceTest::run_receiver() int AcquisitionPerformanceTest::run_receiver()
{ {
std::chrono::time_point<std::chrono::system_clock> start, end;
std::chrono::duration<double> elapsed_seconds(0);
std::string file = "./" + filename_raw_data; std::string file = "./" + filename_raw_data;
const char* file_name = file.c_str(); const char* file_name = file.c_str();
gr::blocks::file_source::sptr file_source = gr::blocks::file_source::make(sizeof(int8_t), file_name, false); gr::blocks::file_source::sptr file_source = gr::blocks::file_source::make(sizeof(int8_t), file_name, false);
@ -514,10 +529,7 @@ int AcquisitionPerformanceTest::run_receiver()
start_queue(); start_queue();
start = std::chrono::system_clock::now();
top_block->run(); // Start threads and wait top_block->run(); // Start threads and wait
end = std::chrono::system_clock::now();
elapsed_seconds = end - start;
#ifdef OLD_BOOST #ifdef OLD_BOOST
ch_thread.timed_join(boost::posix_time::seconds(1)); ch_thread.timed_join(boost::posix_time::seconds(1));
@ -526,8 +538,6 @@ int AcquisitionPerformanceTest::run_receiver()
ch_thread.try_join_until(boost::chrono::steady_clock::now() + boost::chrono::milliseconds(50)); ch_thread.try_join_until(boost::chrono::steady_clock::now() + boost::chrono::milliseconds(50));
#endif #endif
//std::cout << "Processed " << nsamples << " samples in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl;
return 0; return 0;
} }
@ -587,12 +597,33 @@ int AcquisitionPerformanceTest::count_executions(const std::string& basename, un
TEST_F(AcquisitionPerformanceTest, PdvsCn0) TEST_F(AcquisitionPerformanceTest, PdvsCn0)
{ {
tracking_true_obs_reader true_trk_data; tracking_true_obs_reader true_trk_data;
if (boost::filesystem::exists(path_str))
{
boost::filesystem::remove_all(path_str);
}
boost::system::error_code ec;
if (!boost::filesystem::create_directory(path_str, ec))
{
std::cout << "Could not create the " << path_str << " folder." << std::endl;
// error
}
unsigned int cn0_index = 0;
for (std::vector<double>::const_iterator it = cn0_.cbegin(); it != cn0_.cend(); ++it) for (std::vector<double>::const_iterator it = cn0_.cbegin(); it != cn0_.cend(); ++it)
{ {
// Do N_iterations of the experiment // Do N_iterations of the experiment
std::vector<float> pfa_local = {0.01}; //{FLAGS_acq_test_pfa}; //{0.001, 0.01, 0.1, 1};
std::vector<double> meas_Pd_;
std::vector<double> meas_Pd_correct_;
std::vector<double> meas_Pfa_;
for (unsigned iter = 0; iter < N_iterations; iter++) for (unsigned iter = 0; iter < N_iterations; iter++)
{ {
std::string basename = std::string("./acquisition_") + std::to_string(*it) + "_" + std::to_string(iter) + "_" + gnss_synchro.System + "_1C"; // Set parameter to sweep
for (int pfa_iter = 0; pfa_iter < pfa_local.size(); pfa_iter++)
{
std::string basename = path_str + std::string("/acquisition_") + std::to_string(*it) + "_" + std::to_string(iter) + "_" + std::to_string(pfa_local[pfa_iter]) + "_" + gnss_synchro.System + "_1C";
// Configure the signal generator // Configure the signal generator
configure_generator(*it); configure_generator(*it);
@ -614,7 +645,7 @@ TEST_F(AcquisitionPerformanceTest, PdvsCn0)
init(); init();
// Configure the receiver // Configure the receiver
configure_receiver(*it, iter); configure_receiver(*it, pfa_local[pfa_iter], iter);
// Run it // Run it
run_receiver(); run_receiver();
@ -685,6 +716,8 @@ TEST_F(AcquisitionPerformanceTest, PdvsCn0)
// Process results // Process results
arma::vec clean_doppler_estimation_error; arma::vec clean_doppler_estimation_error;
arma::vec clean_delay_estimation_error; arma::vec clean_delay_estimation_error;
std::vector<double> meas_Pd_;
std::vector<double> meas_Pd_correct_;
if (epoch_counter > 2) if (epoch_counter > 2)
{ {
arma::vec true_interpolated_doppler = arma::zeros(num_executions, 1); arma::vec true_interpolated_doppler = arma::zeros(num_executions, 1);
@ -729,8 +762,11 @@ TEST_F(AcquisitionPerformanceTest, PdvsCn0)
std::cout << delay_estimation_error(i) << " "; std::cout << delay_estimation_error(i) << " ";
} }
std::cout << std::endl; std::cout << std::endl;
}
if (k == 0)
{
double detected = arma::accu(positive_acq); double detected = arma::accu(positive_acq);
if (num_executions > 0) meas_Pd_.push_back(static_cast<double>(detected / num_executions));
std::cout << TEXT_BOLD_BLACK << "Probability of detection for channel=" << ch << ", CN0=" << *it << " dBHz" std::cout << TEXT_BOLD_BLACK << "Probability of detection for channel=" << ch << ", CN0=" << *it << " dBHz"
<< ": " << (num_executions > 0 ? (detected / num_executions) : 0.0) << TEXT_RESET << std::endl; << ": " << (num_executions > 0 ? (detected / num_executions) : 0.0) << TEXT_RESET << std::endl;
} }
@ -751,16 +787,39 @@ TEST_F(AcquisitionPerformanceTest, PdvsCn0)
} }
else else
{ {
std::cout << "No reference data has been found. Maybe a non-present satellite?" << std::endl; // std::cout << "No reference data has been found. Maybe a non-present satellite?" << std::endl;
if (k == 1)
{
double wrongly_detected = arma::accu(positive_acq); double wrongly_detected = arma::accu(positive_acq);
std::cout << TEXT_BOLD_BLACK << "Probability of false alarm for channel=" << ch << ", CN0=" << *it << " dBHz" if (num_executions > 0) meas_Pfa_.push_back(static_cast<double>(wrongly_detected / num_executions));
std::cout
<< TEXT_BOLD_BLACK << "Probability of false alarm for channel=" << ch << ", CN0=" << *it << " dBHz"
<< ": " << (num_executions > 0 ? (wrongly_detected / num_executions) : 0.0) << TEXT_RESET << std::endl; << ": " << (num_executions > 0 ? (wrongly_detected / num_executions) : 0.0) << TEXT_RESET << std::endl;
} }
}
true_trk_data.restart(); true_trk_data.restart();
} }
float sum_ = static_cast<float>(std::accumulate(meas_Pd_.begin(), meas_Pd_.end(), 0.0));
Pd[cn0_index][pfa_iter] = sum_ / static_cast<float>(meas_Pd_.size());
sum_ = static_cast<float>(std::accumulate(meas_Pfa_.begin(), meas_Pfa_.end(), 0.0));
Pfa[cn0_index][pfa_iter] = sum_ / static_cast<float>(meas_Pfa_.size());
cn0_index++;
}
} }
true_trk_data.close_obs_file(); true_trk_data.close_obs_file();
// Compute results // Compute results
} }
unsigned int aux_index = 0;
for (std::vector<double>::const_iterator it = cn0_.cbegin(); it != cn0_.cend(); ++it)
{
std::cout << "Results for CN0 = " << *it << " dBHz:" << std::endl;
std::cout << "Pd = ";
for (int pfa_iter = 0; pfa_iter < 1; pfa_iter++)
{
std::cout << Pd[aux_index][pfa_iter] << " ";
}
std::cout << std::endl;
aux_index++;
}
} }