mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-14 20:20:35 +00:00
Adding Single state Notch Filter
New Notch_Filter_Lite input filter block
This commit is contained in:
parent
8f1fcb382a
commit
1e753e5f54
@ -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(
|
||||
|
114
src/algorithms/input_filter/adapters/notch_filter_lite.cc
Normal file
114
src/algorithms/input_filter/adapters/notch_filter_lite.cc
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "notch_filter_lite.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <gnuradio/blocks/file_sink.h>
|
||||
#include <glog/logging.h>
|
||||
#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_;
|
||||
}
|
84
src/algorithms/input_filter/adapters/notch_filter_lite.h
Normal file
84
src/algorithms/input_filter/adapters/notch_filter_lite.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef GNSS_SDR_NOTCH_FILTER_LITE_H_
|
||||
#define GNSS_SDR_NOTCH_FILTER_LITE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <gnuradio/blocks/file_sink.h>
|
||||
#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_
|
@ -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(
|
||||
|
80
src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc
Normal file
80
src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.cc
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "notch_lite_cc.h"
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include <volk/volk.h>
|
||||
#include <iostream>
|
||||
#include <glog/logging.h>
|
||||
|
||||
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<gr_complex *>(volk_malloc(noutput_items * sizeof(gr_complex), volk_get_alignment()));
|
||||
angle_ = static_cast<float *>(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;
|
||||
}
|
66
src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h
Normal file
66
src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef GNSS_SDR_NOTCH_LITE_H_
|
||||
#define GNSS_SDR_NOTCH_LITE_H_
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <gnuradio/block.h>
|
||||
|
||||
class NotchLite;
|
||||
|
||||
typedef boost::shared_ptr<NotchLite> 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_
|
Loading…
Reference in New Issue
Block a user