From 75a0019896b69fa02abd549d6d741fc2017d37b1 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Sun, 28 May 2017 18:08:03 +0200 Subject: [PATCH 01/22] Adding notch filter files Creation of empty files for notch input filter --- src/algorithms/input_filter/adapters/CMakeLists.txt | 1 + src/algorithms/input_filter/adapters/notch_filter.cc | 0 src/algorithms/input_filter/adapters/notch_filter.h | 0 src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt | 3 ++- src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.cc | 0 src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.h | 0 6 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 src/algorithms/input_filter/adapters/notch_filter.cc create mode 100644 src/algorithms/input_filter/adapters/notch_filter.h create mode 100644 src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.cc create mode 100644 src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.h diff --git a/src/algorithms/input_filter/adapters/CMakeLists.txt b/src/algorithms/input_filter/adapters/CMakeLists.txt index daafaf401..38c35012a 100644 --- a/src/algorithms/input_filter/adapters/CMakeLists.txt +++ b/src/algorithms/input_filter/adapters/CMakeLists.txt @@ -21,6 +21,7 @@ set(INPUT_FILTER_ADAPTER_SOURCES freq_xlating_fir_filter.cc beamformer_filter.cc pulse_blanking_filter.cc + notch_filter.cc ) include_directories( diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc new file mode 100644 index 000000000..e69de29bb diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h new file mode 100644 index 000000000..e69de29bb diff --git a/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt b/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt index e2c3a3674..857e54140 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt @@ -20,6 +20,7 @@ set(INPUT_FILTER_GR_BLOCKS_SOURCES beamformer.cc pulse_blanking_cc.cc + notch_filter_cc.cc ) include_directories( @@ -38,4 +39,4 @@ target_link_libraries(input_filter_gr_blocks ${GNURADIO_FILTER_LIBRARIES} ${VOL if(NOT VOLK_GNSSSDR_FOUND) add_dependencies(input_filter_gr_blocks volk_gnsssdr_module) -endif(NOT VOLK_GNSSSDR_FOUND) \ No newline at end of file +endif(NOT VOLK_GNSSSDR_FOUND) diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.cc new file mode 100644 index 000000000..e69de29bb diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.h new file mode 100644 index 000000000..e69de29bb From 405d9dea5cc1f2519c58f6abcf50a5b6194b5725 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 5 Jun 2017 17:00:33 +0200 Subject: [PATCH 02/22] Modifying notch filter files Little changes in the files --- .../input_filter/adapters/notch_filter.h | 37 +++++++++++++++++++ .../gnuradio_blocks/CMakeLists.txt | 2 +- .../{notch_filter_cc.cc => notch_cc.cc} | 0 .../input_filter/gnuradio_blocks/notch_cc.h | 36 ++++++++++++++++++ .../gnuradio_blocks/notch_filter_cc.h | 0 5 files changed, 74 insertions(+), 1 deletion(-) rename src/algorithms/input_filter/gnuradio_blocks/{notch_filter_cc.cc => notch_cc.cc} (100%) create mode 100644 src/algorithms/input_filter/gnuradio_blocks/notch_cc.h delete mode 100644 src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.h diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index e69de29bb..2783dcd37 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -0,0 +1,37 @@ +/*! + * \file notch_filter.h + * \brief + * \author Antonio Ramos, 2017. antonio.ramosdet(at)gmail.com + * + * Detailed description of the file here if needed. + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * 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 + * (at your option) any later version. + * + * 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 . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_NOTCH_FILTER_H_ +#define GNSS_SDR_NOTCH_FILTER_H_ + + +#endif diff --git a/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt b/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt index 857e54140..718ac1c9a 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt @@ -20,7 +20,7 @@ set(INPUT_FILTER_GR_BLOCKS_SOURCES beamformer.cc pulse_blanking_cc.cc - notch_filter_cc.cc + notch_cc.cc ) include_directories( diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc similarity index 100% rename from src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.cc rename to src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h new file mode 100644 index 000000000..dbe4fa76a --- /dev/null +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -0,0 +1,36 @@ +/*! + * \file notch_cc.h + * \brief Implements a notch filter algorithm + * \author Antonio Ramos (antonio.ramosdet(at)gmail.com) + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * 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 + * (at your option) any later version. + * + * 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 . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_NOTCH_H_ +#define GNSS_SDR_NOTCH_H_ + + + +#endif \ No newline at end of file diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_filter_cc.h deleted file mode 100644 index e69de29bb..000000000 From 4c52774da1062b414be24f830b7d5f2db1170705 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Fri, 9 Jun 2017 14:11:20 +0200 Subject: [PATCH 03/22] Including notch filter header to GNSSBlockFactory Adding #include "notch_filter.h" --- src/core/receiver/gnss_block_factory.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index 0e85d4f2d..a10836917 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -65,6 +65,7 @@ #include "freq_xlating_fir_filter.h" #include "beamformer_filter.h" #include "pulse_blanking_filter.h" +#include "notch_filter.h" #include "gps_l1_ca_pcps_acquisition.h" #include "gps_l2_m_pcps_acquisition.h" #include "gps_l1_ca_pcps_multithread_acquisition.h" From 2731be3939dea5294aad6da0f86477f84ec2edff Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Fri, 9 Jun 2017 14:12:55 +0200 Subject: [PATCH 04/22] Adding some lines to notch_filter.h Coding the class NotchFilter --- .../input_filter/adapters/notch_filter.h | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index 2783dcd37..d583ecc11 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -33,5 +33,45 @@ #ifndef GNSS_SDR_NOTCH_FILTER_H_ #define GNSS_SDR_NOTCH_FILTER_H_ +#include +#include +#include +#include "gnss_block_interface.h" +#include "notch_cc.h" -#endif +class ConfigurationInterface; + +class NotchFilter: public GNSSBlockInterface +{ +public: + NotchFilter(ConfigurationInterface* configuration, + std::string role, unsigned int in_streams, + unsigned int out_streams); + + virtual ~NotchFilter(); + std::string role() + { + return role_; + } + + //! Returns "Notch_Filter" + std::string implementation() + { + return "Notch_Filter"; + } + size_t item_size() + { + return 0; + } + void connect(gr::top_block_sptr top_block); + void disconnect(gr::top_block_sptr top_block); + gr::basic_block_sptr get_left_block(); + gr::basic_block_sptr get_right_block(); + +private: + ConfigurationInterface* config_; + + +}; + +#endif //GNSS_SDR_NOTCH_FILTER_H_ From 3ed545ac3f48909f56b98502b0877cb5ab1b43bf Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Thu, 15 Jun 2017 10:00:20 +0200 Subject: [PATCH 05/22] Minor changes in notch filter files --- .../input_filter/adapters/notch_filter.cc | 75 +++++++++++++++++++ .../input_filter/adapters/notch_filter.h | 10 +++ .../input_filter/gnuradio_blocks/notch_cc.h | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc index e69de29bb..38517a304 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.cc +++ b/src/algorithms/input_filter/adapters/notch_filter.cc @@ -0,0 +1,75 @@ +/*! + * \file notch_filter.cc + * \brief Adapts a gnuradio gr_notch_filter + * \author Antonio Ramos, 2017. antonio.ramosdet(at)gmail.com + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * 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 + * (at your option) any later version. + * + * 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 . + * + * ------------------------------------------------------------------------- + */ + +#include "notch_filter.h" +#include +#include +#include +#include "configuration_interface.h" + +using google::LogMessage; + +NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role, + unsigned int in_streams, unsigned int out_streams) : + config_(configuration), role_(role), in_streams_(in_streams), + out_streams_(out_streams) +{ + (*this).init(); +} + +NotchFilter::~NotchFilter() +{} + +void NotchFilter::connect(gr::top_block_sptr top_block) +{ + +} + +void NotchFilter::disconnect(gr::top_block_sptr top_block) +{ + +} + + +gr::basic_block_sptr NotchFilter::get_left_block() +{ + +} + +gr::basic_block_sptr NotchFilter::get_right_block() +{ + +} + +void NotchFilter::init() +{ + +} \ No newline at end of file diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index d583ecc11..8f929b6a3 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -69,7 +69,17 @@ public: gr::basic_block_sptr get_right_block(); private: + gr::filter::iir_filter_ccc::sptr iir_filter_ccf_; ConfigurationInterface* config_; + bool dump_; + std::string dump_filename_; + std::string input_item_type_; + std::string output_item_type_; + std::string role_; + unsigned int in_streams_; + unsigned int out_streams_; + gr::blocks::file_sink::sptr file_sink_; + void init(); }; diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index dbe4fa76a..a3727c73f 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -33,4 +33,4 @@ -#endif \ No newline at end of file +#endif //GNSS_SDR_NOTCH_H_ \ No newline at end of file From 70dc68b984349ccc673215816654352bda9dd089 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Fri, 16 Jun 2017 13:55:15 +0200 Subject: [PATCH 06/22] Several changes in notch input filter adapter Re-definition of the adapter --- .../input_filter/adapters/notch_filter.cc | 61 +++++++++++++++---- .../input_filter/adapters/notch_filter.h | 11 ++-- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc index 38517a304..665d634b0 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.cc +++ b/src/algorithms/input_filter/adapters/notch_filter.cc @@ -30,19 +30,50 @@ */ #include "notch_filter.h" +#include +#include +#include #include +#include #include -#include #include "configuration_interface.h" +#include "notch_cc.cc" using google::LogMessage; NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role, unsigned int in_streams, unsigned int out_streams) : - config_(configuration), role_(role), in_streams_(in_streams), + role_(role), in_streams_(in_streams), out_streams_(out_streams) { - (*this).init(); + size_t item_size_; + std::string default_item_type = "gr_complex"; + std::string default_dump_file = "./data/input_filter.dat"; + item_type_ = configuration->property(role + ".item_type", default_item_type); + dump_ = configuration->property(role + ".dump", false); + DLOG(INFO) << "dump_ is " << dump_; + dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); + + if (item_type_.compare("gr_complex") == 0) + { + item_size_ = sizeof(gr_complex); + notch_filter_ = make_notch_filter(); + DLOG(INFO) << "Item size " << item_size_; + DLOG(INFO) << "input filter(" << notch_filter_->unique_id() << ")"; + + } + else + { + LOG(WARNING) << item_type_ + << " unrecognized item type for notch filter"; + item_size_ = sizeof(gr_complex); + } + if (dump_) + { + DLOG(INFO) << "Dumping output into file " << dump_filename_; + file_sink_ = gr::blocks::file_sink::make(item_size_, dump_filename_.c_str()); + DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")"; + } } NotchFilter::~NotchFilter() @@ -50,26 +81,32 @@ NotchFilter::~NotchFilter() void NotchFilter::connect(gr::top_block_sptr top_block) { - + if (dump_) + { + top_block->connect(notch_filter_, 0, file_sink_, 0); + DLOG(INFO) << "connected notch filter output to file sink"; + } + else + { + DLOG(INFO) << "nothing to connect internally"; + } } void NotchFilter::disconnect(gr::top_block_sptr top_block) { - + if (dump_) + { + top_block->disconnect(notch_filter_, 0, file_sink_, 0); + } } gr::basic_block_sptr NotchFilter::get_left_block() { - + return notch_filter_; } gr::basic_block_sptr NotchFilter::get_right_block() { - + return notch_filter_; } - -void NotchFilter::init() -{ - -} \ No newline at end of file diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index 8f929b6a3..31ae255ba 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -37,7 +37,7 @@ #include #include #include "gnss_block_interface.h" -#include "notch_cc.h" + class ConfigurationInterface; @@ -69,19 +69,16 @@ public: gr::basic_block_sptr get_right_block(); private: - gr::filter::iir_filter_ccc::sptr iir_filter_ccf_; + ConfigurationInterface* config_; bool dump_; std::string dump_filename_; - std::string input_item_type_; - std::string output_item_type_; std::string role_; + std::string item_type_; unsigned int in_streams_; unsigned int out_streams_; gr::blocks::file_sink::sptr file_sink_; - void init(); - - + gr::block_sptr notch_filter_; }; #endif //GNSS_SDR_NOTCH_FILTER_H_ From 93de803b4172a3a4b40b6129ab5d08ac67fa3b2a Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 19 Jun 2017 15:22:54 +0200 Subject: [PATCH 07/22] GetBlock method modification Adding Notch_Filter to the list of implementations --- src/core/receiver/gnss_block_factory.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index a10836917..cac56293a 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -883,6 +883,12 @@ std::unique_ptr GNSSBlockFactory::GetBlock( out_streams)); block = std::move(block_); } + else if (implementation.compare("Notch_Filter") == 0) + { + std::unique_ptr block_(new NotchFilter(configuration.get(), role, in_streams, + out_streams)); + block = std::move(block_); + } // RESAMPLER ------------------------------------------------------------------- From cf516566d6175e65383e9ed3cf207d8d6939e952 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 19 Jun 2017 15:51:57 +0200 Subject: [PATCH 08/22] New lines in notch filter files Adapter is ready and gnuradio block in progress --- .../input_filter/adapters/notch_filter.cc | 12 +++- .../input_filter/adapters/notch_filter.h | 1 - .../input_filter/gnuradio_blocks/notch_cc.cc | 64 +++++++++++++++++++ .../input_filter/gnuradio_blocks/notch_cc.h | 40 +++++++++++- 4 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc index 665d634b0..31fb6a93d 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.cc +++ b/src/algorithms/input_filter/adapters/notch_filter.cc @@ -47,17 +47,25 @@ NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role out_streams_(out_streams) { size_t item_size_; + double pfa; + double default_pfa = 0.001; + double p_c_factor; + double default_p_c_factor = 0.9; + unsigned int length_; + unsigned int default_length_ = 5; std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/input_filter.dat"; item_type_ = configuration->property(role + ".item_type", default_item_type); dump_ = configuration->property(role + ".dump", false); DLOG(INFO) << "dump_ is " << dump_; dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); - + pfa = configuration->property(role + ".pfa", default_pfa); + p_c_factor = configuration->property(role + ".p_c_factor", default_p_c_factor); + length_ = configuration->property(role + ".length", default_length_); if (item_type_.compare("gr_complex") == 0) { item_size_ = sizeof(gr_complex); - notch_filter_ = make_notch_filter(); + notch_filter_ = make_notch_filter(pfa, p_c_factor, length_); DLOG(INFO) << "Item size " << item_size_; DLOG(INFO) << "input filter(" << notch_filter_->unique_id() << ")"; diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index 31ae255ba..9341cd77b 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -70,7 +70,6 @@ public: private: - ConfigurationInterface* config_; bool dump_; std::string dump_filename_; std::string role_; diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index e69de29bb..a802c67a0 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -0,0 +1,64 @@ +/*! + * \file notch_cc.cc + * \brief Implements a multi state notch filter algorithm + * \author Antonio Ramos (antonio.ramosdet(at)gmail.com) + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * 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 + * (at your option) any later version. + * + * 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 . + * + * ------------------------------------------------------------------------- + */ + +#include "notch_cc.h" +#include +#include +#include +#include +#include + +notch_sptr make_notch_filter(double pfa, double p_c_factor, + unsigned int length_) +{ + return notch_sptr(new Notch(pfa, p_c_factor, length_)); +} + +Notch::Notch(double pfa, double p_c_factor, unsigned int length_) : gr::block("Notch", + gr::io_signature::make (1, 1, sizeof(gr_complex)), + gr::io_signature::make (1, 1, sizeof(gr_complex))) +{ + this->pfa = pfa; + this->noise_pow_est = 0.0; + this->p_c_factor = p_c_factor; + this->length_ = length_; + filter_state_ = 0; + n_deg_fred = 2 * length_; + z_0 = gr_complex(0 , 0); + thres_ = + +} + + +int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), + gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) +{ + +} diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index a3727c73f..6a34d0955 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -31,6 +31,44 @@ #ifndef GNSS_SDR_NOTCH_H_ #define GNSS_SDR_NOTCH_H_ +#include +#include +class Notch; -#endif //GNSS_SDR_NOTCH_H_ \ No newline at end of file +typedef boost::shared_ptr notch_sptr; + +notch_sptr make_notch_filter(double pfa, double p_c_factor, + unsigned int length_); + +/*! + * \brief This class implements a real-time software-defined multi state notch filter + */ + +class Notch: public gr::block +{ +private: + + friend notch_sptr make_notch_filter(double pfa, double p_c_factor, + unsigned int length_); + double pfa; + double noise_pow_est; + double p_c_factor; + double thres_; + unsigned int length_; + unsigned int n_deg_fred; + unsigned int filter_state_; + gr_complex z_0; + + +public: + + Notch(double pfa, double p_c_factor, unsigned int length_); + + ~Notch(); + + int work (int noutput_items, gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif //GNSS_SDR_NOTCH_H_ From 660e3fe3aa28d42649cda3c1c9a2a2d83d055a33 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Tue, 20 Jun 2017 18:13:52 +0200 Subject: [PATCH 09/22] Beta version of notch input filter Beta version of general_work method implemented --- .../input_filter/adapters/notch_filter.cc | 14 ++-- .../input_filter/adapters/notch_filter.h | 3 +- .../input_filter/gnuradio_blocks/notch_cc.cc | 75 +++++++++++++++++-- .../input_filter/gnuradio_blocks/notch_cc.h | 34 +++++---- 4 files changed, 95 insertions(+), 31 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc index 31fb6a93d..abab1a03e 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.cc +++ b/src/algorithms/input_filter/adapters/notch_filter.cc @@ -37,7 +37,7 @@ #include #include #include "configuration_interface.h" -#include "notch_cc.cc" +#include "notch_cc.h" using google::LogMessage; @@ -47,12 +47,12 @@ NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role out_streams_(out_streams) { size_t item_size_; - double pfa; - double default_pfa = 0.001; - double p_c_factor; - double default_p_c_factor = 0.9; - unsigned int length_; - unsigned int default_length_ = 5; + float pfa; + float default_pfa = 0.001; + float p_c_factor; + float default_p_c_factor = 0.9; + int length_; + int default_length_ = 5; std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/input_filter.dat"; item_type_ = configuration->property(role + ".item_type", default_item_type); diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index 9341cd77b..09ac10e99 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -37,6 +37,7 @@ #include #include #include "gnss_block_interface.h" +#include "notch_cc.h" class ConfigurationInterface; @@ -77,7 +78,7 @@ private: unsigned int in_streams_; unsigned int out_streams_; gr::blocks::file_sink::sptr file_sink_; - gr::block_sptr notch_filter_; + notch_sptr notch_filter_; }; #endif //GNSS_SDR_NOTCH_FILTER_H_ diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index a802c67a0..f111412f5 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -32,27 +32,32 @@ #include #include #include -#include #include +#include -notch_sptr make_notch_filter(double pfa, double p_c_factor, - unsigned int length_) +notch_sptr make_notch_filter(float pfa, float p_c_factor, + int length_) { return notch_sptr(new Notch(pfa, p_c_factor, length_)); } -Notch::Notch(double pfa, double p_c_factor, unsigned int length_) : gr::block("Notch", +Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) { + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); this->pfa = pfa; - this->noise_pow_est = 0.0; + noise_pow_est = 0.0; this->p_c_factor = p_c_factor; this->length_ = length_; - filter_state_ = 0; + filter_state_ = false; n_deg_fred = 2 * length_; + n_segments_est = 5; + n_segments = 0; z_0 = gr_complex(0 , 0); - thres_ = + boost::math::chi_squared_distribution my_dist_(n_deg_fred); + thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); } @@ -60,5 +65,59 @@ Notch::Notch(double pfa, double p_c_factor, unsigned int length_) : gr::block("N int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - + gr_complex * in = (gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + gr_complex * paux; + int samples_proc = 0; + int aux = 0; + gr_complex magnitude; + float sig2 = 0.0; + float* angle_; + gr_complex * c_samples; + c_samples = static_cast(volk_malloc(length_ * sizeof(gr_complex), volk_get_alignment())); + angle_ = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); + while(((samples_proc + length_) < noutput_items) && (n_segments < n_segments_est)) + { + volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); + sig2 = magnitude.real() / ((float) n_deg_fred); + noise_pow_est = (((float) n_segments) * noise_pow_est + sig2) / ((float)(n_segments + 1)); + samples_proc = samples_proc + length_; + n_segments++; + memcpy(out, in, sizeof(gr_complex)*length_); + in = (gr_complex *) input_items[samples_proc]; + out = (gr_complex *) output_items[samples_proc]; + } + while((samples_proc + length_) < noutput_items) + { + volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); + if( (magnitude.real() / noise_pow_est) > thres_) + { + filter_state_ = true; + paux = (gr_complex *) input_items[samples_proc-1]; + volk_32fc_x2_multiply_conjugate_32fc(c_samples, in, paux, length_); + volk_32fc_s32f_atan2_32f(angle_, c_samples, (float)1.0, length_); + for(aux = 0; aux < length_; aux++) + { + z_0 = std::exp(gr_complex(0,1) *angle_[aux]); + out[samples_proc] = in[samples_proc] - z_0 * in[samples_proc - 1] + + gr_complex(p_c_factor,0) * z_0 * out[samples_proc -1]; + samples_proc++; + in = (gr_complex *) input_items[samples_proc]; + out = (gr_complex *) output_items[samples_proc]; + } + + } + else + { + filter_state_ = false; + samples_proc = samples_proc + length_; + memcpy(out, in, sizeof(gr_complex)*length_); + in = (gr_complex *) input_items[samples_proc]; + out = (gr_complex *) output_items[samples_proc]; + } + } + volk_free(c_samples); + volk_free(angle_); + consume_each(samples_proc); + return samples_proc; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index 6a34d0955..ad12c49c4 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -38,37 +38,41 @@ class Notch; typedef boost::shared_ptr notch_sptr; -notch_sptr make_notch_filter(double pfa, double p_c_factor, - unsigned int length_); +notch_sptr make_notch_filter(float pfa, float p_c_factor, + int length_); /*! * \brief This class implements a real-time software-defined multi state notch filter */ -class Notch: public gr::block +class Notch : public gr::block { private: - friend notch_sptr make_notch_filter(double pfa, double p_c_factor, - unsigned int length_); - double pfa; - double noise_pow_est; - double p_c_factor; - double thres_; - unsigned int length_; - unsigned int n_deg_fred; - unsigned int filter_state_; + float pfa; + float noise_pow_est; + float p_c_factor; + float thres_; + int length_; + int n_segments_est; + int n_segments; + int n_deg_fred; + bool filter_state_; gr_complex z_0; public: - Notch(double pfa, double p_c_factor, unsigned int length_); + //friend notch_sptr make_notch_filter(float pfa, float p_c_factor, + // int length_); + + Notch(float pfa, float p_c_factor, int length_); ~Notch(); - int work (int noutput_items, gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work (int noutput_items, gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); }; #endif //GNSS_SDR_NOTCH_H_ From 7fba751a49b9059195dfdca62fd56e89b7444086 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Tue, 20 Jun 2017 18:13:52 +0200 Subject: [PATCH 10/22] Beta version of notch input filter Beta version of general_work method implemented --- .../input_filter/adapters/notch_filter.cc | 14 ++-- .../input_filter/adapters/notch_filter.h | 3 +- .../input_filter/gnuradio_blocks/notch_cc.cc | 75 +++++++++++++++++-- .../input_filter/gnuradio_blocks/notch_cc.h | 36 ++++----- 4 files changed, 95 insertions(+), 33 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc index 31fb6a93d..abab1a03e 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.cc +++ b/src/algorithms/input_filter/adapters/notch_filter.cc @@ -37,7 +37,7 @@ #include #include #include "configuration_interface.h" -#include "notch_cc.cc" +#include "notch_cc.h" using google::LogMessage; @@ -47,12 +47,12 @@ NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role out_streams_(out_streams) { size_t item_size_; - double pfa; - double default_pfa = 0.001; - double p_c_factor; - double default_p_c_factor = 0.9; - unsigned int length_; - unsigned int default_length_ = 5; + float pfa; + float default_pfa = 0.001; + float p_c_factor; + float default_p_c_factor = 0.9; + int length_; + int default_length_ = 5; std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/input_filter.dat"; item_type_ = configuration->property(role + ".item_type", default_item_type); diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index 9341cd77b..09ac10e99 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -37,6 +37,7 @@ #include #include #include "gnss_block_interface.h" +#include "notch_cc.h" class ConfigurationInterface; @@ -77,7 +78,7 @@ private: unsigned int in_streams_; unsigned int out_streams_; gr::blocks::file_sink::sptr file_sink_; - gr::block_sptr notch_filter_; + notch_sptr notch_filter_; }; #endif //GNSS_SDR_NOTCH_FILTER_H_ diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index a802c67a0..f111412f5 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -32,27 +32,32 @@ #include #include #include -#include #include +#include -notch_sptr make_notch_filter(double pfa, double p_c_factor, - unsigned int length_) +notch_sptr make_notch_filter(float pfa, float p_c_factor, + int length_) { return notch_sptr(new Notch(pfa, p_c_factor, length_)); } -Notch::Notch(double pfa, double p_c_factor, unsigned int length_) : gr::block("Notch", +Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) { + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); this->pfa = pfa; - this->noise_pow_est = 0.0; + noise_pow_est = 0.0; this->p_c_factor = p_c_factor; this->length_ = length_; - filter_state_ = 0; + filter_state_ = false; n_deg_fred = 2 * length_; + n_segments_est = 5; + n_segments = 0; z_0 = gr_complex(0 , 0); - thres_ = + boost::math::chi_squared_distribution my_dist_(n_deg_fred); + thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); } @@ -60,5 +65,59 @@ Notch::Notch(double pfa, double p_c_factor, unsigned int length_) : gr::block("N int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - + gr_complex * in = (gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + gr_complex * paux; + int samples_proc = 0; + int aux = 0; + gr_complex magnitude; + float sig2 = 0.0; + float* angle_; + gr_complex * c_samples; + c_samples = static_cast(volk_malloc(length_ * sizeof(gr_complex), volk_get_alignment())); + angle_ = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); + while(((samples_proc + length_) < noutput_items) && (n_segments < n_segments_est)) + { + volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); + sig2 = magnitude.real() / ((float) n_deg_fred); + noise_pow_est = (((float) n_segments) * noise_pow_est + sig2) / ((float)(n_segments + 1)); + samples_proc = samples_proc + length_; + n_segments++; + memcpy(out, in, sizeof(gr_complex)*length_); + in = (gr_complex *) input_items[samples_proc]; + out = (gr_complex *) output_items[samples_proc]; + } + while((samples_proc + length_) < noutput_items) + { + volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); + if( (magnitude.real() / noise_pow_est) > thres_) + { + filter_state_ = true; + paux = (gr_complex *) input_items[samples_proc-1]; + volk_32fc_x2_multiply_conjugate_32fc(c_samples, in, paux, length_); + volk_32fc_s32f_atan2_32f(angle_, c_samples, (float)1.0, length_); + for(aux = 0; aux < length_; aux++) + { + z_0 = std::exp(gr_complex(0,1) *angle_[aux]); + out[samples_proc] = in[samples_proc] - z_0 * in[samples_proc - 1] + + gr_complex(p_c_factor,0) * z_0 * out[samples_proc -1]; + samples_proc++; + in = (gr_complex *) input_items[samples_proc]; + out = (gr_complex *) output_items[samples_proc]; + } + + } + else + { + filter_state_ = false; + samples_proc = samples_proc + length_; + memcpy(out, in, sizeof(gr_complex)*length_); + in = (gr_complex *) input_items[samples_proc]; + out = (gr_complex *) output_items[samples_proc]; + } + } + volk_free(c_samples); + volk_free(angle_); + consume_each(samples_proc); + return samples_proc; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index 6a34d0955..29e292b95 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -38,37 +38,39 @@ class Notch; typedef boost::shared_ptr notch_sptr; -notch_sptr make_notch_filter(double pfa, double p_c_factor, - unsigned int length_); +notch_sptr make_notch_filter(float pfa, float p_c_factor, + int length_); /*! * \brief This class implements a real-time software-defined multi state notch filter */ -class Notch: public gr::block +class Notch : public gr::block { private: - friend notch_sptr make_notch_filter(double pfa, double p_c_factor, - unsigned int length_); - double pfa; - double noise_pow_est; - double p_c_factor; - double thres_; - unsigned int length_; - unsigned int n_deg_fred; - unsigned int filter_state_; + float pfa; + float noise_pow_est; + float p_c_factor; + float thres_; + int length_; + int n_segments_est; + int n_segments; + int n_deg_fred; + bool filter_state_; gr_complex z_0; public: - Notch(double pfa, double p_c_factor, unsigned int length_); + //friend notch_sptr make_notch_filter(float pfa, float p_c_factor, + // int length_); - ~Notch(); - - int work (int noutput_items, gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + Notch(float pfa, float p_c_factor, int length_); + + int general_work (int noutput_items, gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); }; #endif //GNSS_SDR_NOTCH_H_ From d67d9b270e65282b799eaf41c879bfee626cfa43 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Fri, 23 Jun 2017 11:34:02 +0200 Subject: [PATCH 11/22] Improved multistate notch filter Better managing of the system memory --- .../input_filter/gnuradio_blocks/notch_cc.cc | 92 +++++++++++-------- .../input_filter/gnuradio_blocks/notch_cc.h | 20 ++-- 2 files changed, 69 insertions(+), 43 deletions(-) diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index f111412f5..cde7eae38 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -47,77 +47,97 @@ Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", { const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); set_alignment(std::max(1, alignment_multiple)); + set_history(2); this->pfa = pfa; noise_pow_est = 0.0; this->p_c_factor = p_c_factor; - this->length_ = length_; - filter_state_ = false; - n_deg_fred = 2 * length_; - n_segments_est = 5; - n_segments = 0; + this->length_ = length_; //Set the number of samples per segment + set_output_multiple(length_); + filter_state_ = false; //Initial state of the filter + n_deg_fred = 2 * length_; //Number of dregrees of freedom + n_segments = 0; + n_segments_est = 8; // Set the number of segments for noise power estimation + n_segments_reset = 1000000; // Set the period (in segments) when the noise power is estimated z_0 = gr_complex(0 , 0); boost::math::chi_squared_distribution my_dist_(n_deg_fred); thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); - + in = NULL; + out = NULL; + paux = NULL; + c_samples = static_cast(volk_malloc(length_ * sizeof(gr_complex), volk_get_alignment())); + angle_ = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); + last_out = gr_complex(0,0); } +Notch::~Notch() +{ + volk_free(c_samples); + volk_free(angle_); +} int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - gr_complex * in = (gr_complex *) input_items[0]; - gr_complex *out = (gr_complex *) output_items[0]; - gr_complex * paux; - int samples_proc = 0; + int index_in = 1; + int index_out = 0; + in = (gr_complex *) input_items[index_in]; + out = (gr_complex *) output_items[index_out]; int aux = 0; gr_complex magnitude; float sig2 = 0.0; - float* angle_; - gr_complex * c_samples; - c_samples = static_cast(volk_malloc(length_ * sizeof(gr_complex), volk_get_alignment())); - angle_ = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); - while(((samples_proc + length_) < noutput_items) && (n_segments < n_segments_est)) + while(((index_out + length_) < noutput_items) && (n_segments < n_segments_est) && (filter_state_ == false)) { volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); sig2 = magnitude.real() / ((float) n_deg_fred); noise_pow_est = (((float) n_segments) * noise_pow_est + sig2) / ((float)(n_segments + 1)); - samples_proc = samples_proc + length_; + index_out = index_out + length_; + index_in = index_in +length_; n_segments++; - memcpy(out, in, sizeof(gr_complex)*length_); - in = (gr_complex *) input_items[samples_proc]; - out = (gr_complex *) output_items[samples_proc]; + memcpy(out, in, sizeof(gr_complex) * length_); + in = (gr_complex *) input_items[index_in]; + out = (gr_complex *) output_items[index_out]; } - while((samples_proc + length_) < noutput_items) + while((index_out + length_) < noutput_items) { + n_segments++; volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); if( (magnitude.real() / noise_pow_est) > thres_) { - filter_state_ = true; - paux = (gr_complex *) input_items[samples_proc-1]; + if(filter_state_ == false) + { + filter_state_ = true; + last_out = gr_complex(0,0); + } + paux = (gr_complex *) input_items[index_in-1]; volk_32fc_x2_multiply_conjugate_32fc(c_samples, in, paux, length_); volk_32fc_s32f_atan2_32f(angle_, c_samples, (float)1.0, length_); for(aux = 0; aux < length_; aux++) { - z_0 = std::exp(gr_complex(0,1) *angle_[aux]); - out[samples_proc] = in[samples_proc] - z_0 * in[samples_proc - 1] - + gr_complex(p_c_factor,0) * z_0 * out[samples_proc -1]; - samples_proc++; - in = (gr_complex *) input_items[samples_proc]; - out = (gr_complex *) output_items[samples_proc]; + z_0 = std::exp(gr_complex(0,1) * angle_[aux]); + out[index_out] = in[index_in] - z_0 * in[index_in - 1] + + gr_complex(p_c_factor,0) * z_0 * last_out; + last_out = out[index_out]; + index_out++; + index_in++; + in = (gr_complex *) input_items[index_in]; + out = (gr_complex *) output_items[index_out]; } } else { + if (n_segments > n_segments_reset) + { + n_segments = 0; + } filter_state_ = false; - samples_proc = samples_proc + length_; - memcpy(out, in, sizeof(gr_complex)*length_); - in = (gr_complex *) input_items[samples_proc]; - out = (gr_complex *) output_items[samples_proc]; + index_out = index_out + length_; + index_in = index_in +length_; + memcpy(out, in, sizeof(gr_complex) * length_); + in = (gr_complex *) input_items[index_in]; + out = (gr_complex *) output_items[index_out]; } } - volk_free(c_samples); - volk_free(angle_); - consume_each(samples_proc); - return samples_proc; + consume_each(index_out); + return index_out; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index 29e292b95..5f7c469a8 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -54,20 +54,26 @@ private: float p_c_factor; float thres_; int length_; - int n_segments_est; - int n_segments; + unsigned int n_segments; + unsigned int n_segments_est; + unsigned int n_segments_reset; int n_deg_fred; bool filter_state_; + gr_complex last_out; gr_complex z_0; + gr_complex* in; + gr_complex* out; + gr_complex* paux; + gr_complex* c_samples; + float* angle_; public: - - //friend notch_sptr make_notch_filter(float pfa, float p_c_factor, - // int length_); - + Notch(float pfa, float p_c_factor, int length_); - + + ~Notch(); + int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); From 119c8c19663fa5e4236fc0a9ddd352f5b90eb9bd Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Fri, 7 Jul 2017 11:48:54 +0200 Subject: [PATCH 12/22] Notch filter solved problems Segmentation fault due to pointers in the notch filter gnu radio block solved --- .../input_filter/adapters/notch_filter.cc | 2 +- .../input_filter/gnuradio_blocks/notch_cc.cc | 56 ++++++++++--------- .../input_filter/gnuradio_blocks/notch_cc.h | 8 +-- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc index abab1a03e..a69c0c9c0 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.cc +++ b/src/algorithms/input_filter/adapters/notch_filter.cc @@ -52,7 +52,7 @@ NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role float p_c_factor; float default_p_c_factor = 0.9; int length_; - int default_length_ = 5; + int default_length_ = 32; std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/input_filter.dat"; item_type_ = configuration->property(role + ".item_type", default_item_type); diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index cde7eae38..7b5d7db6e 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -32,8 +32,14 @@ #include #include #include +#include +#include #include #include +#include +#include + +using google::LogMessage; notch_sptr make_notch_filter(float pfa, float p_c_factor, int length_) @@ -50,7 +56,7 @@ Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", set_history(2); this->pfa = pfa; noise_pow_est = 0.0; - this->p_c_factor = p_c_factor; + this->p_c_factor = gr_complex(p_c_factor , 0); this->length_ = length_; //Set the number of samples per segment set_output_multiple(length_); filter_state_ = false; //Initial state of the filter @@ -61,9 +67,6 @@ Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", z_0 = gr_complex(0 , 0); boost::math::chi_squared_distribution my_dist_(n_deg_fred); thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); - in = NULL; - out = NULL; - paux = NULL; c_samples = static_cast(volk_malloc(length_ * sizeof(gr_complex), volk_get_alignment())); angle_ = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); last_out = gr_complex(0,0); @@ -78,49 +81,52 @@ Notch::~Notch() int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { + int index_in = 1; int index_out = 0; - in = (gr_complex *) input_items[index_in]; - out = (gr_complex *) output_items[index_out]; int aux = 0; - gr_complex magnitude; + lv_32fc_t magnitude; float sig2 = 0.0; + gr_complex* in = (gr_complex *) input_items[0]; + gr_complex* out = (gr_complex *) output_items[0]; + gr_complex* paux; + in++; while(((index_out + length_) < noutput_items) && (n_segments < n_segments_est) && (filter_state_ == false)) { volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); - sig2 = magnitude.real() / ((float) n_deg_fred); + sig2 = lv_creal(magnitude) / ((float) n_deg_fred); noise_pow_est = (((float) n_segments) * noise_pow_est + sig2) / ((float)(n_segments + 1)); - index_out = index_out + length_; - index_in = index_in +length_; + index_out += length_; + index_in += length_; n_segments++; memcpy(out, in, sizeof(gr_complex) * length_); - in = (gr_complex *) input_items[index_in]; - out = (gr_complex *) output_items[index_out]; + in += length_; + out += length_; } while((index_out + length_) < noutput_items) { n_segments++; volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); - if( (magnitude.real() / noise_pow_est) > thres_) + if( (lv_creal(magnitude) / noise_pow_est) > thres_) { if(filter_state_ == false) { filter_state_ = true; last_out = gr_complex(0,0); } - paux = (gr_complex *) input_items[index_in-1]; + paux = in - 1; volk_32fc_x2_multiply_conjugate_32fc(c_samples, in, paux, length_); - volk_32fc_s32f_atan2_32f(angle_, c_samples, (float)1.0, length_); + volk_32fc_s32f_atan2_32f(angle_, c_samples, ((float)1.0), length_); for(aux = 0; aux < length_; aux++) { - z_0 = std::exp(gr_complex(0,1) * angle_[aux]); - out[index_out] = in[index_in] - z_0 * in[index_in - 1] - + gr_complex(p_c_factor,0) * z_0 * last_out; - last_out = out[index_out]; + z_0 = std::exp(gr_complex(0,1) * (*(angle_ + aux))); + *out = *in - z_0 * (*(in - 1)) + + p_c_factor * z_0 * last_out; + last_out = *out; index_out++; index_in++; - in = (gr_complex *) input_items[index_in]; - out = (gr_complex *) output_items[index_out]; + in ++; + out ++; } } @@ -131,11 +137,11 @@ int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int n_segments = 0; } filter_state_ = false; - index_out = index_out + length_; - index_in = index_in +length_; + index_out += length_; + index_in += length_; memcpy(out, in, sizeof(gr_complex) * length_); - in = (gr_complex *) input_items[index_in]; - out = (gr_complex *) output_items[index_out]; + in += length_; + out += length_; } } consume_each(index_out); diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index 5f7c469a8..c3a843310 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -51,7 +51,7 @@ private: float pfa; float noise_pow_est; - float p_c_factor; + gr_complex p_c_factor; float thres_; int length_; unsigned int n_segments; @@ -61,12 +61,8 @@ private: bool filter_state_; gr_complex last_out; gr_complex z_0; - gr_complex* in; - gr_complex* out; - gr_complex* paux; gr_complex* c_samples; - float* angle_; - + float* angle_; public: From 0b8e3c93991c3e7c8445eba604dd2db6ae05f4fe Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 10 Jul 2017 09:48:38 +0200 Subject: [PATCH 13/22] New noise floor power estimation in notch filter In this version, the noise floor power is estimated via a VOLK Kernel --- .../input_filter/gnuradio_blocks/notch_cc.cc | 31 ++++++++++++------- .../input_filter/gnuradio_blocks/notch_cc.h | 7 +++-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index 7b5d7db6e..8c79d3b50 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -38,6 +38,7 @@ #include #include #include +#include using google::LogMessage; @@ -63,12 +64,13 @@ Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", n_deg_fred = 2 * length_; //Number of dregrees of freedom n_segments = 0; n_segments_est = 8; // Set the number of segments for noise power estimation - n_segments_reset = 1000000; // Set the period (in segments) when the noise power is estimated + n_segments_reset = 10000; // Set the period (in segments) when the noise power is estimated z_0 = gr_complex(0 , 0); boost::math::chi_squared_distribution my_dist_(n_deg_fred); thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); c_samples = static_cast(volk_malloc(length_ * sizeof(gr_complex), volk_get_alignment())); angle_ = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); + power_spect = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); last_out = gr_complex(0,0); } @@ -76,6 +78,7 @@ Notch::~Notch() { volk_free(c_samples); volk_free(angle_); + volk_free(power_spect); } int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), @@ -85,29 +88,35 @@ int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int int index_in = 1; int index_out = 0; int aux = 0; - lv_32fc_t magnitude; - float sig2 = 0.0; + float sig2dB = 0.0; + float sig2lin = 0.0; + lv_32fc_t dot_prod_; gr_complex* in = (gr_complex *) input_items[0]; gr_complex* out = (gr_complex *) output_items[0]; gr_complex* paux; in++; + arma::cx_fvec signal_segment; + arma::cx_fvec signal_segment_fft; while(((index_out + length_) < noutput_items) && (n_segments < n_segments_est) && (filter_state_ == false)) { - volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); - sig2 = lv_creal(magnitude) / ((float) n_deg_fred); - noise_pow_est = (((float) n_segments) * noise_pow_est + sig2) / ((float)(n_segments + 1)); + signal_segment = arma::cx_fvec(in, length_, false, false); + signal_segment_fft = arma::fft(signal_segment); + volk_32fc_s32f_power_spectrum_32f(power_spect, signal_segment_fft.memptr(), 1.0, length_); + volk_32f_s32f_calc_spectral_noise_floor_32f(&sig2dB, power_spect, 15.0, length_); + sig2lin = std::pow(10.0, (sig2dB / 10.0)) / ((float) n_deg_fred); + noise_pow_est = (((float) n_segments) * noise_pow_est + sig2lin) / ((float)(n_segments + 1)); + memcpy(out, in, sizeof(gr_complex) * length_); index_out += length_; index_in += length_; n_segments++; - memcpy(out, in, sizeof(gr_complex) * length_); in += length_; out += length_; } while((index_out + length_) < noutput_items) { n_segments++; - volk_32fc_x2_conjugate_dot_prod_32fc(&magnitude, in, in, length_); - if( (lv_creal(magnitude) / noise_pow_est) > thres_) + volk_32fc_x2_conjugate_dot_prod_32fc(&dot_prod_, in, in, length_); + if( (lv_creal(dot_prod_) / noise_pow_est) > thres_) { if(filter_state_ == false) { @@ -120,7 +129,7 @@ int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int for(aux = 0; aux < length_; aux++) { z_0 = std::exp(gr_complex(0,1) * (*(angle_ + aux))); - *out = *in - z_0 * (*(in - 1)) + *out = (*in) - z_0 * (*(in - 1)) + p_c_factor * z_0 * last_out; last_out = *out; index_out++; @@ -137,9 +146,9 @@ int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int n_segments = 0; } filter_state_ = false; + memcpy(out, in, sizeof(gr_complex) * length_); index_out += length_; index_in += length_; - memcpy(out, in, sizeof(gr_complex) * length_); in += length_; out += length_; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index c3a843310..faf7c5d0c 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -51,18 +51,19 @@ private: float pfa; float noise_pow_est; - gr_complex p_c_factor; float thres_; int length_; + int n_deg_fred; unsigned int n_segments; unsigned int n_segments_est; unsigned int n_segments_reset; - int n_deg_fred; bool filter_state_; gr_complex last_out; gr_complex z_0; + gr_complex p_c_factor; gr_complex* c_samples; - float* angle_; + float* angle_; + float* power_spect; public: From cbe54da10fa71676e5decc74b8ab89829391d70e Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 10 Jul 2017 12:53:26 +0200 Subject: [PATCH 14/22] Beta version Pulse Blanking Filter First version of the pulse blanking input filter --- .../adapters/pulse_blanking_filter.cc | 11 ++- .../adapters/pulse_blanking_filter.h | 2 - .../gnuradio_blocks/pulse_blanking_cc.cc | 94 ++++++++++++------- .../gnuradio_blocks/pulse_blanking_cc.h | 24 +++-- 4 files changed, 82 insertions(+), 49 deletions(-) diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc index 4bca7a799..7dfe27b62 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc @@ -46,21 +46,22 @@ PulseBlankingFilter::PulseBlankingFilter(ConfigurationInterface* configuration, std::string default_input_item_type = "gr_complex"; std::string default_output_item_type = "gr_complex"; std::string default_dump_filename = "../data/input_filter.dat"; - + DLOG(INFO) << "role " << role_; input_item_type_ = config_->property(role_ + ".input_item_type", default_input_item_type); output_item_type_ = config_->property(role_ + ".output_item_type", default_output_item_type); dump_ = config_->property(role_ + ".dump", false); dump_filename_ = config_->property(role_ + ".dump_filename", default_dump_filename); - - double Pfa = config_->property(role_ + ".Pfa", 0.001); - + float default_pfa_ = 0.001; + float pfa = config_->property(role_ + ".pfa", default_pfa_); + int default_length_ = 32; + int length_ = config_->property(role_ + ".length", default_length_); if (input_item_type_.compare("gr_complex") == 0) { item_size = sizeof(gr_complex); //output input_size_ = sizeof(gr_complex); //input - pulse_blanking_cc_ = make_pulse_blanking_cc(Pfa); + pulse_blanking_cc_ = make_pulse_blanking_cc(pfa, length_); } else { diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h index ce812556d..4382e4281 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h @@ -76,8 +76,6 @@ private: std::string input_item_type_; size_t input_size_; std::string output_item_type_; - double intermediate_freq_; - double sampling_freq_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc index f2ec0f198..c7cfc0475 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc @@ -29,62 +29,88 @@ */ #include "pulse_blanking_cc.h" +#include #include #include #include #include -#include - -pulse_blanking_cc_sptr make_pulse_blanking_cc(double Pfa) +pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int length_) { - return pulse_blanking_cc_sptr(new pulse_blanking_cc(Pfa)); + return pulse_blanking_cc_sptr(new pulse_blanking_cc(pfa, length_)); } -pulse_blanking_cc::pulse_blanking_cc(double Pfa) : gr::block("pulse_blanking_cc", +pulse_blanking_cc::pulse_blanking_cc(float pfa, int length_) : gr::block("pulse_blanking_cc", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) { const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); set_alignment(std::max(1, alignment_multiple)); - d_Pfa = Pfa; + this->pfa = pfa; + this->length_ = length_; + set_output_multiple(length_); + last_filtered = false; + n_segments = 0; + n_segments_est = 8; + n_segments_reset = 10000; + noise_power_estimation = 0.0; + n_deg_fred = 2*length_; + boost::math::chi_squared_distribution my_dist_(n_deg_fred); + thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); + zeros_ = static_cast(volk_malloc(length_ * sizeof(gr_complex), volk_get_alignment())); + magnitude = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); + for (int aux = 0; aux < length_; aux++) + { + zeros_[aux] = gr_complex(0, 0); + } } +pulse_blanking_cc::~pulse_blanking_cc() +{ + volk_free(zeros_); + volk_free(magnitude); +} int pulse_blanking_cc::general_work (int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - const gr_complex *in = (const gr_complex *) input_items[0]; + gr_complex *in = (gr_complex *) input_items[0]; gr_complex *out = (gr_complex *) output_items[0]; - - // 1- (optional) Compute the input signal power estimation - //float mean; - //float stddev; - //volk_32f_stddev_and_mean_32f_x2(&stddev, &mean, in, noutput_items); - - float* magnitude; - magnitude = static_cast(volk_gnsssdr_malloc(noutput_items * sizeof(float), volk_gnsssdr_get_alignment())); - - float var; - volk_32fc_magnitude_squared_32f(magnitude, in, noutput_items); - volk_32f_accumulator_s32f(&var, magnitude, noutput_items); - var /= static_cast(noutput_items); - // compute pulse blanking threshold (Paper Borio 2016) - - float Th = sqrt(-2.0 * var * log10(d_Pfa)); - - //apply the pulse blanking - //todo: write volk kernel to optimize the blanking - memcpy(out,in, sizeof(gr_complex)*noutput_items); - for (int n = 0; n < noutput_items; n++) + int sample_index = 0; + float segment_energy; + while((sample_index + length_) < noutput_items) + { + volk_32fc_magnitude_squared_32f(magnitude, in, length_); + volk_32f_accumulator_s32f(&segment_energy, magnitude, length_); + if((n_segments < n_segments_est) && (last_filtered == false)) { - if (std::abs(out[n]) > Th) - { - out[n] = gr_complex(0,0); - } + noise_power_estimation = (((float) n_segments) * noise_power_estimation + segment_energy / ((float)n_deg_fred)) / ((float)(n_segments + 1)); + memcpy(out, in, sizeof(gr_complex)*length_); } - consume_each(noutput_items); - return noutput_items; + else + { + if((segment_energy/noise_power_estimation) > thres_) + { + memcpy(out, zeros_, sizeof(gr_complex)*length_); + last_filtered = true; + } + else + { + memcpy(out, in, sizeof(gr_complex)*length_); + last_filtered = false; + if (n_segments > n_segments_reset) + { + n_segments = 0; + } + } + } + in+=length_; + out+=length_; + sample_index+=length_; + n_segments++; + } + consume_each(sample_index); + return sample_index; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h index 8e23d39ad..620e4731f 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h @@ -38,19 +38,27 @@ class pulse_blanking_cc; typedef boost::shared_ptr pulse_blanking_cc_sptr; -pulse_blanking_cc_sptr make_pulse_blanking_cc(double Pfa); +pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int length_); + -/*! - * \brief This class adapts a short (16-bits) interleaved sample stream - * into a std::complex stream - */ class pulse_blanking_cc : public gr::block { private: - friend pulse_blanking_cc_sptr make_pulse_blanking_cc(double Pfa); - double d_Pfa; + int length_; + int n_segments; + int n_segments_est; + int n_segments_reset; + int n_deg_fred; + bool last_filtered; + float noise_power_estimation; + float thres_; + float pfa; + float* magnitude; + gr_complex* zeros_; public: - pulse_blanking_cc(double Pfa); + pulse_blanking_cc(float pfa, int length_); + + ~pulse_blanking_cc(); int general_work (int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); From 8f1fcb382a60717b3eedb5ce32fd90dcf3dcab18 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Wed, 12 Jul 2017 09:12:56 +0200 Subject: [PATCH 15/22] Improved Pulse Blanking Filter Number of signal segments for estimating the noise power is passed now as a parameter in the configuration file --- .../adapters/pulse_blanking_filter.cc | 11 ++++++---- .../adapters/pulse_blanking_filter.h | 3 --- .../gnuradio_blocks/pulse_blanking_cc.cc | 20 +++++++++++-------- .../gnuradio_blocks/pulse_blanking_cc.h | 8 ++++++-- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc index 7dfe27b62..cedad7741 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc @@ -42,7 +42,6 @@ PulseBlankingFilter::PulseBlankingFilter(ConfigurationInterface* configuration, out_streams_(out_streams) { size_t item_size; - std::string default_input_item_type = "gr_complex"; std::string default_output_item_type = "gr_complex"; std::string default_dump_filename = "../data/input_filter.dat"; @@ -53,15 +52,19 @@ PulseBlankingFilter::PulseBlankingFilter(ConfigurationInterface* configuration, output_item_type_ = config_->property(role_ + ".output_item_type", default_output_item_type); dump_ = config_->property(role_ + ".dump", false); dump_filename_ = config_->property(role_ + ".dump_filename", default_dump_filename); - float default_pfa_ = 0.001; + float default_pfa_ = 0.01; float pfa = config_->property(role_ + ".pfa", default_pfa_); - int default_length_ = 32; + int default_length_ = 16; int length_ = config_->property(role_ + ".length", default_length_); + int default_n_segments_est = 25000; + int n_segments_est = config_->property(role_ + ".segments_estimation", default_n_segments_est); + int default_n_segments_reset = 500000; + int n_segments_reset = config_->property(role_ + ".segments_reset", default_n_segments_reset); if (input_item_type_.compare("gr_complex") == 0) { item_size = sizeof(gr_complex); //output input_size_ = sizeof(gr_complex); //input - pulse_blanking_cc_ = make_pulse_blanking_cc(pfa, length_); + pulse_blanking_cc_ = make_pulse_blanking_cc(pfa, length_, n_segments_est, n_segments_reset); } else { diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h index 4382e4281..041ba2251 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h @@ -39,9 +39,6 @@ class ConfigurationInterface; -/*! - * \brief TODO - */ class PulseBlankingFilter: public GNSSBlockInterface { public: diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc index c7cfc0475..ec758e511 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc @@ -34,15 +34,19 @@ #include #include #include +#include -pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int length_) +using google::LogMessage; + +pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int length_, + int n_segments_est, int n_segments_reset) { - return pulse_blanking_cc_sptr(new pulse_blanking_cc(pfa, length_)); + return pulse_blanking_cc_sptr(new pulse_blanking_cc(pfa, length_, n_segments_est, n_segments_reset)); } -pulse_blanking_cc::pulse_blanking_cc(float pfa, int length_) : gr::block("pulse_blanking_cc", +pulse_blanking_cc::pulse_blanking_cc(float pfa, int length_, int n_segments_est, int n_segments_reset) : gr::block("pulse_blanking_cc", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) { @@ -53,8 +57,8 @@ pulse_blanking_cc::pulse_blanking_cc(float pfa, int length_) : gr::block("pulse_ set_output_multiple(length_); last_filtered = false; n_segments = 0; - n_segments_est = 8; - n_segments_reset = 10000; + this->n_segments_est = n_segments_est; + this->n_segments_reset = n_segments_reset; noise_power_estimation = 0.0; n_deg_fred = 2*length_; boost::math::chi_squared_distribution my_dist_(n_deg_fred); @@ -64,13 +68,13 @@ pulse_blanking_cc::pulse_blanking_cc(float pfa, int length_) : gr::block("pulse_ for (int aux = 0; aux < length_; aux++) { zeros_[aux] = gr_complex(0, 0); - } + } } pulse_blanking_cc::~pulse_blanking_cc() { volk_free(zeros_); - volk_free(magnitude); + volk_free(magnitude); } int pulse_blanking_cc::general_work (int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), @@ -87,7 +91,7 @@ int pulse_blanking_cc::general_work (int noutput_items __attribute__((unused)), if((n_segments < n_segments_est) && (last_filtered == false)) { noise_power_estimation = (((float) n_segments) * noise_power_estimation + segment_energy / ((float)n_deg_fred)) / ((float)(n_segments + 1)); - memcpy(out, in, sizeof(gr_complex)*length_); + memcpy(out, in, sizeof(gr_complex)*length_); } else { diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h index 620e4731f..1bb9a7550 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h @@ -38,12 +38,13 @@ class pulse_blanking_cc; typedef boost::shared_ptr pulse_blanking_cc_sptr; -pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int length_); +pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int length_, int n_segments_est, int n_segments_reset); class pulse_blanking_cc : public gr::block { private: + int length_; int n_segments; int n_segments_est; @@ -55,13 +56,16 @@ private: float pfa; float* magnitude; gr_complex* zeros_; + public: - pulse_blanking_cc(float pfa, int length_); + + pulse_blanking_cc(float pfa, int length_, int n_segments_est, int n_segments_reset); ~pulse_blanking_cc(); int general_work (int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + }; #endif From 1e753e5f5479b3ed690848f83be0baebe00aa6b4 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 21 Aug 2017 13:08:33 +0200 Subject: [PATCH 16/22] Adding Single state Notch Filter New Notch_Filter_Lite input filter block --- .../input_filter/adapters/CMakeLists.txt | 1 + .../adapters/notch_filter_lite.cc | 114 ++++++++++++++++++ .../input_filter/adapters/notch_filter_lite.h | 84 +++++++++++++ .../gnuradio_blocks/CMakeLists.txt | 1 + .../gnuradio_blocks/notch_lite_cc.cc | 80 ++++++++++++ .../gnuradio_blocks/notch_lite_cc.h | 66 ++++++++++ 6 files changed, 346 insertions(+) create mode 100644 src/algorithms/input_filter/adapters/notch_filter_lite.cc create mode 100644 src/algorithms/input_filter/adapters/notch_filter_lite.h create mode 100644 src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc create mode 100644 src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h diff --git a/src/algorithms/input_filter/adapters/CMakeLists.txt b/src/algorithms/input_filter/adapters/CMakeLists.txt index 38c35012a..2cee74880 100644 --- a/src/algorithms/input_filter/adapters/CMakeLists.txt +++ b/src/algorithms/input_filter/adapters/CMakeLists.txt @@ -22,6 +22,7 @@ set(INPUT_FILTER_ADAPTER_SOURCES beamformer_filter.cc pulse_blanking_filter.cc notch_filter.cc + notch_filter_lite.cc ) include_directories( diff --git a/src/algorithms/input_filter/adapters/notch_filter_lite.cc b/src/algorithms/input_filter/adapters/notch_filter_lite.cc new file mode 100644 index 000000000..ec2ac636e --- /dev/null +++ b/src/algorithms/input_filter/adapters/notch_filter_lite.cc @@ -0,0 +1,114 @@ +/*! + * \file notch_filter_lite.cc + * \brief Adapts a gnuradio gr_notch_filter_lite + * \author Antonio Ramos, 2017. antonio.ramosdet(at)gmail.com + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * 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 + * (at your option) any later version. + * + * 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 . + * + * ------------------------------------------------------------------------- + */ + +#include "notch_filter_lite.h" +#include +#include +#include +#include +#include +#include +#include "configuration_interface.h" +#include "notch_lite_cc.h" + +using google::LogMessage; + +NotchFilterLite::NotchFilterLite(ConfigurationInterface* configuration, std::string role, + unsigned int in_streams, unsigned int out_streams) : + role_(role), in_streams_(in_streams), + out_streams_(out_streams) +{ + size_t item_size_; + float p_c_factor; + float default_p_c_factor = 0.9; + std::string default_item_type = "gr_complex"; + std::string default_dump_file = "./data/input_filter.dat"; + item_type_ = configuration->property(role + ".item_type", default_item_type); + dump_ = configuration->property(role + ".dump", false); + DLOG(INFO) << "dump_ is " << dump_; + dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); + p_c_factor = configuration->property(role + ".p_c_factor", default_p_c_factor); + if (item_type_.compare("gr_complex") == 0) + { + item_size_ = sizeof(gr_complex); + notch_filter_lite_ = make_notch_filter_lite(p_c_factor); + DLOG(INFO) << "Item size " << item_size_; + DLOG(INFO) << "input filter(" << notch_filter_lite_->unique_id() << ")"; + + } + else + { + LOG(WARNING) << item_type_ + << " unrecognized item type for notch filter"; + item_size_ = sizeof(gr_complex); + } + if (dump_) + { + DLOG(INFO) << "Dumping output into file " << dump_filename_; + file_sink_ = gr::blocks::file_sink::make(item_size_, dump_filename_.c_str()); + DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")"; + } +} + +NotchFilterLite::~NotchFilterLite() +{} + +void NotchFilterLite::connect(gr::top_block_sptr top_block) +{ + if (dump_) + { + top_block->connect(notch_filter_lite_, 0, file_sink_, 0); + DLOG(INFO) << "connected notch filter output to file sink"; + } + else + { + DLOG(INFO) << "nothing to connect internally"; + } +} + +void NotchFilterLite::disconnect(gr::top_block_sptr top_block) +{ + if (dump_) + { + top_block->disconnect(notch_filter_lite_, 0, file_sink_, 0); + } +} + + +gr::basic_block_sptr NotchFilterLite::get_left_block() +{ + return notch_filter_lite_; +} + +gr::basic_block_sptr NotchFilterLite::get_right_block() +{ + return notch_filter_lite_; +} diff --git a/src/algorithms/input_filter/adapters/notch_filter_lite.h b/src/algorithms/input_filter/adapters/notch_filter_lite.h new file mode 100644 index 000000000..03796f319 --- /dev/null +++ b/src/algorithms/input_filter/adapters/notch_filter_lite.h @@ -0,0 +1,84 @@ +/*! + * \file notch_filter_lite.h + * \brief + * \author Antonio Ramos, 2017. antonio.ramosdet(at)gmail.com + * + * Detailed description of the file here if needed. + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * 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 + * (at your option) any later version. + * + * 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 . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_NOTCH_FILTER_LITE_H_ +#define GNSS_SDR_NOTCH_FILTER_LITE_H_ + +#include +#include +#include +#include "gnss_block_interface.h" +#include "notch_lite_cc.h" + + +class ConfigurationInterface; + +class NotchFilterLite: public GNSSBlockInterface +{ +public: + NotchFilterLite(ConfigurationInterface* configuration, + std::string role, unsigned int in_streams, + unsigned int out_streams); + + virtual ~NotchFilterLite(); + std::string role() + { + return role_; + } + + //! Returns "Notch_Filter_Lite" + std::string implementation() + { + return "Notch_Filter_Lite"; + } + size_t item_size() + { + return 0; + } + void connect(gr::top_block_sptr top_block); + void disconnect(gr::top_block_sptr top_block); + gr::basic_block_sptr get_left_block(); + gr::basic_block_sptr get_right_block(); + +private: + + bool dump_; + std::string dump_filename_; + std::string role_; + std::string item_type_; + unsigned int in_streams_; + unsigned int out_streams_; + gr::blocks::file_sink::sptr file_sink_; + notch_lite_sptr notch_filter_lite_; +}; + +#endif //GNSS_SDR_NOTCH_FILTER_LITE_H_ diff --git a/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt b/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt index 718ac1c9a..b0ce4a55e 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt @@ -21,6 +21,7 @@ set(INPUT_FILTER_GR_BLOCKS_SOURCES beamformer.cc pulse_blanking_cc.cc notch_cc.cc + notch_lite_cc.cc ) include_directories( diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc new file mode 100644 index 000000000..4b21bf33e --- /dev/null +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc @@ -0,0 +1,80 @@ +/*! + * \file notch_lite_cc.cc + * \brief Implements a multi state notch filter algorithm + * \author Antonio Ramos (antonio.ramosdet(at)gmail.com) + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * 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 + * (at your option) any later version. + * + * 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 . + * + * ------------------------------------------------------------------------- + */ + +#include "notch_lite_cc.h" +#include +#include +#include +#include +#include +#include +#include +#include + +using google::LogMessage; + +notch_lite_sptr make_notch_filter_lite(float p_c_factor) +{ + return notch_lite_sptr(new NotchLite(p_c_factor)); +} + +NotchLite::NotchLite(float p_c_factor) : gr::block("NotchLite", + gr::io_signature::make (1, 1, sizeof(gr_complex)), + gr::io_signature::make (1, 1, sizeof(gr_complex))) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); + set_history(2); + this->p_c_factor = gr_complex(p_c_factor , 0); + z_0 = gr_complex(0 , 0); + last_out = gr_complex(0,0); +} + +int NotchLite::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), + gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) +{ + gr_complex* in = (gr_complex *) input_items[0]; + gr_complex* out = (gr_complex *) output_items[0]; + c_samples = static_cast(volk_malloc(noutput_items * sizeof(gr_complex), volk_get_alignment())); + angle_ = static_cast(volk_malloc(noutput_items * sizeof(float), volk_get_alignment())); + + volk_32fc_x2_multiply_conjugate_32fc(c_samples, (in + 1), in, noutput_items); + volk_32fc_s32f_atan2_32f(angle_, c_samples, ((float)1.0), noutput_items); + for (int aux = 0; aux < noutput_items; aux++) + { + z_0 = std::exp(gr_complex(0,1) * (*(angle_ + aux))); + *(out + aux) = *(in + aux + 1) - z_0 * (*(in + aux)) + p_c_factor * z_0 * last_out; + last_out = *(out + aux); + } + volk_free(c_samples); + volk_free(angle_); + consume_each(noutput_items); + return noutput_items; +} diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h new file mode 100644 index 000000000..16f56286d --- /dev/null +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h @@ -0,0 +1,66 @@ +/*! + * \file notch_lite_cc.h + * \brief Implements a notch filter algorithm + * \author Antonio Ramos (antonio.ramosdet(at)gmail.com) + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * 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 + * (at your option) any later version. + * + * 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 . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_NOTCH_LITE_H_ +#define GNSS_SDR_NOTCH_LITE_H_ + +#include +#include + +class NotchLite; + +typedef boost::shared_ptr notch_lite_sptr; + +notch_lite_sptr make_notch_filter_lite(float p_c_factor); + +/*! + * \brief This class implements a real-time software-defined single state notch filter + */ + +class NotchLite : public gr::block +{ +private: + + gr_complex last_out; + gr_complex z_0; + gr_complex p_c_factor; + gr_complex* c_samples; + float* angle_; + +public: + + NotchLite(float p_c_factor); + + int general_work (int noutput_items, gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif //GNSS_SDR_NOTCH_LITE_H_ From e1dc9f5aac6799f9cb118585bb4cb6092ed89205 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 21 Aug 2017 13:11:18 +0200 Subject: [PATCH 17/22] Improving real-time performances of input filters Pulse blanking and Notch filters improved --- .../adapters/pulse_blanking_filter.cc | 8 +- .../input_filter/gnuradio_blocks/notch_cc.cc | 94 ++++++++----------- .../gnuradio_blocks/pulse_blanking_cc.cc | 12 +-- .../gnuradio_blocks/pulse_blanking_cc.h | 1 - src/core/receiver/gnss_block_factory.cc | 7 ++ 5 files changed, 56 insertions(+), 66 deletions(-) diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc index cedad7741..fed7205cc 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc @@ -52,13 +52,13 @@ PulseBlankingFilter::PulseBlankingFilter(ConfigurationInterface* configuration, output_item_type_ = config_->property(role_ + ".output_item_type", default_output_item_type); dump_ = config_->property(role_ + ".dump", false); dump_filename_ = config_->property(role_ + ".dump_filename", default_dump_filename); - float default_pfa_ = 0.01; + float default_pfa_ = 0.04; float pfa = config_->property(role_ + ".pfa", default_pfa_); - int default_length_ = 16; + int default_length_ = 32; int length_ = config_->property(role_ + ".length", default_length_); - int default_n_segments_est = 25000; + int default_n_segments_est = 12500; int n_segments_est = config_->property(role_ + ".segments_estimation", default_n_segments_est); - int default_n_segments_reset = 500000; + int default_n_segments_reset = 5000000; int n_segments_reset = config_->property(role_ + ".segments_reset", default_n_segments_reset); if (input_item_type_.compare("gr_complex") == 0) { diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index 8c79d3b50..007b3d9b3 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -84,75 +84,61 @@ Notch::~Notch() int Notch::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - - int index_in = 1; int index_out = 0; - int aux = 0; float sig2dB = 0.0; float sig2lin = 0.0; lv_32fc_t dot_prod_; gr_complex* in = (gr_complex *) input_items[0]; gr_complex* out = (gr_complex *) output_items[0]; - gr_complex* paux; in++; arma::cx_fvec signal_segment; arma::cx_fvec signal_segment_fft; - while(((index_out + length_) < noutput_items) && (n_segments < n_segments_est) && (filter_state_ == false)) + while((index_out + length_) < noutput_items) { - signal_segment = arma::cx_fvec(in, length_, false, false); - signal_segment_fft = arma::fft(signal_segment); - volk_32fc_s32f_power_spectrum_32f(power_spect, signal_segment_fft.memptr(), 1.0, length_); - volk_32f_s32f_calc_spectral_noise_floor_32f(&sig2dB, power_spect, 15.0, length_); - sig2lin = std::pow(10.0, (sig2dB / 10.0)) / ((float) n_deg_fred); - noise_pow_est = (((float) n_segments) * noise_pow_est + sig2lin) / ((float)(n_segments + 1)); - memcpy(out, in, sizeof(gr_complex) * length_); + if((n_segments < n_segments_est) && (filter_state_ == false)) + { + signal_segment = arma::cx_fvec(in, length_, false, false); + signal_segment_fft = arma::fft(signal_segment); + volk_32fc_s32f_power_spectrum_32f(power_spect, signal_segment_fft.memptr(), 1.0, length_); + volk_32f_s32f_calc_spectral_noise_floor_32f(&sig2dB, power_spect, 15.0, length_); + sig2lin = std::pow(10.0, (sig2dB / 10.0)) / ((float) n_deg_fred); + noise_pow_est = (((float) n_segments) * noise_pow_est + sig2lin) / ((float)(n_segments + 1)); + memcpy(out, in, sizeof(gr_complex) * length_); + } + else + { + volk_32fc_x2_conjugate_dot_prod_32fc(&dot_prod_, in, in, length_); + if( (lv_creal(dot_prod_) / noise_pow_est) > thres_) + { + if(filter_state_ == false) + { + filter_state_ = true; + last_out = gr_complex(0,0); + } + volk_32fc_x2_multiply_conjugate_32fc(c_samples, in, (in - 1), length_); + volk_32fc_s32f_atan2_32f(angle_, c_samples, ((float)1.0), length_); + for(int aux = 0; aux < length_; aux++) + { + z_0 = std::exp(gr_complex(0,1) * (*(angle_ + aux))); + *(out + aux) = *(in + aux) - z_0 * (*(in + aux - 1)) + p_c_factor * z_0 * last_out; + last_out = *(out + aux); + } + } + else + { + if (n_segments > n_segments_reset) + { + n_segments = 0; + } + filter_state_ = false; + memcpy(out, in, sizeof(gr_complex) * length_); + } + } index_out += length_; - index_in += length_; n_segments++; in += length_; out += length_; } - while((index_out + length_) < noutput_items) - { - n_segments++; - volk_32fc_x2_conjugate_dot_prod_32fc(&dot_prod_, in, in, length_); - if( (lv_creal(dot_prod_) / noise_pow_est) > thres_) - { - if(filter_state_ == false) - { - filter_state_ = true; - last_out = gr_complex(0,0); - } - paux = in - 1; - volk_32fc_x2_multiply_conjugate_32fc(c_samples, in, paux, length_); - volk_32fc_s32f_atan2_32f(angle_, c_samples, ((float)1.0), length_); - for(aux = 0; aux < length_; aux++) - { - z_0 = std::exp(gr_complex(0,1) * (*(angle_ + aux))); - *out = (*in) - z_0 * (*(in - 1)) - + p_c_factor * z_0 * last_out; - last_out = *out; - index_out++; - index_in++; - in ++; - out ++; - } - - } - else - { - if (n_segments > n_segments_reset) - { - n_segments = 0; - } - filter_state_ = false; - memcpy(out, in, sizeof(gr_complex) * length_); - index_out += length_; - index_in += length_; - in += length_; - out += length_; - } - } consume_each(index_out); return index_out; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc index ec758e511..a744f8747 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc @@ -44,8 +44,6 @@ pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int length_, return pulse_blanking_cc_sptr(new pulse_blanking_cc(pfa, length_, n_segments_est, n_segments_reset)); } - - pulse_blanking_cc::pulse_blanking_cc(float pfa, int length_, int n_segments_est, int n_segments_reset) : gr::block("pulse_blanking_cc", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) @@ -64,7 +62,6 @@ pulse_blanking_cc::pulse_blanking_cc(float pfa, int length_, int n_segments_est, boost::math::chi_squared_distribution my_dist_(n_deg_fred); thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); zeros_ = static_cast(volk_malloc(length_ * sizeof(gr_complex), volk_get_alignment())); - magnitude = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); for (int aux = 0; aux < length_; aux++) { zeros_[aux] = gr_complex(0, 0); @@ -73,8 +70,7 @@ pulse_blanking_cc::pulse_blanking_cc(float pfa, int length_, int n_segments_est, pulse_blanking_cc::~pulse_blanking_cc() { - volk_free(zeros_); - volk_free(magnitude); + volk_free(zeros_); } int pulse_blanking_cc::general_work (int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), @@ -82,12 +78,13 @@ int pulse_blanking_cc::general_work (int noutput_items __attribute__((unused)), { gr_complex *in = (gr_complex *) input_items[0]; gr_complex *out = (gr_complex *) output_items[0]; + float* magnitude = static_cast(volk_malloc(noutput_items * sizeof(float), volk_get_alignment())); + volk_32fc_magnitude_squared_32f(magnitude, in, noutput_items); int sample_index = 0; float segment_energy; while((sample_index + length_) < noutput_items) { - volk_32fc_magnitude_squared_32f(magnitude, in, length_); - volk_32f_accumulator_s32f(&segment_energy, magnitude, length_); + volk_32f_accumulator_s32f(&segment_energy, (magnitude + sample_index), length_); if((n_segments < n_segments_est) && (last_filtered == false)) { noise_power_estimation = (((float) n_segments) * noise_power_estimation + segment_energy / ((float)n_deg_fred)) / ((float)(n_segments + 1)); @@ -115,6 +112,7 @@ int pulse_blanking_cc::general_work (int noutput_items __attribute__((unused)), sample_index+=length_; n_segments++; } + volk_free(magnitude); consume_each(sample_index); return sample_index; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h index 1bb9a7550..a77cf4deb 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h @@ -54,7 +54,6 @@ private: float noise_power_estimation; float thres_; float pfa; - float* magnitude; gr_complex* zeros_; public: diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index cac56293a..6efe76db5 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -66,6 +66,7 @@ #include "beamformer_filter.h" #include "pulse_blanking_filter.h" #include "notch_filter.h" +#include "notch_filter_lite.h" #include "gps_l1_ca_pcps_acquisition.h" #include "gps_l2_m_pcps_acquisition.h" #include "gps_l1_ca_pcps_multithread_acquisition.h" @@ -889,6 +890,12 @@ std::unique_ptr GNSSBlockFactory::GetBlock( out_streams)); block = std::move(block_); } + else if (implementation.compare("Notch_Filter_Lite") == 0) + { + std::unique_ptr block_(new NotchFilterLite(configuration.get(), role, in_streams, + out_streams)); + block = std::move(block_); + } // RESAMPLER ------------------------------------------------------------------- From a18c3467a18661f9f1b17176f73a7ea75e39a5cc Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Tue, 22 Aug 2017 13:21:28 +0200 Subject: [PATCH 18/22] Improved Notch Filter Lite Updated version of the filter --- .../input_filter/adapters/notch_filter.cc | 8 +- .../adapters/notch_filter_lite.cc | 23 +++- .../input_filter/gnuradio_blocks/notch_cc.cc | 10 +- .../input_filter/gnuradio_blocks/notch_cc.h | 4 +- .../gnuradio_blocks/notch_lite_cc.cc | 105 +++++++++++++++--- .../gnuradio_blocks/notch_lite_cc.h | 24 +++- 6 files changed, 142 insertions(+), 32 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc index a69c0c9c0..405f1f430 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.cc +++ b/src/algorithms/input_filter/adapters/notch_filter.cc @@ -53,6 +53,10 @@ NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role float default_p_c_factor = 0.9; int length_; int default_length_ = 32; + int n_segments_est; + int default_n_segments_est = 12500; + int n_segments_reset; + int default_n_segments_reset = 5000000; std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/input_filter.dat"; item_type_ = configuration->property(role + ".item_type", default_item_type); @@ -62,10 +66,12 @@ NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role pfa = configuration->property(role + ".pfa", default_pfa); p_c_factor = configuration->property(role + ".p_c_factor", default_p_c_factor); length_ = configuration->property(role + ".length", default_length_); + n_segments_est = configuration->property(role + ".segments_est", default_n_segments_est); + n_segments_reset = configuration->property(role + ".segments_reset", default_n_segments_reset); if (item_type_.compare("gr_complex") == 0) { item_size_ = sizeof(gr_complex); - notch_filter_ = make_notch_filter(pfa, p_c_factor, length_); + notch_filter_ = make_notch_filter(pfa, p_c_factor, length_, n_segments_est, n_segments_reset); DLOG(INFO) << "Item size " << item_size_; DLOG(INFO) << "input filter(" << notch_filter_->unique_id() << ")"; diff --git a/src/algorithms/input_filter/adapters/notch_filter_lite.cc b/src/algorithms/input_filter/adapters/notch_filter_lite.cc index ec2ac636e..a91aa39e6 100644 --- a/src/algorithms/input_filter/adapters/notch_filter_lite.cc +++ b/src/algorithms/input_filter/adapters/notch_filter_lite.cc @@ -31,6 +31,7 @@ #include "notch_filter_lite.h" #include +#include #include #include #include @@ -49,6 +50,18 @@ NotchFilterLite::NotchFilterLite(ConfigurationInterface* configuration, std::str size_t item_size_; float p_c_factor; float default_p_c_factor = 0.9; + float pfa; + float default_pfa = 0.001; + int length_; + int default_length_ = 32; + int n_segments_est; + int default_n_segments_est = 12500; + int n_segments_reset; + int default_n_segments_reset = 5000000; + float default_samp_freq = 4000000; + float samp_freq = configuration->property("SignalSource.sampling_frequency", default_samp_freq); + float default_coeff_rate = samp_freq * 0.1; + float coeff_rate; std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/input_filter.dat"; item_type_ = configuration->property(role + ".item_type", default_item_type); @@ -56,13 +69,19 @@ NotchFilterLite::NotchFilterLite(ConfigurationInterface* configuration, std::str DLOG(INFO) << "dump_ is " << dump_; dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); p_c_factor = configuration->property(role + ".p_c_factor", default_p_c_factor); + pfa = configuration->property(role + ".pfa", default_pfa); + coeff_rate = configuration->property(role + ".coeff_rate", default_coeff_rate); + length_ = configuration->property(role + ".length", default_length_); + n_segments_est = configuration->property(role + ".segments_est", default_n_segments_est); + n_segments_reset = configuration->property(role + ".segments_reset", default_n_segments_reset); + int n_segments_coeff = (int) ((samp_freq / coeff_rate) / ((float) length_)); + n_segments_coeff = std::max(1, n_segments_coeff); if (item_type_.compare("gr_complex") == 0) { item_size_ = sizeof(gr_complex); - notch_filter_lite_ = make_notch_filter_lite(p_c_factor); + notch_filter_lite_ = make_notch_filter_lite(p_c_factor, pfa, length_, n_segments_est, n_segments_reset, n_segments_coeff); DLOG(INFO) << "Item size " << item_size_; DLOG(INFO) << "input filter(" << notch_filter_lite_->unique_id() << ")"; - } else { diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index 007b3d9b3..700ccfea8 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -43,12 +43,12 @@ using google::LogMessage; notch_sptr make_notch_filter(float pfa, float p_c_factor, - int length_) + int length_, int n_segments_est, int n_segments_reset) { - return notch_sptr(new Notch(pfa, p_c_factor, length_)); + return notch_sptr(new Notch(pfa, p_c_factor, length_, n_segments_est, n_segments_reset)); } -Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", +Notch::Notch(float pfa, float p_c_factor, int length_, int n_segments_est, int n_segments_reset) : gr::block("Notch", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) { @@ -63,8 +63,8 @@ Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", filter_state_ = false; //Initial state of the filter n_deg_fred = 2 * length_; //Number of dregrees of freedom n_segments = 0; - n_segments_est = 8; // Set the number of segments for noise power estimation - n_segments_reset = 10000; // Set the period (in segments) when the noise power is estimated + this->n_segments_est = n_segments_est; // Set the number of segments for noise power estimation + this->n_segments_reset = n_segments_reset; // Set the period (in segments) when the noise power is estimated z_0 = gr_complex(0 , 0); boost::math::chi_squared_distribution my_dist_(n_deg_fred); thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index faf7c5d0c..5be7dfda6 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -39,7 +39,7 @@ class Notch; typedef boost::shared_ptr notch_sptr; notch_sptr make_notch_filter(float pfa, float p_c_factor, - int length_); + int length_, int n_segments_est, int n_segments_reset); /*! * \brief This class implements a real-time software-defined multi state notch filter @@ -67,7 +67,7 @@ private: public: - Notch(float pfa, float p_c_factor, int length_); + Notch(float pfa, float p_c_factor, int length_, int n_segments_est, int n_segments_reset); ~Notch(); diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc index 4b21bf33e..3ce19f656 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc @@ -37,15 +37,17 @@ #include #include #include +#include +#include using google::LogMessage; -notch_lite_sptr make_notch_filter_lite(float p_c_factor) +notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff) { - return notch_lite_sptr(new NotchLite(p_c_factor)); + return notch_lite_sptr(new NotchLite(p_c_factor, pfa, length_, n_segments_est, n_segments_reset, n_segments_coeff)); } -NotchLite::NotchLite(float p_c_factor) : gr::block("NotchLite", +NotchLite::NotchLite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff) : gr::block("NotchLite", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) { @@ -53,28 +55,97 @@ NotchLite::NotchLite(float p_c_factor) : gr::block("NotchLite", set_alignment(std::max(1, alignment_multiple)); set_history(2); this->p_c_factor = gr_complex(p_c_factor , 0); + this->n_segments_est = n_segments_est; + this->n_segments_reset = n_segments_reset; + this->n_segments_coeff_reset = n_segments_coeff; + this->n_segments_coeff = 0; + this->length_ = length_; + set_output_multiple(length_); + this->pfa = pfa; + n_segments = 0; + n_deg_fred = 2 * length_; + noise_pow_est = 0.0; + filter_state_ = false; z_0 = gr_complex(0 , 0); - last_out = gr_complex(0,0); + last_out = gr_complex(0, 0); + boost::math::chi_squared_distribution my_dist_(n_deg_fred); + thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); + c_samples = gr_complex(0, 0); + angle_ = 0.0; + power_spect = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); + } +NotchLite::~NotchLite() +{ + volk_free(power_spect); +} + + int NotchLite::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { + int index_out = 0; + float sig2dB = 0.0; + float sig2lin = 0.0; + lv_32fc_t dot_prod_; gr_complex* in = (gr_complex *) input_items[0]; gr_complex* out = (gr_complex *) output_items[0]; - c_samples = static_cast(volk_malloc(noutput_items * sizeof(gr_complex), volk_get_alignment())); - angle_ = static_cast(volk_malloc(noutput_items * sizeof(float), volk_get_alignment())); - - volk_32fc_x2_multiply_conjugate_32fc(c_samples, (in + 1), in, noutput_items); - volk_32fc_s32f_atan2_32f(angle_, c_samples, ((float)1.0), noutput_items); - for (int aux = 0; aux < noutput_items; aux++) + in++; + arma::cx_fvec signal_segment; + arma::cx_fvec signal_segment_fft; + while((index_out + length_) < noutput_items) { - z_0 = std::exp(gr_complex(0,1) * (*(angle_ + aux))); - *(out + aux) = *(in + aux + 1) - z_0 * (*(in + aux)) + p_c_factor * z_0 * last_out; - last_out = *(out + aux); + if((n_segments < n_segments_est) && (filter_state_ == false)) + { + signal_segment = arma::cx_fvec(in, length_, false, false); + signal_segment_fft = arma::fft(signal_segment); + volk_32fc_s32f_power_spectrum_32f(power_spect, signal_segment_fft.memptr(), 1.0, length_); + volk_32f_s32f_calc_spectral_noise_floor_32f(&sig2dB, power_spect, 15.0, length_); + sig2lin = std::pow(10.0, (sig2dB / 10.0)) / ((float) n_deg_fred); + noise_pow_est = (((float) n_segments) * noise_pow_est + sig2lin) / ((float)(n_segments + 1)); + memcpy(out, in, sizeof(gr_complex) * length_); + } + else + { + volk_32fc_x2_conjugate_dot_prod_32fc(&dot_prod_, in, in, length_); + if( (lv_creal(dot_prod_) / noise_pow_est) > thres_) + { + if(filter_state_ == false) + { + filter_state_ = true; + last_out = gr_complex(0,0); + n_segments_coeff = 0; + } + if(n_segments_coeff == 0) + { + volk_32fc_x2_multiply_conjugate_32fc(&c_samples, in, (in - 1), 1); + volk_32fc_s32f_atan2_32f(&angle_, &c_samples, ((float)1.0), 1); + z_0 = std::exp(gr_complex(0,1) * angle_); + } + for(int aux = 0; aux < length_; aux++) + { + *(out + aux) = *(in + aux) - z_0 * (*(in + aux - 1)) + p_c_factor * z_0 * last_out; + last_out = *(out + aux); + } + n_segments_coeff++; + n_segments_coeff = n_segments_coeff % n_segments_coeff_reset; + } + else + { + if (n_segments > n_segments_reset) + { + n_segments = 0; + } + filter_state_ = false; + memcpy(out, in, sizeof(gr_complex) * length_); + } + } + index_out += length_; + n_segments++; + in += length_; + out += length_; } - volk_free(c_samples); - volk_free(angle_); - consume_each(noutput_items); - return noutput_items; + consume_each(index_out); + return index_out; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h index 16f56286d..64dcb8d53 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h @@ -38,7 +38,7 @@ class NotchLite; typedef boost::shared_ptr notch_lite_sptr; -notch_lite_sptr make_notch_filter_lite(float p_c_factor); +notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff); /*! * \brief This class implements a real-time software-defined single state notch filter @@ -48,15 +48,29 @@ class NotchLite : public gr::block { private: + int length_; + int n_segments; + int n_segments_est; + int n_segments_reset; + int n_segments_coeff_reset; + int n_segments_coeff; + int n_deg_fred; + float pfa; + float thres_; + float noise_pow_est; + bool filter_state_; gr_complex last_out; gr_complex z_0; gr_complex p_c_factor; - gr_complex* c_samples; - float* angle_; - + gr_complex c_samples; + float angle_; + float* power_spect; + public: - NotchLite(float p_c_factor); + NotchLite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff); + + ~NotchLite(); int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, From 0441f3c24c57601ebb21a09a7513e7aac4165d16 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Thu, 24 Aug 2017 19:21:24 +0200 Subject: [PATCH 19/22] Minor changes Changing some variable names --- src/algorithms/input_filter/adapters/notch_filter.h | 2 +- .../input_filter/adapters/notch_filter_lite.h | 2 +- .../input_filter/adapters/pulse_blanking_filter.cc | 4 ++-- .../input_filter/adapters/pulse_blanking_filter.h | 1 + .../input_filter/gnuradio_blocks/notch_lite_cc.cc | 13 +++++++++---- .../input_filter/gnuradio_blocks/notch_lite_cc.h | 10 ++++++---- .../gnuradio_blocks/pulse_blanking_cc.cc | 4 ++-- .../gnuradio_blocks/pulse_blanking_cc.h | 4 ++-- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index 09ac10e99..a8ab2136b 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -1,6 +1,6 @@ /*! * \file notch_filter.h - * \brief + * \brief Adapter of a multistate Notch filter * \author Antonio Ramos, 2017. antonio.ramosdet(at)gmail.com * * Detailed description of the file here if needed. diff --git a/src/algorithms/input_filter/adapters/notch_filter_lite.h b/src/algorithms/input_filter/adapters/notch_filter_lite.h index 03796f319..f9088db52 100644 --- a/src/algorithms/input_filter/adapters/notch_filter_lite.h +++ b/src/algorithms/input_filter/adapters/notch_filter_lite.h @@ -1,6 +1,6 @@ /*! * \file notch_filter_lite.h - * \brief + * \brief Adapts a ligth version of a multistate notch filter * \author Antonio Ramos, 2017. antonio.ramosdet(at)gmail.com * * Detailed description of the file here if needed. diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc index fed7205cc..0786f3f3e 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc @@ -2,7 +2,7 @@ * \file pulse_blanking_filter.cc * \brief Instantiates the GNSS-SDR pulse blanking filter * \author Javier Arribas 2017 - * + * Antonio Ramos 2017 * ------------------------------------------------------------------------- * * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) @@ -57,7 +57,7 @@ PulseBlankingFilter::PulseBlankingFilter(ConfigurationInterface* configuration, int default_length_ = 32; int length_ = config_->property(role_ + ".length", default_length_); int default_n_segments_est = 12500; - int n_segments_est = config_->property(role_ + ".segments_estimation", default_n_segments_est); + int n_segments_est = config_->property(role_ + ".segments_est", default_n_segments_est); int default_n_segments_reset = 5000000; int n_segments_reset = config_->property(role_ + ".segments_reset", default_n_segments_reset); if (input_item_type_.compare("gr_complex") == 0) diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h index 041ba2251..c57c68d10 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h @@ -2,6 +2,7 @@ * \file pulse_blanking_filter.h * \brief Instantiates the GNSS-SDR pulse blanking filter * \author Javier Arribas 2017 + * Antonio Ramos 2017 * * ------------------------------------------------------------------------- * diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc index 3ce19f656..a84ec6ae6 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc @@ -70,8 +70,10 @@ NotchLite::NotchLite(float p_c_factor, float pfa, int length_, int n_segments_es last_out = gr_complex(0, 0); boost::math::chi_squared_distribution my_dist_(n_deg_fred); thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); - c_samples = gr_complex(0, 0); - angle_ = 0.0; + c_samples1 = gr_complex(0, 0); + c_samples2 = gr_complex(0, 0); + angle1 = 0.0; + angle2 = 0.0; power_spect = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); } @@ -119,8 +121,11 @@ int NotchLite::general_work(int noutput_items __attribute__((unused)), gr_vector } if(n_segments_coeff == 0) { - volk_32fc_x2_multiply_conjugate_32fc(&c_samples, in, (in - 1), 1); - volk_32fc_s32f_atan2_32f(&angle_, &c_samples, ((float)1.0), 1); + volk_32fc_x2_multiply_conjugate_32fc(&c_samples1, (in + 1), in, 1); + volk_32fc_s32f_atan2_32f(&angle1, &c_samples1, ((float)1.0), 1); + volk_32fc_x2_multiply_conjugate_32fc(&c_samples2, (in + length_ - 1), (in + length_ - 2), 1); + volk_32fc_s32f_atan2_32f(&angle2, &c_samples2, ((float)1.0), 1); + float angle_ = (angle1 + angle2) / 2.0; z_0 = std::exp(gr_complex(0,1) * angle_); } for(int aux = 0; aux < length_; aux++) diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h index 64dcb8d53..2151a459f 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h @@ -1,6 +1,6 @@ /*! * \file notch_lite_cc.h - * \brief Implements a notch filter algorithm + * \brief Implements a notch filter ligth algorithm * \author Antonio Ramos (antonio.ramosdet(at)gmail.com) * * ------------------------------------------------------------------------- @@ -41,7 +41,7 @@ typedef boost::shared_ptr notch_lite_sptr; notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff); /*! - * \brief This class implements a real-time software-defined single state notch filter + * \brief This class implements a real-time software-defined multi state notch filter ligth version */ class NotchLite : public gr::block @@ -62,8 +62,10 @@ private: gr_complex last_out; gr_complex z_0; gr_complex p_c_factor; - gr_complex c_samples; - float angle_; + gr_complex c_samples1; + gr_complex c_samples2; + float angle1; + float angle2; float* power_spect; public: diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc index a744f8747..7924f17ba 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc @@ -1,8 +1,8 @@ /*! * \file pulse_blanking_cc.cc - * \brief Implements a simple pulse blanking algorithm + * \brief Implements a pulse blanking algorithm * \author Javier Arribas (jarribas(at)cttc.es) - * + * Antonio Ramos (antonio.ramosdet(at)gmail.com) * ------------------------------------------------------------------------- * * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h index a77cf4deb..7a19bf74e 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h @@ -1,8 +1,8 @@ /*! * \file pulse_blanking_cc.h - * \brief Implements a simple pulse blanking algorithm + * \brief Implements a pulse blanking algorithm * \author Javier Arribas (jarribas(at)cttc.es) - * + * Antonio Ramos (antonio.ramosdet(at)gmail.com) * ------------------------------------------------------------------------- * * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) From 3536bce55cd2420dce027de0643d76fc9a37728b Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Tue, 22 Aug 2017 13:21:28 +0200 Subject: [PATCH 20/22] Improved Notch Filter Lite Updated version of the filter --- .../input_filter/adapters/notch_filter.cc | 8 +- .../adapters/notch_filter_lite.cc | 23 +++- .../input_filter/gnuradio_blocks/notch_cc.cc | 10 +- .../input_filter/gnuradio_blocks/notch_cc.h | 4 +- .../gnuradio_blocks/notch_lite_cc.cc | 105 +++++++++++++++--- .../gnuradio_blocks/notch_lite_cc.h | 24 +++- 6 files changed, 142 insertions(+), 32 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.cc b/src/algorithms/input_filter/adapters/notch_filter.cc index a69c0c9c0..405f1f430 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.cc +++ b/src/algorithms/input_filter/adapters/notch_filter.cc @@ -53,6 +53,10 @@ NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role float default_p_c_factor = 0.9; int length_; int default_length_ = 32; + int n_segments_est; + int default_n_segments_est = 12500; + int n_segments_reset; + int default_n_segments_reset = 5000000; std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/input_filter.dat"; item_type_ = configuration->property(role + ".item_type", default_item_type); @@ -62,10 +66,12 @@ NotchFilter::NotchFilter(ConfigurationInterface* configuration, std::string role pfa = configuration->property(role + ".pfa", default_pfa); p_c_factor = configuration->property(role + ".p_c_factor", default_p_c_factor); length_ = configuration->property(role + ".length", default_length_); + n_segments_est = configuration->property(role + ".segments_est", default_n_segments_est); + n_segments_reset = configuration->property(role + ".segments_reset", default_n_segments_reset); if (item_type_.compare("gr_complex") == 0) { item_size_ = sizeof(gr_complex); - notch_filter_ = make_notch_filter(pfa, p_c_factor, length_); + notch_filter_ = make_notch_filter(pfa, p_c_factor, length_, n_segments_est, n_segments_reset); DLOG(INFO) << "Item size " << item_size_; DLOG(INFO) << "input filter(" << notch_filter_->unique_id() << ")"; diff --git a/src/algorithms/input_filter/adapters/notch_filter_lite.cc b/src/algorithms/input_filter/adapters/notch_filter_lite.cc index ec2ac636e..a91aa39e6 100644 --- a/src/algorithms/input_filter/adapters/notch_filter_lite.cc +++ b/src/algorithms/input_filter/adapters/notch_filter_lite.cc @@ -31,6 +31,7 @@ #include "notch_filter_lite.h" #include +#include #include #include #include @@ -49,6 +50,18 @@ NotchFilterLite::NotchFilterLite(ConfigurationInterface* configuration, std::str size_t item_size_; float p_c_factor; float default_p_c_factor = 0.9; + float pfa; + float default_pfa = 0.001; + int length_; + int default_length_ = 32; + int n_segments_est; + int default_n_segments_est = 12500; + int n_segments_reset; + int default_n_segments_reset = 5000000; + float default_samp_freq = 4000000; + float samp_freq = configuration->property("SignalSource.sampling_frequency", default_samp_freq); + float default_coeff_rate = samp_freq * 0.1; + float coeff_rate; std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/input_filter.dat"; item_type_ = configuration->property(role + ".item_type", default_item_type); @@ -56,13 +69,19 @@ NotchFilterLite::NotchFilterLite(ConfigurationInterface* configuration, std::str DLOG(INFO) << "dump_ is " << dump_; dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); p_c_factor = configuration->property(role + ".p_c_factor", default_p_c_factor); + pfa = configuration->property(role + ".pfa", default_pfa); + coeff_rate = configuration->property(role + ".coeff_rate", default_coeff_rate); + length_ = configuration->property(role + ".length", default_length_); + n_segments_est = configuration->property(role + ".segments_est", default_n_segments_est); + n_segments_reset = configuration->property(role + ".segments_reset", default_n_segments_reset); + int n_segments_coeff = (int) ((samp_freq / coeff_rate) / ((float) length_)); + n_segments_coeff = std::max(1, n_segments_coeff); if (item_type_.compare("gr_complex") == 0) { item_size_ = sizeof(gr_complex); - notch_filter_lite_ = make_notch_filter_lite(p_c_factor); + notch_filter_lite_ = make_notch_filter_lite(p_c_factor, pfa, length_, n_segments_est, n_segments_reset, n_segments_coeff); DLOG(INFO) << "Item size " << item_size_; DLOG(INFO) << "input filter(" << notch_filter_lite_->unique_id() << ")"; - } else { diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc index 007b3d9b3..700ccfea8 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.cc @@ -43,12 +43,12 @@ using google::LogMessage; notch_sptr make_notch_filter(float pfa, float p_c_factor, - int length_) + int length_, int n_segments_est, int n_segments_reset) { - return notch_sptr(new Notch(pfa, p_c_factor, length_)); + return notch_sptr(new Notch(pfa, p_c_factor, length_, n_segments_est, n_segments_reset)); } -Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", +Notch::Notch(float pfa, float p_c_factor, int length_, int n_segments_est, int n_segments_reset) : gr::block("Notch", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) { @@ -63,8 +63,8 @@ Notch::Notch(float pfa, float p_c_factor, int length_) : gr::block("Notch", filter_state_ = false; //Initial state of the filter n_deg_fred = 2 * length_; //Number of dregrees of freedom n_segments = 0; - n_segments_est = 8; // Set the number of segments for noise power estimation - n_segments_reset = 10000; // Set the period (in segments) when the noise power is estimated + this->n_segments_est = n_segments_est; // Set the number of segments for noise power estimation + this->n_segments_reset = n_segments_reset; // Set the period (in segments) when the noise power is estimated z_0 = gr_complex(0 , 0); boost::math::chi_squared_distribution my_dist_(n_deg_fred); thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index faf7c5d0c..5be7dfda6 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -39,7 +39,7 @@ class Notch; typedef boost::shared_ptr notch_sptr; notch_sptr make_notch_filter(float pfa, float p_c_factor, - int length_); + int length_, int n_segments_est, int n_segments_reset); /*! * \brief This class implements a real-time software-defined multi state notch filter @@ -67,7 +67,7 @@ private: public: - Notch(float pfa, float p_c_factor, int length_); + Notch(float pfa, float p_c_factor, int length_, int n_segments_est, int n_segments_reset); ~Notch(); diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc index 4b21bf33e..3ce19f656 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc @@ -37,15 +37,17 @@ #include #include #include +#include +#include using google::LogMessage; -notch_lite_sptr make_notch_filter_lite(float p_c_factor) +notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff) { - return notch_lite_sptr(new NotchLite(p_c_factor)); + return notch_lite_sptr(new NotchLite(p_c_factor, pfa, length_, n_segments_est, n_segments_reset, n_segments_coeff)); } -NotchLite::NotchLite(float p_c_factor) : gr::block("NotchLite", +NotchLite::NotchLite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff) : gr::block("NotchLite", gr::io_signature::make (1, 1, sizeof(gr_complex)), gr::io_signature::make (1, 1, sizeof(gr_complex))) { @@ -53,28 +55,97 @@ NotchLite::NotchLite(float p_c_factor) : gr::block("NotchLite", set_alignment(std::max(1, alignment_multiple)); set_history(2); this->p_c_factor = gr_complex(p_c_factor , 0); + this->n_segments_est = n_segments_est; + this->n_segments_reset = n_segments_reset; + this->n_segments_coeff_reset = n_segments_coeff; + this->n_segments_coeff = 0; + this->length_ = length_; + set_output_multiple(length_); + this->pfa = pfa; + n_segments = 0; + n_deg_fred = 2 * length_; + noise_pow_est = 0.0; + filter_state_ = false; z_0 = gr_complex(0 , 0); - last_out = gr_complex(0,0); + last_out = gr_complex(0, 0); + boost::math::chi_squared_distribution my_dist_(n_deg_fred); + thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); + c_samples = gr_complex(0, 0); + angle_ = 0.0; + power_spect = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); + } +NotchLite::~NotchLite() +{ + volk_free(power_spect); +} + + int NotchLite::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)), gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { + int index_out = 0; + float sig2dB = 0.0; + float sig2lin = 0.0; + lv_32fc_t dot_prod_; gr_complex* in = (gr_complex *) input_items[0]; gr_complex* out = (gr_complex *) output_items[0]; - c_samples = static_cast(volk_malloc(noutput_items * sizeof(gr_complex), volk_get_alignment())); - angle_ = static_cast(volk_malloc(noutput_items * sizeof(float), volk_get_alignment())); - - volk_32fc_x2_multiply_conjugate_32fc(c_samples, (in + 1), in, noutput_items); - volk_32fc_s32f_atan2_32f(angle_, c_samples, ((float)1.0), noutput_items); - for (int aux = 0; aux < noutput_items; aux++) + in++; + arma::cx_fvec signal_segment; + arma::cx_fvec signal_segment_fft; + while((index_out + length_) < noutput_items) { - z_0 = std::exp(gr_complex(0,1) * (*(angle_ + aux))); - *(out + aux) = *(in + aux + 1) - z_0 * (*(in + aux)) + p_c_factor * z_0 * last_out; - last_out = *(out + aux); + if((n_segments < n_segments_est) && (filter_state_ == false)) + { + signal_segment = arma::cx_fvec(in, length_, false, false); + signal_segment_fft = arma::fft(signal_segment); + volk_32fc_s32f_power_spectrum_32f(power_spect, signal_segment_fft.memptr(), 1.0, length_); + volk_32f_s32f_calc_spectral_noise_floor_32f(&sig2dB, power_spect, 15.0, length_); + sig2lin = std::pow(10.0, (sig2dB / 10.0)) / ((float) n_deg_fred); + noise_pow_est = (((float) n_segments) * noise_pow_est + sig2lin) / ((float)(n_segments + 1)); + memcpy(out, in, sizeof(gr_complex) * length_); + } + else + { + volk_32fc_x2_conjugate_dot_prod_32fc(&dot_prod_, in, in, length_); + if( (lv_creal(dot_prod_) / noise_pow_est) > thres_) + { + if(filter_state_ == false) + { + filter_state_ = true; + last_out = gr_complex(0,0); + n_segments_coeff = 0; + } + if(n_segments_coeff == 0) + { + volk_32fc_x2_multiply_conjugate_32fc(&c_samples, in, (in - 1), 1); + volk_32fc_s32f_atan2_32f(&angle_, &c_samples, ((float)1.0), 1); + z_0 = std::exp(gr_complex(0,1) * angle_); + } + for(int aux = 0; aux < length_; aux++) + { + *(out + aux) = *(in + aux) - z_0 * (*(in + aux - 1)) + p_c_factor * z_0 * last_out; + last_out = *(out + aux); + } + n_segments_coeff++; + n_segments_coeff = n_segments_coeff % n_segments_coeff_reset; + } + else + { + if (n_segments > n_segments_reset) + { + n_segments = 0; + } + filter_state_ = false; + memcpy(out, in, sizeof(gr_complex) * length_); + } + } + index_out += length_; + n_segments++; + in += length_; + out += length_; } - volk_free(c_samples); - volk_free(angle_); - consume_each(noutput_items); - return noutput_items; + consume_each(index_out); + return index_out; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h index 16f56286d..64dcb8d53 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h @@ -38,7 +38,7 @@ class NotchLite; typedef boost::shared_ptr notch_lite_sptr; -notch_lite_sptr make_notch_filter_lite(float p_c_factor); +notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff); /*! * \brief This class implements a real-time software-defined single state notch filter @@ -48,15 +48,29 @@ class NotchLite : public gr::block { private: + int length_; + int n_segments; + int n_segments_est; + int n_segments_reset; + int n_segments_coeff_reset; + int n_segments_coeff; + int n_deg_fred; + float pfa; + float thres_; + float noise_pow_est; + bool filter_state_; gr_complex last_out; gr_complex z_0; gr_complex p_c_factor; - gr_complex* c_samples; - float* angle_; - + gr_complex c_samples; + float angle_; + float* power_spect; + public: - NotchLite(float p_c_factor); + NotchLite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff); + + ~NotchLite(); int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, From 9df36dcd831535a1e64f2b779edf3c9d4111b863 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Thu, 24 Aug 2017 19:21:24 +0200 Subject: [PATCH 21/22] Minor changes Changing some variable names --- src/algorithms/input_filter/adapters/notch_filter.h | 2 +- .../input_filter/adapters/notch_filter_lite.h | 2 +- .../input_filter/adapters/pulse_blanking_filter.cc | 4 ++-- .../input_filter/adapters/pulse_blanking_filter.h | 1 + .../input_filter/gnuradio_blocks/notch_lite_cc.cc | 13 +++++++++---- .../input_filter/gnuradio_blocks/notch_lite_cc.h | 10 ++++++---- .../gnuradio_blocks/pulse_blanking_cc.cc | 4 ++-- .../gnuradio_blocks/pulse_blanking_cc.h | 4 ++-- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/algorithms/input_filter/adapters/notch_filter.h b/src/algorithms/input_filter/adapters/notch_filter.h index 09ac10e99..a8ab2136b 100644 --- a/src/algorithms/input_filter/adapters/notch_filter.h +++ b/src/algorithms/input_filter/adapters/notch_filter.h @@ -1,6 +1,6 @@ /*! * \file notch_filter.h - * \brief + * \brief Adapter of a multistate Notch filter * \author Antonio Ramos, 2017. antonio.ramosdet(at)gmail.com * * Detailed description of the file here if needed. diff --git a/src/algorithms/input_filter/adapters/notch_filter_lite.h b/src/algorithms/input_filter/adapters/notch_filter_lite.h index 03796f319..f9088db52 100644 --- a/src/algorithms/input_filter/adapters/notch_filter_lite.h +++ b/src/algorithms/input_filter/adapters/notch_filter_lite.h @@ -1,6 +1,6 @@ /*! * \file notch_filter_lite.h - * \brief + * \brief Adapts a ligth version of a multistate notch filter * \author Antonio Ramos, 2017. antonio.ramosdet(at)gmail.com * * Detailed description of the file here if needed. diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc index fed7205cc..0786f3f3e 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.cc @@ -2,7 +2,7 @@ * \file pulse_blanking_filter.cc * \brief Instantiates the GNSS-SDR pulse blanking filter * \author Javier Arribas 2017 - * + * Antonio Ramos 2017 * ------------------------------------------------------------------------- * * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) @@ -57,7 +57,7 @@ PulseBlankingFilter::PulseBlankingFilter(ConfigurationInterface* configuration, int default_length_ = 32; int length_ = config_->property(role_ + ".length", default_length_); int default_n_segments_est = 12500; - int n_segments_est = config_->property(role_ + ".segments_estimation", default_n_segments_est); + int n_segments_est = config_->property(role_ + ".segments_est", default_n_segments_est); int default_n_segments_reset = 5000000; int n_segments_reset = config_->property(role_ + ".segments_reset", default_n_segments_reset); if (input_item_type_.compare("gr_complex") == 0) diff --git a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h index 041ba2251..c57c68d10 100644 --- a/src/algorithms/input_filter/adapters/pulse_blanking_filter.h +++ b/src/algorithms/input_filter/adapters/pulse_blanking_filter.h @@ -2,6 +2,7 @@ * \file pulse_blanking_filter.h * \brief Instantiates the GNSS-SDR pulse blanking filter * \author Javier Arribas 2017 + * Antonio Ramos 2017 * * ------------------------------------------------------------------------- * diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc index 3ce19f656..a84ec6ae6 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc @@ -70,8 +70,10 @@ NotchLite::NotchLite(float p_c_factor, float pfa, int length_, int n_segments_es last_out = gr_complex(0, 0); boost::math::chi_squared_distribution my_dist_(n_deg_fred); thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa)); - c_samples = gr_complex(0, 0); - angle_ = 0.0; + c_samples1 = gr_complex(0, 0); + c_samples2 = gr_complex(0, 0); + angle1 = 0.0; + angle2 = 0.0; power_spect = static_cast(volk_malloc(length_ * sizeof(float), volk_get_alignment())); } @@ -119,8 +121,11 @@ int NotchLite::general_work(int noutput_items __attribute__((unused)), gr_vector } if(n_segments_coeff == 0) { - volk_32fc_x2_multiply_conjugate_32fc(&c_samples, in, (in - 1), 1); - volk_32fc_s32f_atan2_32f(&angle_, &c_samples, ((float)1.0), 1); + volk_32fc_x2_multiply_conjugate_32fc(&c_samples1, (in + 1), in, 1); + volk_32fc_s32f_atan2_32f(&angle1, &c_samples1, ((float)1.0), 1); + volk_32fc_x2_multiply_conjugate_32fc(&c_samples2, (in + length_ - 1), (in + length_ - 2), 1); + volk_32fc_s32f_atan2_32f(&angle2, &c_samples2, ((float)1.0), 1); + float angle_ = (angle1 + angle2) / 2.0; z_0 = std::exp(gr_complex(0,1) * angle_); } for(int aux = 0; aux < length_; aux++) diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h index 64dcb8d53..2151a459f 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h @@ -1,6 +1,6 @@ /*! * \file notch_lite_cc.h - * \brief Implements a notch filter algorithm + * \brief Implements a notch filter ligth algorithm * \author Antonio Ramos (antonio.ramosdet(at)gmail.com) * * ------------------------------------------------------------------------- @@ -41,7 +41,7 @@ typedef boost::shared_ptr notch_lite_sptr; notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff); /*! - * \brief This class implements a real-time software-defined single state notch filter + * \brief This class implements a real-time software-defined multi state notch filter ligth version */ class NotchLite : public gr::block @@ -62,8 +62,10 @@ private: gr_complex last_out; gr_complex z_0; gr_complex p_c_factor; - gr_complex c_samples; - float angle_; + gr_complex c_samples1; + gr_complex c_samples2; + float angle1; + float angle2; float* power_spect; public: diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc index a744f8747..7924f17ba 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.cc @@ -1,8 +1,8 @@ /*! * \file pulse_blanking_cc.cc - * \brief Implements a simple pulse blanking algorithm + * \brief Implements a pulse blanking algorithm * \author Javier Arribas (jarribas(at)cttc.es) - * + * Antonio Ramos (antonio.ramosdet(at)gmail.com) * ------------------------------------------------------------------------- * * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h index a77cf4deb..7a19bf74e 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h @@ -1,8 +1,8 @@ /*! * \file pulse_blanking_cc.h - * \brief Implements a simple pulse blanking algorithm + * \brief Implements a pulse blanking algorithm * \author Javier Arribas (jarribas(at)cttc.es) - * + * Antonio Ramos (antonio.ramosdet(at)gmail.com) * ------------------------------------------------------------------------- * * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) From 732597860f20334653ff1ab699958ad0ff71a599 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 16 Oct 2017 11:39:22 +0200 Subject: [PATCH 22/22] Fix building --- .../input_filter/gnuradio_blocks/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt b/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt index 0d169b019..caac50136 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/input_filter/gnuradio_blocks/CMakeLists.txt @@ -17,7 +17,7 @@ # -set(INPUT_FILTER_GR_BLOCKS_SOURCES +set(INPUT_FILTER_GR_BLOCKS_SOURCES beamformer.cc pulse_blanking_cc.cc notch_cc.cc @@ -29,6 +29,8 @@ include_directories( ${GNURADIO_RUNTIME_INCLUDE_DIRS} ${GNURADIO_BLOCKS_INCLUDE_DIRS} ${VOLK_GNSSSDR_INCLUDE_DIRS} + ${GLOG_INCLUDE_DIRS} + ${GFlags_INCLUDE_DIRS} ) file(GLOB INPUT_FILTER_GR_BLOCKS_HEADERS "*.h") @@ -39,5 +41,7 @@ source_group(Headers FILES ${INPUT_FILTER_GR_BLOCKS_HEADERS}) target_link_libraries(input_filter_gr_blocks ${GNURADIO_FILTER_LIBRARIES} ${VOLK_GNSSSDR_LIBRARIES} ${LOG4CPP_LIBRARIES}) if(NOT VOLK_GNSSSDR_FOUND) - add_dependencies(input_filter_gr_blocks volk_gnsssdr_module) + add_dependencies(input_filter_gr_blocks volk_gnsssdr_module glog-${glog_RELEASE}) +else(NOT VOLK_GNSSSDR_FOUND) + add_dependencies(input_filter_gr_blocks glog-${glog_RELEASE}) endif(NOT VOLK_GNSSSDR_FOUND)