1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-29 02:14:51 +00:00

Add lowpass filtering

Lowpass filtering implementation in freq_xlating
This commit is contained in:
Unknown 2017-11-06 10:32:11 +01:00
parent f02bd08ce9
commit 03f7cf0b07
3 changed files with 58 additions and 50 deletions

View File

@ -32,6 +32,7 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <gnuradio/blocks/file_sink.h> #include <gnuradio/blocks/file_sink.h>
#include <gnuradio/filter/pm_remez.h> #include <gnuradio/filter/pm_remez.h>
#include <gnuradio/filter/firdes.h>
#include <glog/logging.h> #include <glog/logging.h>
#include <volk/volk.h> #include <volk/volk.h>
#include "configuration_interface.h" #include "configuration_interface.h"
@ -343,8 +344,8 @@ void FreqXlatingFirFilter::init()
std::string default_output_item_type = "gr_complex"; std::string default_output_item_type = "gr_complex";
std::string default_taps_item_type = "float"; std::string default_taps_item_type = "float";
std::string default_dump_filename = "../data/input_filter.dat"; std::string default_dump_filename = "../data/input_filter.dat";
double default_intermediate_freq = 0; double default_intermediate_freq = 0.0;
double default_sampling_freq = 4000000; double default_sampling_freq = 4000000.0;
int default_number_of_taps = 6; int default_number_of_taps = 6;
unsigned int default_number_of_bands = 2; unsigned int default_number_of_bands = 2;
std::vector<double> default_bands = { 0.0, 0.4, 0.6, 1.0 }; std::vector<double> default_bands = { 0.0, 0.4, 0.6, 1.0 };
@ -364,46 +365,54 @@ void FreqXlatingFirFilter::init()
sampling_freq_ = config_->property(role_ + ".sampling_frequency", default_sampling_freq); sampling_freq_ = config_->property(role_ + ".sampling_frequency", default_sampling_freq);
int number_of_taps = config_->property(role_ + ".number_of_taps", default_number_of_taps); int number_of_taps = config_->property(role_ + ".number_of_taps", default_number_of_taps);
unsigned int number_of_bands = config_->property(role_ + ".number_of_bands", default_number_of_bands); unsigned int number_of_bands = config_->property(role_ + ".number_of_bands", default_number_of_bands);
std::vector<double> bands;
std::vector<double> ampl;
std::vector<double> error_w;
std::string option;
double option_value;
for (unsigned int i = 0; i < number_of_bands; i++)
{
option = ".band" + boost::lexical_cast<std::string>(i + 1) + "_begin";
option_value = config_->property(role_ + option, default_bands[i]);
bands.push_back(option_value);
option = ".band" + boost::lexical_cast<std::string>(i + 1) + "_end";
option_value = config_->property(role_ + option, default_bands[i]);
bands.push_back(option_value);
option = ".ampl" + boost::lexical_cast<std::string>(i + 1) + "_begin";
option_value = config_->property(role_ + option, default_bands[i]);
ampl.push_back(option_value);
option = ".ampl" + boost::lexical_cast<std::string>(i + 1) + "_end";
option_value = config_->property(role_ + option, default_bands[i]);
ampl.push_back(option_value);
option = ".band" + boost::lexical_cast<std::string>(i + 1) + "_error";
option_value = config_->property(role_ + option, default_bands[i]);
error_w.push_back(option_value);
}
std::string filter_type = config_->property(role_ + ".filter_type", default_filter_type); std::string filter_type = config_->property(role_ + ".filter_type", default_filter_type);
int grid_density = config_->property(role_ + ".grid_density", default_grid_density);
std::vector<double> taps_d = gr::filter::pm_remez(number_of_taps - 1, bands, ampl, if(filter_type.compare("lowpass") != 0)
error_w, filter_type, grid_density);
taps_.reserve(taps_d.size());
for (std::vector<double>::iterator it = taps_d.begin(); it != taps_d.end(); it++)
{ {
taps_.push_back(float(*it)); std::vector<double> taps_d;
//std::cout<<"TAP="<<float(*it)<<std::endl; std::vector<double> bands;
std::vector<double> ampl;
std::vector<double> error_w;
std::string option;
double option_value;
for (unsigned int i = 0; i < number_of_bands; i++)
{
option = ".band" + boost::lexical_cast<std::string>(i + 1) + "_begin";
option_value = config_->property(role_ + option, default_bands[i]);
bands.push_back(option_value);
option = ".band" + boost::lexical_cast<std::string>(i + 1) + "_end";
option_value = config_->property(role_ + option, default_bands[i]);
bands.push_back(option_value);
option = ".ampl" + boost::lexical_cast<std::string>(i + 1) + "_begin";
option_value = config_->property(role_ + option, default_bands[i]);
ampl.push_back(option_value);
option = ".ampl" + boost::lexical_cast<std::string>(i + 1) + "_end";
option_value = config_->property(role_ + option, default_bands[i]);
ampl.push_back(option_value);
option = ".band" + boost::lexical_cast<std::string>(i + 1) + "_error";
option_value = config_->property(role_ + option, default_bands[i]);
error_w.push_back(option_value);
}
int grid_density = config_->property(role_ + ".grid_density", default_grid_density);
taps_d = gr::filter::pm_remez(number_of_taps - 1, bands, ampl, error_w, filter_type, grid_density);
taps_.reserve(taps_d.size());
for (std::vector<double>::iterator it = taps_d.begin(); it != taps_d.end(); it++)
{
taps_.push_back(static_cast<float>(*it));
}
} }
else
{
double default_bw = 2000000.0;
double bw_ = config_->property(role_ + ".bw", default_bw);
double default_tw = bw_ / 20.0;
double tw_ = config_->property(role_ + ".tw", default_tw);
taps_ = gr::filter::firdes::low_pass(1.0, sampling_freq_, bw_ / 2.0, tw_);
}
} }

View File

@ -28,13 +28,13 @@
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#include "pulse_blanking_filter.h"
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <vector> #include <vector>
#include <cmath>
#include <glog/logging.h> #include <glog/logging.h>
#include <gnuradio/filter/firdes.h> #include <gnuradio/filter/firdes.h>
#include "configuration_interface.h" #include "configuration_interface.h"
#include <vector> #include "pulse_blanking_filter.h"
using google::LogMessage; using google::LogMessage;
@ -74,13 +74,13 @@ PulseBlankingFilter::PulseBlankingFilter(ConfigurationInterface* configuration,
item_size = sizeof(gr_complex); //avoids uninitialization item_size = sizeof(gr_complex); //avoids uninitialization
input_size_ = sizeof(gr_complex); //avoids uninitialization input_size_ = sizeof(gr_complex); //avoids uninitialization
} }
float default_if = 0.0; double default_if = 0.0;
float if_ = config_->property(role_ + ".if", default_if); double if_ = config_->property(role_ + ".if", default_if);
if (if_ > 0.0) if (std::abs(if_) > 1.0)
{ {
double default_bw = 2000000.0; double default_bw = 2000000.0;
double bw_ = config_->property(role_ + ".bw", default_bw); double bw_ = config_->property(role_ + ".bw", default_bw);
double default_tw = bw_ / 15.0; double default_tw = bw_ / 20.0;
double tw_ = config_->property(role_ + ".tw", default_tw); double tw_ = config_->property(role_ + ".tw", default_tw);
const std::vector<float> taps = gr::filter::firdes::low_pass(1.0, config_->property("SignalSource.sampling_frequency", 2000000.0), bw_ / 2.0, tw_); const std::vector<float> taps = gr::filter::firdes::low_pass(1.0, config_->property("SignalSource.sampling_frequency", 2000000.0), bw_ / 2.0, tw_);
freq_xlating_ = gr::filter::freq_xlating_fir_filter_ccf::make(1, taps, if_, config_->property("SignalSource.sampling_frequency", 2000000.0)); freq_xlating_ = gr::filter::freq_xlating_fir_filter_ccf::make(1, taps, if_, config_->property("SignalSource.sampling_frequency", 2000000.0));
@ -108,7 +108,7 @@ void PulseBlankingFilter::connect(gr::top_block_sptr top_block)
{ {
top_block->connect(pulse_blanking_cc_, 0, file_sink_, 0); top_block->connect(pulse_blanking_cc_, 0, file_sink_, 0);
} }
if (config_->property(role_ + ".if", 0.0) > 0.0) if (std::abs(config_->property(role_ + ".if", 0.0)) > 1.0)
{ {
top_block->connect(freq_xlating_, 0, pulse_blanking_cc_, 0); top_block->connect(freq_xlating_, 0, pulse_blanking_cc_, 0);
} }
@ -130,7 +130,7 @@ void PulseBlankingFilter::disconnect(gr::top_block_sptr top_block)
{ {
top_block->disconnect(pulse_blanking_cc_, 0, file_sink_, 0); top_block->disconnect(pulse_blanking_cc_, 0, file_sink_, 0);
} }
if (config_->property(role_ + ".if", 0.0) > 0.0) if (std::abs(config_->property(role_ + ".if", 0.0)) > 1.0)
{ {
top_block->disconnect(freq_xlating_, 0, pulse_blanking_cc_, 0); top_block->disconnect(freq_xlating_, 0, pulse_blanking_cc_, 0);
} }
@ -146,7 +146,7 @@ gr::basic_block_sptr PulseBlankingFilter::get_left_block()
{ {
if (input_item_type_.compare("gr_complex") == 0) if (input_item_type_.compare("gr_complex") == 0)
{ {
if (config_->property(role_ + ".if", 0.0) > 0.0) if (std::abs(config_->property(role_ + ".if", 0.0)) > 1.0)
{ {
return freq_xlating_; return freq_xlating_;
} }

View File

@ -33,7 +33,6 @@
#define GNSS_SDR_PULSE_BLANKING_FILTER_H_ #define GNSS_SDR_PULSE_BLANKING_FILTER_H_
#include <string> #include <string>
#include <vector>
#include <gnuradio/blocks/file_sink.h> #include <gnuradio/blocks/file_sink.h>
#include <gnuradio/filter/freq_xlating_fir_filter_ccf.h> #include <gnuradio/filter/freq_xlating_fir_filter_ccf.h>
#include "gnss_block_interface.h" #include "gnss_block_interface.h"