From d1ed8a963c4e982e0d09b2583db92111da40a68d Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 23 Oct 2017 19:25:41 +0200 Subject: [PATCH 1/5] Add plot of correlators\' output --- .../gps_l1_ca_dll_pll_tracking_test.cc | 78 ++++++++++++++++--- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc index 894afe228..14678be4a 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc @@ -30,10 +30,12 @@ * ------------------------------------------------------------------------- */ - +#include #include #include +#include #include +#include #include #include #include @@ -53,6 +55,10 @@ #include "tracking_true_obs_reader.h" #include "tracking_dump_reader.h" #include "signal_generator_flags.h" +#include "gnuplot_i.h" +#include "test_flags.h" + +DEFINE_bool(plot_gps_l1_tracking_test, false, "Plots results of GpsL1CADllPllTrackingTest with gnuplot"); // ######## GNURADIO BLOCK MESSAGE RECEVER ######### @@ -358,9 +364,7 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) generate_signal(); } - struct timeval tv; - long long int begin = 0; - long long int end = 0; + std::chrono::time_point start, end; configure_receiver(); @@ -427,11 +431,9 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) tracking->start_tracking(); EXPECT_NO_THROW( { - gettimeofday(&tv, NULL); - begin = tv.tv_sec * 1000000 + tv.tv_usec; + start = std::chrono::system_clock::now(); top_block->run(); // Start threads and wait - gettimeofday(&tv, NULL); - end = tv.tv_sec * 1000000 + tv.tv_usec; + end = std::chrono::system_clock::now(); }) << "Failure running the top_block." << std::endl; //check results @@ -461,7 +463,7 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) ASSERT_NO_THROW({ if (trk_dump.open_obs_file(std::string("./tracking_ch_0.dat")) == false) { - + throw std::exception(); }; }) << "Failure opening tracking dump file" << std::endl; @@ -473,7 +475,11 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) arma::vec trk_acc_carrier_phase_cycles = arma::zeros(nepoch, 1); arma::vec trk_Doppler_Hz = arma::zeros(nepoch, 1); arma::vec trk_prn_delay_chips = arma::zeros(nepoch, 1); - + + std::vector prompt; + std::vector early; + std::vector late; + epoch_counter = 0; while(trk_dump.read_binary_obs()) { @@ -486,6 +492,9 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) trk_prn_delay_chips(epoch_counter) = delay_chips; epoch_counter++; + prompt.push_back(trk_dump.abs_P); + early.push_back(trk_dump.abs_E); + late.push_back(trk_dump.abs_L); } //Align initial measurements and cut the tracking pull-in transitory @@ -501,6 +510,51 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) check_results_codephase(true_timestamp_s, true_prn_delay_chips, trk_timestamp_s, trk_prn_delay_chips); check_results_acc_carrier_phase(true_timestamp_s, true_acc_carrier_phase_cycles, trk_timestamp_s, trk_acc_carrier_phase_cycles); - std::cout << "Signal tracking completed in " << (end - begin) << " microseconds" << std::endl; -} + std::chrono::duration elapsed_seconds = end - start; + std::cout << "Signal tracking completed in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; + if(FLAGS_plot_gps_l1_tracking_test == true) + { + const std::string gnuplot_executable(FLAGS_gnuplot_executable); + if(gnuplot_executable.empty()) + { + std::cout << "WARNING: Although the flag plot_gps_l1_tracking_test has been set to TRUE," << std::endl; + std::cout << "gnuplot has not been found in your system." << std::endl; + std::cout << "Test results will not be plotted." << std::endl; + } + else + { + try + { + boost::filesystem::path p(gnuplot_executable); + boost::filesystem::path dir = p.parent_path(); + std::string gnuplot_path = dir.native(); + Gnuplot::set_GNUPlotPath(gnuplot_path); + + std::vector timevec; + //sample_interval = (1 / baseband_sampling_freq) + double t = 0.0; + for (auto it = prompt.begin(); it != prompt.end(); it++) + { + timevec.push_back(t); + t = t + GPS_L1_CA_CODE_PERIOD; + } + Gnuplot g1("linespoints"); + g1.set_title("GPS L1 C/A signal tracking for satellite " + std::to_string(FLAGS_test_satellite_PRN)); + g1.set_grid(); + g1.set_xlabel("Time [s]"); + g1.set_ylabel("Correlators output"); + g1.plot_xy( timevec, prompt, "Prompt"); + g1.plot_xy( timevec, early, "Early"); + g1.plot_xy( timevec, late, "Late"); + g1.savetops("Correlators_outputs"); + g1.savetopdf("Correlators_outputs", 18); + g1.showonscreen(); // window output + } + catch (GnuplotException ge) + { + std::cout << ge.what() << std::endl; + } + } + } +} From 8509b7254a915ac84aabef4b5a9cd2666a028237 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 24 Oct 2017 08:45:13 +0200 Subject: [PATCH 2/5] Add opaque legend --- .../gps_l1_ca_dll_pll_tracking_test.cc | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc index 14678be4a..a41312e8f 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc @@ -103,7 +103,7 @@ void GpsL1CADllPllTrackingTest_msg_rx::msg_handler_events(pmt::pmt_t msg) GpsL1CADllPllTrackingTest_msg_rx::GpsL1CADllPllTrackingTest_msg_rx() : - gr::block("GpsL1CADllPllTrackingTest_msg_rx", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)) + gr::block("GpsL1CADllPllTrackingTest_msg_rx", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)) { this->message_port_register_in(pmt::mp("events")); this->set_msg_handler(pmt::mp("events"), boost::bind(&GpsL1CADllPllTrackingTest_msg_rx::msg_handler_events, this, _1)); @@ -268,8 +268,8 @@ void GpsL1CADllPllTrackingTest::check_results_doppler(arma::vec & true_time_s, //5. report std::streamsize ss = std::cout.precision(); std::cout << std::setprecision(10) << "TRK Doppler RMSE=" << rmse - << ", mean=" << error_mean - << ", stdev="<< sqrt(error_var) << " (max,min)=" << max_error << "," << min_error << " [Hz]" << std::endl; + << ", mean=" << error_mean + << ", stdev="<< sqrt(error_var) << " (max,min)=" << max_error << "," << min_error << " [Hz]" << std::endl; std::cout.precision (ss); } @@ -526,30 +526,30 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) { try { - boost::filesystem::path p(gnuplot_executable); - boost::filesystem::path dir = p.parent_path(); - std::string gnuplot_path = dir.native(); - Gnuplot::set_GNUPlotPath(gnuplot_path); + boost::filesystem::path p(gnuplot_executable); + boost::filesystem::path dir = p.parent_path(); + std::string gnuplot_path = dir.native(); + Gnuplot::set_GNUPlotPath(gnuplot_path); - std::vector timevec; - //sample_interval = (1 / baseband_sampling_freq) - double t = 0.0; - for (auto it = prompt.begin(); it != prompt.end(); it++) - { - timevec.push_back(t); - t = t + GPS_L1_CA_CODE_PERIOD; - } - Gnuplot g1("linespoints"); - g1.set_title("GPS L1 C/A signal tracking for satellite " + std::to_string(FLAGS_test_satellite_PRN)); - g1.set_grid(); - g1.set_xlabel("Time [s]"); - g1.set_ylabel("Correlators output"); - g1.plot_xy( timevec, prompt, "Prompt"); - g1.plot_xy( timevec, early, "Early"); - g1.plot_xy( timevec, late, "Late"); - g1.savetops("Correlators_outputs"); - g1.savetopdf("Correlators_outputs", 18); - g1.showonscreen(); // window output + std::vector timevec; + double t = 0.0; + for (auto it = prompt.begin(); it != prompt.end(); it++) + { + timevec.push_back(t); + t = t + GPS_L1_CA_CODE_PERIOD; + } + Gnuplot g1("linespoints"); + g1.set_title("GPS L1 C/A signal tracking correlators' output (satellite PRN #" + std::to_string(FLAGS_test_satellite_PRN) + ")"); + g1.set_grid(); + g1.set_xlabel("Time [s]"); + g1.set_ylabel("Correlators' output"); + g1.cmd("set key box opaque"); + g1.plot_xy( timevec, prompt, "Prompt"); + g1.plot_xy( timevec, early, "Early"); + g1.plot_xy( timevec, late, "Late"); + g1.savetops("Correlators_outputs"); + g1.savetopdf("Correlators_outputs", 18); + g1.showonscreen(); // window output } catch (GnuplotException ge) { From ac99ba5b753d57e47c3105e204692efd5a1a3427 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 24 Oct 2017 11:38:37 +0200 Subject: [PATCH 3/5] Fix exception catching --- .../signal-processing-blocks/libs/tracking_dump_reader.cc | 2 +- .../signal-processing-blocks/libs/tracking_true_obs_reader.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/unit-tests/signal-processing-blocks/libs/tracking_dump_reader.cc b/src/tests/unit-tests/signal-processing-blocks/libs/tracking_dump_reader.cc index 9d6e55cdb..368b1ee27 100644 --- a/src/tests/unit-tests/signal-processing-blocks/libs/tracking_dump_reader.cc +++ b/src/tests/unit-tests/signal-processing-blocks/libs/tracking_dump_reader.cc @@ -54,7 +54,7 @@ bool tracking_dump_reader::read_binary_obs() d_dump_file.read(reinterpret_cast(&aux2), sizeof(double)); d_dump_file.read(reinterpret_cast(&PRN), sizeof(unsigned int)); } - catch (const std::exception &e) + catch (const std::ifstream::failure &e) { return false; } diff --git a/src/tests/unit-tests/signal-processing-blocks/libs/tracking_true_obs_reader.cc b/src/tests/unit-tests/signal-processing-blocks/libs/tracking_true_obs_reader.cc index bd5b2a7fa..bc407fc20 100644 --- a/src/tests/unit-tests/signal-processing-blocks/libs/tracking_true_obs_reader.cc +++ b/src/tests/unit-tests/signal-processing-blocks/libs/tracking_true_obs_reader.cc @@ -40,7 +40,7 @@ bool tracking_true_obs_reader::read_binary_obs() d_dump_file.read(reinterpret_cast(&prn_delay_chips), sizeof(double)); d_dump_file.read(reinterpret_cast(&tow), sizeof(double)); } - catch (const std::exception &e) + catch (const std::ifstream::failure &e) { return false; } From 2c3ada26f28b134b675a9e781cc92a990fff9b28 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 24 Oct 2017 14:23:59 +0200 Subject: [PATCH 4/5] Add constellation diagram plot --- src/tests/common-files/gnuplot_i.h | 124 +++++++++--------- src/tests/common-files/test_flags.h | 2 + .../gps_l1_ca_dll_pll_tracking_test.cc | 55 +++++--- 3 files changed, 102 insertions(+), 79 deletions(-) diff --git a/src/tests/common-files/gnuplot_i.h b/src/tests/common-files/gnuplot_i.h index 614dc678e..8d1afe8ab 100644 --- a/src/tests/common-files/gnuplot_i.h +++ b/src/tests/common-files/gnuplot_i.h @@ -51,19 +51,19 @@ #include #include #include -#include +#include #include // for std::ostringstream -#include -#include +#include +#include #include // for getenv() #include // for std::list -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) //defined for 32 and 64-bit environments #include // for _access(), _mktemp() #define GP_MAX_TMP_FILES 27 // 27 temporary files it's Microsoft restriction -#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__) +#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__) //all UNIX-like OSs (Linux, *BSD, MacOSX, Solaris, ...) #include // for access(), mkstemp() #define GP_MAX_TMP_FILES 64 @@ -266,24 +266,24 @@ public: // ---------------------------------------------------------------------- /// \brief unset smooth /// attention: smooth is not set by default - /// + /// /// \param --- - /// + /// /// \return <-- a reference to a gnuplot object // ---------------------------------------------------------------------- - inline Gnuplot& unset_smooth(){ smooth = ""; return *this;}; + inline Gnuplot& unset_smooth(){ smooth = ""; return *this;}; /// scales the size of the points used in plots Gnuplot& set_pointsize(const double pointsize = 1.0); /// turns grid on/off inline Gnuplot& set_grid() {cmd("set grid"); return *this;}; - /// grid is not set by default + /// grid is not set by default inline Gnuplot& unset_grid(){cmd("unset grid"); return *this;}; // ----------------------------------------------- /// set the mulitplot mode - /// + /// /// \param --- /// /// \return <-- reference to the gnuplot object @@ -292,7 +292,7 @@ public: // ----------------------------------------------- /// unsets the mulitplot mode - /// + /// /// \param --- /// /// \return <-- reference to the gnuplot object @@ -320,7 +320,7 @@ public: /// /// \return <-- reference to the gnuplot object // --------------------------------------------------------------------------- - inline Gnuplot& unset_hidden3d(){cmd("unset hidden3d"); return *this;}; + inline Gnuplot& unset_hidden3d(){cmd("unset hidden3d"); return *this;}; /// enables/disables contour drawing for surfaces (for 3d plot) /// base, surface, both @@ -337,7 +337,7 @@ public: // ------------------------------------------------------------ /// enables/disables the display of surfaces (for 3d plot) /// - /// \param --- + /// \param --- /// /// \return <-- reference to the gnuplot object // ------------------------------------------------------------------ @@ -347,7 +347,7 @@ public: /// surface is set by default, /// it disables the display of surfaces (for 3d plot) /// - /// \param --- + /// \param --- /// /// \return <-- reference to the gnuplot object // ------------------------------------------------------------------ @@ -356,25 +356,25 @@ public: /// switches legend on/off /// position: inside/outside, left/center/right, top/center/bottom, nobox/box - Gnuplot& set_legend(const std::string &position = "default"); + Gnuplot& set_legend(const std::string &position = "default"); // ------------------------------------------------------------------ /// \brief Switches legend off /// attention:legend is set by default /// - /// \param --- + /// \param --- /// /// \return <-- reference to the gnuplot object // ------------------------------------------------------------------ inline Gnuplot& unset_legend(){cmd("unset key"); return *this;} - // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- /// \brief sets and clears the title of a gnuplot session /// /// \param title --> the title of the plot [optional, default == ""] /// /// \return <-- reference to the gnuplot object - // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- inline Gnuplot& set_title(const std::string &title = "") { std::string cmdstr; @@ -410,7 +410,7 @@ public: Gnuplot& set_zrange(const double iFrom, const double iTo); /// autoscale axis (set by default) of xaxis - /// + /// /// \param --- /// /// \return <-- reference to the gnuplot object @@ -419,7 +419,7 @@ public: // ----------------------------------------------- /// autoscale axis (set by default) of yaxis - /// + /// /// \param --- /// /// \return <-- reference to the gnuplot object @@ -428,7 +428,7 @@ public: // ----------------------------------------------- /// autoscale axis (set by default) of zaxis - /// + /// /// \param --- /// /// \return <-- reference to the gnuplot object @@ -442,31 +442,31 @@ public: /// turns on/off log scaling for the specified zaxis (logscale is not set by default) Gnuplot& set_zlogscale(const double base = 10); - // ----------------------------------------------- + // ----------------------------------------------- /// turns off log scaling for the x axis - /// + /// /// \param --- /// /// \return <-- reference to the gnuplot object - // ----------------------------------------------- + // ----------------------------------------------- inline Gnuplot& unset_xlogscale(){cmd("unset logscale x"); return *this;}; - // ----------------------------------------------- + // ----------------------------------------------- /// turns off log scaling for the y axis - /// + /// /// \param --- /// /// \return <-- reference to the gnuplot object - // ----------------------------------------------- + // ----------------------------------------------- inline Gnuplot& unset_ylogscale(){cmd("unset logscale y"); return *this;}; - // ----------------------------------------------- + // ----------------------------------------------- /// turns off log scaling for the z axis - /// + /// /// \param --- /// /// \return <-- reference to the gnuplot object - // ----------------------------------------------- + // ----------------------------------------------- inline Gnuplot& unset_zlogscale(){cmd("unset logscale z"); return *this;}; /// set palette range (autoscale by default) @@ -490,10 +490,13 @@ public: Gnuplot& plotfile_xy(const std::string &filename, const unsigned int column_x = 1, const unsigned int column_y = 2, - const std::string &title = ""); + const std::string &title = "", + const unsigned int decimate = 1); /// from data template - Gnuplot& plot_xy(const X& x, const Y& y, const std::string &title = ""); + Gnuplot& plot_xy(const X& x, const Y& y, + const std::string &title = "", + const unsigned int decimate = 1); /// plot x,y pairs with dy errorbars: x y dy /// from file @@ -555,7 +558,7 @@ public: ///\brief replot repeats the last plot or splot command. /// this can be useful for viewing a plot with different set options, /// or when generating the same plot for several devices (showonscreen, savetops) - /// + /// /// \param --- /// /// \return --- @@ -573,12 +576,12 @@ public: // ------------------------------------------------------------------- /// \brief Is the gnuplot session valid ?? - /// + /// /// /// \param --- - /// + /// /// \return true if valid, false if not - // ------------------------------------------------------------------- + // ------------------------------------------------------------------- inline bool is_valid(){return(valid);}; }; @@ -724,7 +727,7 @@ Gnuplot& Gnuplot::plot_x(const X& x, const std::string &title) /// Plots a 2d graph from a list of doubles: x y // template -Gnuplot& Gnuplot::plot_xy(const X& x, const Y& y, const std::string &title) +Gnuplot& Gnuplot::plot_xy(const X& x, const Y& y, const std::string &title, const unsigned int decimate) { if (x.size() == 0 || y.size() == 0) { @@ -752,7 +755,7 @@ Gnuplot& Gnuplot::plot_xy(const X& x, const Y& y, const std::string &title) tmp.flush(); tmp.close(); - plotfile_xy(name, 1, 2, title); + plotfile_xy(name, 1, 2, title, decimate); return *this; } @@ -1483,7 +1486,8 @@ Gnuplot& Gnuplot::plotfile_x(const std::string &filename, Gnuplot& Gnuplot::plotfile_xy(const std::string &filename, const unsigned int column_x, const unsigned int column_y, - const std::string &title) + const std::string &title, + const unsigned int decimate) { // // check if file exists @@ -1499,7 +1503,7 @@ Gnuplot& Gnuplot::plotfile_xy(const std::string &filename, else cmdstr << "plot "; - cmdstr << "\"" << filename << "\" using " << column_x << ":" << column_y; + cmdstr << "\"" << filename << "\" using " << column_x << ":" << column_y << " every " << std::to_string(decimate); if (title == "") cmdstr << " notitle "; @@ -1544,7 +1548,7 @@ Gnuplot& Gnuplot::plotfile_xy_err(const std::string &filename, else cmdstr << "plot "; - cmdstr << "\"" << filename << "\" using " + cmdstr << "\"" << filename << "\" using " << column_x << ":" << column_y << ":" << column_dy << " with errorbars "; @@ -1586,7 +1590,7 @@ Gnuplot& Gnuplot::plotfile_xyz(const std::string &filename, else cmdstr << "splot "; - cmdstr << "\"" << filename << "\" using " << column_x << ":" << column_y + cmdstr << "\"" << filename << "\" using " << column_x << ":" << column_y << ":" << column_z; if (title == "") @@ -1701,15 +1705,15 @@ Gnuplot& Gnuplot::cmd(const std::string &cmdstr) // int fputs ( const char * str, FILE * stream ); // writes the string str to the stream. - // The function begins copying from the address specified (str) until it - // reaches the terminating null character ('\0'). This final + // The function begins copying from the address specified (str) until it + // reaches the terminating null character ('\0'). This final // null-character is not copied to the stream. fputs( (cmdstr+"\n").c_str(), gnucmd ); // int fflush ( FILE * stream ); - // If the given stream was open for writing and the last i/o operation was - // an output operation, any unwritten data in the output buffer is written - // to the file. If the argument is a null pointer, all open files are + // If the given stream was open for writing and the last i/o operation was + // an output operation, any unwritten data in the output buffer is written + // to the file. If the argument is a null pointer, all open files are // flushed. The stream remains open after this call. fflush(gnucmd); @@ -1739,8 +1743,8 @@ Gnuplot& Gnuplot::cmd(const std::string &cmdstr) void Gnuplot::init() { // char * getenv ( const char * name ); get value of environment variable - // Retrieves a C string containing the value of the environment variable - // whose name is specified as argument. If the requested variable is not + // Retrieves a C string containing the value of the environment variable + // whose name is specified as argument. If the requested variable is not // part of the environment list, the function returns a NULL pointer. #if ( defined(unix) || defined(__unix) || defined(__unix__) ) && !defined(__APPLE__) if (getenv("DISPLAY") == NULL) @@ -1760,12 +1764,12 @@ void Gnuplot::init() // // open pipe // - std::string tmp = Gnuplot::m_sGNUPlotPath + "/" + + std::string tmp = Gnuplot::m_sGNUPlotPath + "/" + Gnuplot::m_sGNUPlotFileName; // FILE *popen(const char *command, const char *mode); - // The popen() function shall execute the command specified by the string - // command, create a pipe between the calling program and the executed + // The popen() function shall execute the command specified by the string + // command, create a pipe between the calling program and the executed // command, and return a pointer to a stream that can be used to either read // from or write to the pipe. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) @@ -1775,7 +1779,7 @@ void Gnuplot::init() #endif // popen() shall return a pointer to an open stream that can be used to read - // or write to the pipe. Otherwise, it shall return a null pointer and may + // or write to the pipe. Otherwise, it shall return a null pointer and may // set errno to indicate the error. if (!gnucmd) { @@ -1803,7 +1807,7 @@ bool Gnuplot::get_program_path() // // first look in m_sGNUPlotPath for Gnuplot // - std::string tmp = Gnuplot::m_sGNUPlotPath + "/" + + std::string tmp = Gnuplot::m_sGNUPlotPath + "/" + Gnuplot::m_sGNUPlotFileName; #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) @@ -1880,7 +1884,7 @@ bool Gnuplot::file_exists(const std::string &filename, int mode) // int _access(const char *path, int mode); // returns 0 if the file has the given mode, - // it returns -1 if the named file does not exist or is not accessible in + // it returns -1 if the named file does not exist or is not accessible in // the given mode // mode = 0 (F_OK) (default): checks file for existence only // mode = 1 (X_OK): execution permission @@ -1952,12 +1956,12 @@ std::string Gnuplot::create_tmpfile(std::ofstream &tmp) // int mkstemp(char *name); // shall replace the contents of the string pointed to by "name" by a unique - // filename, and return a file descriptor for the file open for reading and - // writing. Otherwise, -1 shall be returned if no suitable file could be - // created. The string in template should look like a filename with six - // trailing 'X' s; mkstemp() replaces each 'X' with a character from the + // filename, and return a file descriptor for the file open for reading and + // writing. Otherwise, -1 shall be returned if no suitable file could be + // created. The string in template should look like a filename with six + // trailing 'X' s; mkstemp() replaces each 'X' with a character from the // portable filename character set. The characters are chosen such that the - // resulting name does not duplicate the name of an existing file at the + // resulting name does not duplicate the name of an existing file at the // time of a call to mkstemp() // diff --git a/src/tests/common-files/test_flags.h b/src/tests/common-files/test_flags.h index 424d0e7bc..fac307f84 100644 --- a/src/tests/common-files/test_flags.h +++ b/src/tests/common-files/test_flags.h @@ -39,4 +39,6 @@ DEFINE_string(gnuplot_executable, "", "Gnuplot binary path"); #endif +DEFINE_int32(plot_decimate, 1, "Decimate plots"); + #endif diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc index a41312e8f..21e93139d 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc @@ -32,6 +32,7 @@ #include #include +//#include #include #include #include @@ -50,8 +51,6 @@ #include "tracking_interface.h" #include "in_memory_configuration.h" #include "gnss_synchro.h" -//#include "gps_l1_ca_dll_pll_tracking.h" -#include "gps_l1_ca_dll_pll_c_aid_tracking.h" #include "tracking_true_obs_reader.h" #include "tracking_dump_reader.h" #include "signal_generator_flags.h" @@ -127,6 +126,8 @@ public: std::string p4; std::string p5; + std::string implementation = "GPS_L1_CA_DLL_PLL_Tracking"; //"GPS_L1_CA_DLL_PLL_C_Aid_Tracking"; + const int baseband_sampling_freq = FLAGS_fs_gen_sps; std::string filename_rinex_obs = FLAGS_filename_rinex_obs; @@ -222,14 +223,14 @@ void GpsL1CADllPllTrackingTest::configure_receiver() config->set_property("GNSS-SDR.internal_fs_sps", std::to_string(baseband_sampling_freq)); // Set Tracking - config->set_property("Tracking_1C.implementation", "GPS_L1_CA_DLL_PLL_Tracking"); + config->set_property("Tracking_1C.implementation", implementation); config->set_property("Tracking_1C.item_type", "gr_complex"); - config->set_property("Tracking_1C.if", "0"); - config->set_property("Tracking_1C.dump", "true"); - config->set_property("Tracking_1C.dump_filename", "./tracking_ch_"); - config->set_property("Tracking_1C.pll_bw_hz", "30.0"); + config->set_property("Tracking_1C.pll_bw_hz", "20.0"); config->set_property("Tracking_1C.dll_bw_hz", "2.0"); config->set_property("Tracking_1C.early_late_space_chips", "0.5"); + config->set_property("Tracking_1C.extend_correlation_ms", "1"); + config->set_property("Tracking_1C.dump", "true"); + config->set_property("Tracking_1C.dump_filename", "./tracking_ch_"); } @@ -383,18 +384,17 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) }) << "Failure opening true observables file" << std::endl; top_block = gr::make_top_block("Tracking test"); - //std::shared_ptr tracking = std::make_shared(config.get(), "Tracking_1C", 1, 1); - std::shared_ptr tracking = std::make_shared(config.get(), "Tracking_1C", 1, 1); + + std::shared_ptr trk_ = factory->GetBlock(config, "Tracking_1C", implementation, 1, 1); + std::shared_ptr tracking = std::dynamic_pointer_cast(trk_);//std::make_shared(config.get(), "Tracking_1C", 1, 1); boost::shared_ptr msg_rx = GpsL1CADllPllTrackingTest_msg_rx_make(); // load acquisition data based on the first epoch of the true observations - ASSERT_NO_THROW({ - if (true_obs_data.read_binary_obs() == false) - { - throw std::exception(); - }; - }) << "Failure reading true observables file" << std::endl; + ASSERT_EQ(true_obs_data.read_binary_obs(), true) + << "Failure reading true tracking dump file." << std::endl + << "Maybe sat PRN #" + std::to_string(FLAGS_test_satellite_PRN) + + " is not available?"; //restart the epoch counter true_obs_data.restart(); @@ -479,6 +479,8 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) std::vector prompt; std::vector early; std::vector late; + std::vector promptI; + std::vector promptQ; epoch_counter = 0; while(trk_dump.read_binary_obs()) @@ -495,6 +497,8 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) prompt.push_back(trk_dump.abs_P); early.push_back(trk_dump.abs_E); late.push_back(trk_dump.abs_L); + promptI.push_back(trk_dump.prompt_I); + promptQ.push_back(trk_dump.prompt_Q); } //Align initial measurements and cut the tracking pull-in transitory @@ -511,7 +515,7 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) check_results_acc_carrier_phase(true_timestamp_s, true_acc_carrier_phase_cycles, trk_timestamp_s, trk_acc_carrier_phase_cycles); std::chrono::duration elapsed_seconds = end - start; - std::cout << "Signal tracking completed in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; + std::cout << "Signal tracking completed in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; if(FLAGS_plot_gps_l1_tracking_test == true) { @@ -544,12 +548,25 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) g1.set_xlabel("Time [s]"); g1.set_ylabel("Correlators' output"); g1.cmd("set key box opaque"); - g1.plot_xy( timevec, prompt, "Prompt"); - g1.plot_xy( timevec, early, "Early"); - g1.plot_xy( timevec, late, "Late"); + unsigned int decimate = static_cast(FLAGS_plot_decimate); + g1.plot_xy( timevec, prompt, "Prompt", decimate); + g1.plot_xy( timevec, early, "Early", decimate); + g1.plot_xy( timevec, late, "Late", decimate); g1.savetops("Correlators_outputs"); g1.savetopdf("Correlators_outputs", 18); g1.showonscreen(); // window output + + Gnuplot g2("points"); + g2.set_title("Constellation diagram (satellite PRN #" + std::to_string(FLAGS_test_satellite_PRN) + ")"); + g2.set_grid(); + g2.set_xlabel("Inphase"); + g2.set_ylabel("Quadrature"); + g2.cmd("set size ratio -1"); + g2.plot_xy( promptI, promptQ); + g2.savetops("Constellation"); + g2.savetopdf("Constellation", 18); + g2.showonscreen(); // window output + } catch (GnuplotException ge) { From 218c23000b053d1a7bfce9c5198d4094d7aae742 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 24 Oct 2017 14:47:05 +0200 Subject: [PATCH 5/5] Small fixes --- .../libs/true_observables_reader.cc | 2 +- .../gps_l1_ca_dll_pll_tracking_test.cc | 69 ++++++++----------- 2 files changed, 29 insertions(+), 42 deletions(-) diff --git a/src/tests/unit-tests/signal-processing-blocks/libs/true_observables_reader.cc b/src/tests/unit-tests/signal-processing-blocks/libs/true_observables_reader.cc index f9d63af29..2a6d7830a 100644 --- a/src/tests/unit-tests/signal-processing-blocks/libs/true_observables_reader.cc +++ b/src/tests/unit-tests/signal-processing-blocks/libs/true_observables_reader.cc @@ -34,7 +34,7 @@ bool true_observables_reader::read_binary_obs() { try { - for(int i=0;i<12;i++) + for(int i = 0; i < 12; i++) { d_dump_file.read(reinterpret_cast(&gps_time_sec[i]), sizeof(double)); d_dump_file.read(reinterpret_cast(&doppler_l1_hz), sizeof(double)); diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc index 21e93139d..c10280c44 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc @@ -32,7 +32,6 @@ #include #include -//#include #include #include #include @@ -47,10 +46,8 @@ #include #include "GPS_L1_CA.h" #include "gnss_block_factory.h" -#include "gnss_block_interface.h" #include "tracking_interface.h" #include "in_memory_configuration.h" -#include "gnss_synchro.h" #include "tracking_true_obs_reader.h" #include "tracking_dump_reader.h" #include "signal_generator_flags.h" @@ -239,8 +236,7 @@ void GpsL1CADllPllTrackingTest::check_results_doppler(arma::vec & true_time_s, arma::vec & meas_time_s, arma::vec & meas_value) { - //1. True value interpolation to match the measurement times - + // 1. True value interpolation to match the measurement times arma::vec true_value_interp; arma::uvec true_time_s_valid = find(true_time_s > 0); true_time_s = true_time_s(true_time_s_valid); @@ -251,26 +247,26 @@ void GpsL1CADllPllTrackingTest::check_results_doppler(arma::vec & true_time_s, arma::interp1(true_time_s, true_value, meas_time_s, true_value_interp); - //2. RMSE + // 2. RMSE arma::vec err; err = meas_value - true_value_interp; arma::vec err2 = arma::square(err); double rmse = sqrt(arma::mean(err2)); - //3. Mean err and variance + // 3. Mean err and variance double error_mean = arma::mean(err); double error_var = arma::var(err); - // 5. Peaks + // 4. Peaks double max_error = arma::max(err); double min_error = arma::min(err); - //5. report + // 5. report std::streamsize ss = std::cout.precision(); std::cout << std::setprecision(10) << "TRK Doppler RMSE=" << rmse - << ", mean=" << error_mean - << ", stdev="<< sqrt(error_var) << " (max,min)=" << max_error << "," << min_error << " [Hz]" << std::endl; + << ", mean=" << error_mean + << ", stdev=" << sqrt(error_var) << " (max,min)=" << max_error << "," << min_error << " [Hz]" << std::endl; std::cout.precision (ss); } @@ -280,7 +276,7 @@ void GpsL1CADllPllTrackingTest::check_results_acc_carrier_phase(arma::vec & true arma::vec & meas_time_s, arma::vec & meas_value) { - //1. True value interpolation to match the measurement times + // 1. True value interpolation to match the measurement times arma::vec true_value_interp; arma::uvec true_time_s_valid = find(true_time_s > 0); true_time_s = true_time_s(true_time_s_valid); @@ -291,13 +287,13 @@ void GpsL1CADllPllTrackingTest::check_results_acc_carrier_phase(arma::vec & true arma::interp1(true_time_s, true_value, meas_time_s, true_value_interp); - //2. RMSE + // 2. RMSE arma::vec err; err = meas_value - true_value_interp; arma::vec err2 = arma::square(err); double rmse = sqrt(arma::mean(err2)); - //3. Mean err and variance + // 3. Mean err and variance double error_mean = arma::mean(err); double error_var = arma::var(err); @@ -305,7 +301,7 @@ void GpsL1CADllPllTrackingTest::check_results_acc_carrier_phase(arma::vec & true double max_error = arma::max(err); double min_error = arma::min(err); - //5. report + // 5. report std::streamsize ss = std::cout.precision(); std::cout << std::setprecision(10) << "TRK acc carrier phase RMSE=" << rmse << ", mean=" << error_mean @@ -319,7 +315,7 @@ void GpsL1CADllPllTrackingTest::check_results_codephase(arma::vec & true_time_s, arma::vec & meas_time_s, arma::vec & meas_value) { - //1. True value interpolation to match the measurement times + // 1. True value interpolation to match the measurement times arma::vec true_value_interp; arma::uvec true_time_s_valid = find(true_time_s > 0); true_time_s = true_time_s(true_time_s_valid); @@ -330,14 +326,14 @@ void GpsL1CADllPllTrackingTest::check_results_codephase(arma::vec & true_time_s, arma::interp1(true_time_s, true_value, meas_time_s, true_value_interp); - //2. RMSE + // 2. RMSE arma::vec err; err = meas_value - true_value_interp; arma::vec err2 = arma::square(err); double rmse = sqrt(arma::mean(err2)); - //3. Mean err and variance + // 3. Mean err and variance double error_mean = arma::mean(err); double error_var = arma::var(err); @@ -345,7 +341,7 @@ void GpsL1CADllPllTrackingTest::check_results_codephase(arma::vec & true_time_s, double max_error = arma::max(err); double min_error = arma::min(err); - //5. report + // 5. report std::streamsize ss = std::cout.precision(); std::cout << std::setprecision(10) << "TRK code phase RMSE=" << rmse << ", mean=" << error_mean @@ -369,19 +365,14 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) configure_receiver(); - //open true observables log file written by the simulator + // open true observables log file written by the simulator tracking_true_obs_reader true_obs_data; int test_satellite_PRN = FLAGS_test_satellite_PRN; std::cout << "Testing satellite PRN=" << test_satellite_PRN << std::endl; std::string true_obs_file = std::string("./gps_l1_ca_obs_prn"); true_obs_file.append(std::to_string(test_satellite_PRN)); true_obs_file.append(".dat"); - ASSERT_NO_THROW({ - if (true_obs_data.open_obs_file(true_obs_file) == false) - { - throw std::exception(); - }; - }) << "Failure opening true observables file" << std::endl; + ASSERT_EQ(true_obs_data.open_obs_file(true_obs_file), true) << "Failure opening true observables file"; top_block = gr::make_top_block("Tracking test"); @@ -396,7 +387,7 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) << "Maybe sat PRN #" + std::to_string(FLAGS_test_satellite_PRN) + " is not available?"; - //restart the epoch counter + // restart the epoch counter true_obs_data.restart(); std::cout << "Initial Doppler [Hz]=" << true_obs_data.doppler_l1_hz << " Initial code delay [Chips]=" << true_obs_data.prn_delay_chips << std::endl; @@ -406,15 +397,15 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) ASSERT_NO_THROW( { tracking->set_channel(gnss_synchro.Channel_ID); - }) << "Failure setting channel." << std::endl; + }) << "Failure setting channel."; ASSERT_NO_THROW( { tracking->set_gnss_synchro(&gnss_synchro); - }) << "Failure setting gnss_synchro." << std::endl; + }) << "Failure setting gnss_synchro."; ASSERT_NO_THROW( { tracking->connect(top_block); - }) << "Failure connecting tracking to the top_block." << std::endl; + }) << "Failure connecting tracking to the top_block."; ASSERT_NO_THROW( { std::string file = "./" + filename_raw_data; @@ -426,7 +417,7 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) top_block->connect(gr_interleaved_char_to_complex, 0, tracking->get_left_block(), 0); top_block->connect(tracking->get_right_block(), 0, sink, 0); top_block->msg_connect(tracking->get_right_block(), pmt::mp("events"), msg_rx, pmt::mp("events")); - }) << "Failure connecting the blocks of tracking test." << std::endl; + }) << "Failure connecting the blocks of tracking test."; tracking->start_tracking(); @@ -434,10 +425,10 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) start = std::chrono::system_clock::now(); top_block->run(); // Start threads and wait end = std::chrono::system_clock::now(); - }) << "Failure running the top_block." << std::endl; + }) << "Failure running the top_block."; - //check results - //load the true values + // check results + // load the true values long int nepoch = true_obs_data.num_epochs(); std::cout << "True observation epochs=" << nepoch << std::endl; @@ -460,13 +451,9 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) //load the measured values tracking_dump_reader trk_dump; - ASSERT_NO_THROW({ - if (trk_dump.open_obs_file(std::string("./tracking_ch_0.dat")) == false) - { - throw std::exception(); - }; - }) << "Failure opening tracking dump file" << std::endl; + ASSERT_EQ(trk_dump.open_obs_file(std::string("./tracking_ch_0.dat")), true) + << "Failure opening tracking dump file"; nepoch = trk_dump.num_epochs(); std::cout << "Measured observation epochs=" << nepoch << std::endl; @@ -501,7 +488,7 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults) promptQ.push_back(trk_dump.prompt_Q); } - //Align initial measurements and cut the tracking pull-in transitory + // Align initial measurements and cut the tracking pull-in transitory double pull_in_offset_s = 1.0; arma::uvec initial_meas_point = arma::find(trk_timestamp_s >= (true_timestamp_s(0) + pull_in_offset_s), 1, "first");