1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-22 21:13:15 +00:00

Input filter: Prefer initialization to assignment in constructors

This commit is contained in:
Carles Fernandez 2021-10-27 21:01:28 +02:00
parent 9df6767461
commit 5ec8fba831
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
9 changed files with 146 additions and 106 deletions

View File

@ -23,15 +23,18 @@
BeamformerFilter::BeamformerFilter(
const ConfigurationInterface* configuration, const std::string& role,
unsigned int in_stream, unsigned int out_stream) : role_(role), in_stream_(in_stream), out_stream_(out_stream)
unsigned int in_stream, unsigned int out_stream)
: role_(role),
samples_(0ULL),
in_stream_(in_stream),
out_stream_(out_stream)
{
const std::string default_item_type("gr_complex");
const 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);
DLOG(INFO) << "role " << role_;
if (item_type_ == "gr_complex")
{
item_size_ = sizeof(gr_complex);
@ -51,7 +54,6 @@ BeamformerFilter::BeamformerFilter(
file_sink_ = gr::blocks::file_sink::make(item_size_, dump_filename_.c_str());
DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")";
}
samples_ = 0ULL;
if (in_stream_ > 8)
{
LOG(ERROR) << "This implementation only supports eight input streams";

View File

@ -23,12 +23,18 @@
#include <utility>
FirFilter::FirFilter(const ConfigurationInterface* configuration, std::string role,
unsigned int in_streams, unsigned int out_streams) : role_(std::move(role)), in_streams_(in_streams), out_streams_(out_streams)
FirFilter::FirFilter(const ConfigurationInterface* configuration,
std::string role,
unsigned int in_streams,
unsigned int out_streams)
: config_(configuration),
role_(std::move(role)),
item_size_(0),
in_streams_(in_streams),
out_streams_(out_streams)
{
config_ = configuration;
(*this).init();
item_size_ = 0;
DLOG(INFO) << "role " << role_;
if ((taps_item_type_ == "float") && (input_item_type_ == "gr_complex") && (output_item_type_ == "gr_complex"))
{
item_size_ = sizeof(gr_complex);
@ -133,23 +139,24 @@ void FirFilter::init()
const std::string default_output_item_type("gr_complex");
const std::string default_taps_item_type("float");
const std::string default_dump_filename("../data/input_filter.dat");
const int default_number_of_taps = 6;
const unsigned int default_number_of_bands = 2;
const std::string default_filter_type("bandpass");
const std::vector<double> default_bands = {0.0, 0.4, 0.6, 1.0};
const std::vector<double> default_ampl = {1.0, 1.0, 0.0, 0.0};
const std::vector<double> default_error_w = {1.0, 1.0};
const std::string default_filter_type("bandpass");
const int default_grid_density = 16;
const int default_number_of_taps = 6;
const unsigned int default_number_of_bands = 2;
DLOG(INFO) << "role " << role_;
const int number_of_taps = config_->property(role_ + ".number_of_taps", default_number_of_taps);
const unsigned int number_of_bands = config_->property(role_ + ".number_of_bands", default_number_of_bands);
const std::string filter_type = config_->property(role_ + ".filter_type", default_filter_type);
const int grid_density = config_->property(role_ + ".grid_density", default_grid_density);
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);
taps_item_type_ = config_->property(role_ + ".taps_item_type", default_taps_item_type);
dump_ = config_->property(role_ + ".dump", false);
dump_filename_ = config_->property(role_ + ".dump_filename", default_dump_filename);
const int number_of_taps = config_->property(role_ + ".number_of_taps", default_number_of_taps);
const unsigned int number_of_bands = config_->property(role_ + ".number_of_bands", default_number_of_bands);
std::vector<double> bands;
std::vector<double> ampl;
@ -179,9 +186,6 @@ void FirFilter::init()
error_w.push_back(option_value);
}
const std::string filter_type = config_->property(role_ + ".filter_type", default_filter_type);
const int grid_density = config_->property(role_ + ".grid_density", default_grid_density);
// pm_remez implements the Parks-McClellan FIR filter design.
// It calculates the optimal (in the Chebyshev/minimax sense) FIR filter
// impulse response given a set of band edges, the desired response on

View File

@ -25,8 +25,13 @@
#include <utility>
FreqXlatingFirFilter::FreqXlatingFirFilter(const ConfigurationInterface* configuration, std::string role,
unsigned int in_streams, unsigned int out_streams) : role_(std::move(role)), in_streams_(in_streams), out_streams_(out_streams)
FreqXlatingFirFilter::FreqXlatingFirFilter(const ConfigurationInterface* configuration,
std::string role,
unsigned int in_streams,
unsigned int out_streams)
: role_(std::move(role)),
in_streams_(in_streams),
out_streams_(out_streams)
{
const std::string default_input_item_type("gr_complex");
const std::string default_output_item_type("gr_complex");
@ -43,19 +48,18 @@ FreqXlatingFirFilter::FreqXlatingFirFilter(const ConfigurationInterface* configu
const int default_grid_density = 16;
const int default_decimation_factor = 1;
DLOG(INFO) << "role " << role_;
input_item_type_ = configuration->property(role_ + ".input_item_type", default_input_item_type);
output_item_type_ = configuration->property(role_ + ".output_item_type", default_output_item_type);
taps_item_type_ = configuration->property(role_ + ".taps_item_type", default_taps_item_type);
dump_ = configuration->property(role_ + ".dump", false);
dump_filename_ = configuration->property(role_ + ".dump_filename", default_dump_filename);
intermediate_freq_ = configuration->property(role_ + ".IF", default_intermediate_freq);
sampling_freq_ = configuration->property(role_ + ".sampling_frequency", default_sampling_freq);
const int number_of_taps = configuration->property(role_ + ".number_of_taps", default_number_of_taps);
const unsigned int number_of_bands = configuration->property(role_ + ".number_of_bands", default_number_of_bands);
const std::string filter_type = configuration->property(role_ + ".filter_type", default_filter_type);
dump_filename_ = configuration->property(role_ + ".dump_filename", default_dump_filename);
input_item_type_ = configuration->property(role_ + ".input_item_type", default_input_item_type);
output_item_type_ = configuration->property(role_ + ".output_item_type", default_output_item_type);
taps_item_type_ = configuration->property(role_ + ".taps_item_type", default_taps_item_type);
intermediate_freq_ = configuration->property(role_ + ".IF", default_intermediate_freq);
sampling_freq_ = configuration->property(role_ + ".sampling_frequency", default_sampling_freq);
decimation_factor_ = configuration->property(role_ + ".decimation_factor", default_decimation_factor);
dump_ = configuration->property(role_ + ".dump", false);
if (filter_type != "lowpass")
{
@ -102,6 +106,7 @@ FreqXlatingFirFilter::FreqXlatingFirFilter(const ConfigurationInterface* configu
}
size_t item_size;
DLOG(INFO) << "role " << role_;
LOG(INFO) << "Created freq_xlating_fir_filter with " << taps_.size() << " taps";
if ((taps_item_type_ == "float") && (input_item_type_ == "gr_complex") && (output_item_type_ == "gr_complex"))
{

View File

@ -22,25 +22,33 @@
#include <glog/logging.h>
NotchFilter::NotchFilter(const ConfigurationInterface* configuration, const std::string& role,
unsigned int in_streams, unsigned int out_streams) : role_(role), in_streams_(in_streams), out_streams_(out_streams)
NotchFilter::NotchFilter(const ConfigurationInterface* configuration,
const std::string& role,
unsigned int in_streams,
unsigned int out_streams)
: role_(role),
in_streams_(in_streams),
out_streams_(out_streams)
{
const std::string default_item_type("gr_complex");
const std::string default_dump_file("./data/input_filter.dat");
const float default_pfa = 0.001;
const float default_p_c_factor = 0.9;
const int default_length_ = 32;
const int default_n_segments_est = 12500;
const int default_n_segments_reset = 5000000;
const std::string default_item_type("gr_complex");
const 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);
const float pfa = configuration->property(role + ".pfa", default_pfa);
const float p_c_factor = configuration->property(role + ".p_c_factor", default_p_c_factor);
const int length_ = configuration->property(role + ".length", default_length_);
const int n_segments_est = configuration->property(role + ".segments_est", default_n_segments_est);
const int n_segments_reset = configuration->property(role + ".segments_reset", default_n_segments_reset);
dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file);
item_type_ = configuration->property(role + ".item_type", default_item_type);
dump_ = configuration->property(role + ".dump", false);
DLOG(INFO) << "role " << role_;
if (item_type_ == "gr_complex")
{
item_size_ = sizeof(gr_complex);

View File

@ -23,31 +23,39 @@
#include <algorithm> // for max
NotchFilterLite::NotchFilterLite(const ConfigurationInterface* configuration, const std::string& role,
unsigned int in_streams, unsigned int out_streams) : role_(role), in_streams_(in_streams), out_streams_(out_streams)
NotchFilterLite::NotchFilterLite(const ConfigurationInterface* configuration,
const std::string& role,
unsigned int in_streams,
unsigned int out_streams)
: role_(role),
in_streams_(in_streams),
out_streams_(out_streams)
{
const float default_p_c_factor = 0.9;
const float default_pfa = 0.001;
const int default_length_ = 32;
const int default_n_segments_est = 12500;
const int default_n_segments_reset = 5000000;
const float default_samp_freq = 4000000;
const std::string default_item_type("gr_complex");
const std::string default_dump_file("./data/input_filter.dat");
const float default_p_c_factor = 0.9;
const float default_pfa = 0.001;
const float default_samp_freq = 4000000;
const int default_n_segments_reset = 5000000;
const int default_length_ = 32;
const int default_n_segments_est = 12500;
const float samp_freq = configuration->property("SignalSource.sampling_frequency", default_samp_freq);
const float default_coeff_rate = samp_freq * 0.1F;
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);
const float p_c_factor = configuration->property(role + ".p_c_factor", default_p_c_factor);
const float pfa = configuration->property(role + ".pfa", default_pfa);
const float coeff_rate = configuration->property(role + ".coeff_rate", default_coeff_rate);
const int length_ = configuration->property(role + ".length", default_length_);
const int n_segments_est = configuration->property(role + ".segments_est", default_n_segments_est);
const int n_segments_reset = configuration->property(role + ".segments_reset", default_n_segments_reset);
dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file);
item_type_ = configuration->property(role + ".item_type", default_item_type);
dump_ = configuration->property(role + ".dump", false);
int n_segments_coeff = static_cast<int>((samp_freq / coeff_rate) / static_cast<float>(length_));
n_segments_coeff = std::max(1, n_segments_coeff);
DLOG(INFO) << "role " << role_;
if (item_type_ == "gr_complex")
{
item_size_ = sizeof(gr_complex);

View File

@ -26,19 +26,16 @@
#include <vector>
PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configuration, std::string role,
unsigned int in_streams, unsigned int out_streams) : role_(std::move(role)), in_streams_(in_streams), out_streams_(out_streams)
PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configuration,
std::string role,
unsigned int in_streams,
unsigned int out_streams)
: role_(std::move(role)),
in_streams_(in_streams),
out_streams_(out_streams)
{
size_t item_size;
xlat_ = false;
const std::string default_item_type("gr_complex");
const std::string default_dump_filename("../data/input_filter.dat");
DLOG(INFO) << "role " << role_;
item_type_ = configuration->property(role_ + ".item_type", default_item_type);
dump_ = configuration->property(role_ + ".dump", false);
dump_filename_ = configuration->property(role_ + ".dump_filename", default_dump_filename);
const float default_pfa_ = 0.04;
const float pfa = configuration->property(role_ + ".pfa", default_pfa_);
const int default_length_ = 32;
@ -47,6 +44,16 @@ PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configura
const int n_segments_est = configuration->property(role_ + ".segments_est", default_n_segments_est);
const int default_n_segments_reset = 5000000;
const int n_segments_reset = configuration->property(role_ + ".segments_reset", default_n_segments_reset);
const double default_if = 0.0;
const double if_aux = configuration->property(role_ + ".if", default_if);
const double if_ = configuration->property(role_ + ".IF", if_aux);
dump_filename_ = configuration->property(role_ + ".dump_filename", default_dump_filename);
item_type_ = configuration->property(role_ + ".item_type", default_item_type);
dump_ = configuration->property(role_ + ".dump", false);
DLOG(INFO) << "role " << role_;
size_t item_size;
if (item_type_ == "gr_complex")
{
item_size = sizeof(gr_complex); // output
@ -59,9 +66,6 @@ PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configura
item_size = sizeof(gr_complex); // avoids uninitialization
input_size_ = 0; // notify wrong configuration
}
const double default_if = 0.0;
const double if_aux = configuration->property(role_ + ".if", default_if);
const double if_ = configuration->property(role_ + ".IF", if_aux);
if (std::abs(if_) > 1.0)
{
xlat_ = true;
@ -74,6 +78,10 @@ PulseBlankingFilter::PulseBlankingFilter(const ConfigurationInterface* configura
const std::vector<float> taps = gr::filter::firdes::low_pass(1.0, sampling_freq_, bw_, tw_);
freq_xlating_ = gr::filter::freq_xlating_fir_filter_ccf::make(1, taps, if_, sampling_freq_);
}
else
{
xlat_ = false;
}
if (dump_)
{
DLOG(INFO) << "Dumping output into file " << dump_filename_;

View File

@ -34,28 +34,29 @@ Notch::Notch(float pfa,
float p_c_factor,
int32_t length,
int32_t n_segments_est,
int32_t n_segments_reset) : gr::block("Notch",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex)))
int32_t n_segments_reset)
: gr::block("Notch",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex))),
last_out_(gr_complex(0.0, 0.0)),
z_0_(gr_complex(0.0, 0.0)),
p_c_factor_(gr_complex(p_c_factor, 0.0)),
pfa_(pfa),
noise_pow_est_(0.0),
length_(length), // Set the number of samples per segment
n_deg_fred_(2 * length), // Number of dregrees of freedom,
n_segments_(0),
n_segments_est_(n_segments_est), // Set the number of segments for noise power estimation
n_segments_reset_(n_segments_reset), // Set the period (in segments) when the noise power is estimated
filter_state_(false)
{
const int32_t alignment_multiple = volk_get_alignment() / sizeof(gr_complex);
set_alignment(std::max(1, alignment_multiple));
pfa_ = pfa;
noise_pow_est_ = 0.0;
p_c_factor_ = gr_complex(p_c_factor, 0.0);
length_ = length; // Set the number of samples per segment
filter_state_ = false; // Initial state of the filter
n_deg_fred_ = 2 * length_; // Number of dregrees of freedom
n_segments_ = 0;
n_segments_est_ = n_segments_est; // Set the number of segments for noise power estimation
n_segments_reset_ = n_segments_reset; // Set the period (in segments) when the noise power is estimated
z_0_ = gr_complex(0.0, 0.0);
boost::math::chi_squared_distribution<float> my_dist_(n_deg_fred_);
thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa_));
c_samples_ = volk_gnsssdr::vector<gr_complex>(length_);
angle_ = volk_gnsssdr::vector<float>(length_);
power_spect_ = volk_gnsssdr::vector<float>(length_);
last_out_ = gr_complex(0.0, 0.0);
d_fft_ = gnss_fft_fwd_make_unique(length_);
}

View File

@ -35,32 +35,35 @@ NotchLite::NotchLite(float p_c_factor,
int32_t length,
int32_t n_segments_est,
int32_t n_segments_reset,
int32_t n_segments_coeff) : gr::block("NotchLite",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex)))
int32_t n_segments_coeff)
: gr::block("NotchLite",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex))),
last_out_(gr_complex(0.0, 0.0)),
z_0_(gr_complex(0.0, 0.0)),
p_c_factor_(gr_complex(p_c_factor, 0.0)),
c_samples1_(gr_complex(0.0, 0.0)),
c_samples2_(gr_complex(0.0, 0.0)),
pfa_(pfa),
noise_pow_est_(0.0),
angle1_(0.0),
angle2_(0.0),
length_(length),
n_segments_(0),
n_segments_est_(n_segments_est),
n_segments_reset_(n_segments_reset),
n_segments_coeff_reset_(n_segments_coeff),
n_segments_coeff_(0),
n_deg_fred_(2 * length),
filter_state_(false)
{
const int32_t alignment_multiple = volk_get_alignment() / sizeof(gr_complex);
set_alignment(std::max(1, alignment_multiple));
set_history(2);
p_c_factor_ = gr_complex(p_c_factor, 0.0);
n_segments_est_ = n_segments_est;
n_segments_reset_ = n_segments_reset;
n_segments_coeff_reset_ = n_segments_coeff;
n_segments_coeff_ = 0;
length_ = length;
pfa_ = pfa;
n_segments_ = 0;
n_deg_fred_ = 2 * length_;
noise_pow_est_ = 0.0;
filter_state_ = false;
z_0_ = gr_complex(0.0, 0.0);
last_out_ = gr_complex(0.0, 0.0);
boost::math::chi_squared_distribution<float> my_dist_(n_deg_fred_);
thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa_));
c_samples1_ = gr_complex(0.0, 0.0);
c_samples2_ = gr_complex(0.0, 0.0);
angle1_ = 0.0;
angle2_ = 0.0;
power_spect_ = volk_gnsssdr::vector<float>(length_);
d_fft_ = gnss_fft_fwd_make_unique(length_);
}

View File

@ -33,20 +33,21 @@ pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int32_t length,
pulse_blanking_cc::pulse_blanking_cc(float pfa,
int32_t length,
int32_t n_segments_est,
int32_t 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)))
int32_t 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))),
noise_power_estimation_(0.0),
pfa_(pfa),
length_(length),
n_segments_(0),
n_segments_est_(n_segments_est),
n_segments_reset_(n_segments_reset),
n_deg_fred_(2 * length),
last_filtered_(false)
{
const int32_t alignment_multiple = volk_get_alignment() / sizeof(gr_complex);
set_alignment(std::max(1, alignment_multiple));
pfa_ = pfa;
length_ = length;
last_filtered_ = false;
n_segments_ = 0;
n_segments_est_ = n_segments_est;
n_segments_reset_ = n_segments_reset;
noise_power_estimation_ = 0.0;
n_deg_fred_ = 2 * length_;
boost::math::chi_squared_distribution<float> my_dist_(n_deg_fred_);
thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa_));
zeros_ = volk_gnsssdr::vector<gr_complex>(length_);