mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-07 07:50:32 +00:00
Improving freq xlating fir filter adapter configuration
This commit is contained in:
parent
06015f82b3
commit
f9573987a2
@ -43,38 +43,112 @@ using google::LogMessage;
|
|||||||
FreqXlatingFirFilter::FreqXlatingFirFilter(ConfigurationInterface* configuration, std::string role,
|
FreqXlatingFirFilter::FreqXlatingFirFilter(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)
|
unsigned int in_streams, unsigned int out_streams) : config_(configuration), role_(role), in_streams_(in_streams), out_streams_(out_streams)
|
||||||
{
|
{
|
||||||
size_t item_size;
|
std::string default_input_item_type = "gr_complex";
|
||||||
(*this).init();
|
std::string default_output_item_type = "gr_complex";
|
||||||
int decimation_factor;
|
std::string default_taps_item_type = "float";
|
||||||
|
std::string default_dump_filename = "../data/input_filter.dat";
|
||||||
|
double default_intermediate_freq = 0.0;
|
||||||
|
double default_sampling_freq = 4000000.0;
|
||||||
|
int default_number_of_taps = 6;
|
||||||
|
unsigned int default_number_of_bands = 2;
|
||||||
|
std::vector<double> default_bands = {0.0, 0.4, 0.6, 1.0};
|
||||||
|
std::vector<double> default_ampl = {1.0, 1.0, 0.0, 0.0};
|
||||||
|
std::vector<double> default_error_w = {1.0, 1.0};
|
||||||
|
std::string default_filter_type = "bandpass";
|
||||||
|
int default_grid_density = 16;
|
||||||
int default_decimation_factor = 1;
|
int default_decimation_factor = 1;
|
||||||
decimation_factor = config_->property(role_ + ".decimation_factor", default_decimation_factor);
|
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
intermediate_freq_ = config_->property(role_ + ".IF", default_intermediate_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);
|
||||||
|
unsigned int number_of_bands = config_->property(role_ + ".number_of_bands", default_number_of_bands);
|
||||||
|
std::string filter_type = config_->property(role_ + ".filter_type", default_filter_type);
|
||||||
|
decimation_factor_ = config_->property(role_ + ".decimation_factor", default_decimation_factor);
|
||||||
|
|
||||||
|
if (filter_type.compare("lowpass") != 0)
|
||||||
|
{
|
||||||
|
std::vector<double> taps_d;
|
||||||
|
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 = (sampling_freq_ / decimation_factor_) / 2;
|
||||||
|
double bw_ = config_->property(role_ + ".bw", default_bw);
|
||||||
|
double default_tw = bw_ / 10.0;
|
||||||
|
double tw_ = config_->property(role_ + ".tw", default_tw);
|
||||||
|
taps_ = gr::filter::firdes::low_pass(1.0, sampling_freq_, bw_, tw_);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t item_size;
|
||||||
|
|
||||||
if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("gr_complex") == 0) && (output_item_type_.compare("gr_complex") == 0))
|
if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("gr_complex") == 0) && (output_item_type_.compare("gr_complex") == 0))
|
||||||
{
|
{
|
||||||
item_size = sizeof(gr_complex); //output
|
item_size = sizeof(gr_complex); //output
|
||||||
input_size_ = sizeof(gr_complex); //input
|
input_size_ = sizeof(gr_complex); //input
|
||||||
freq_xlating_fir_filter_ccf_ = gr::filter::freq_xlating_fir_filter_ccf::make(decimation_factor, taps_, intermediate_freq_, sampling_freq_);
|
freq_xlating_fir_filter_ccf_ = gr::filter::freq_xlating_fir_filter_ccf::make(decimation_factor_, taps_, intermediate_freq_, sampling_freq_);
|
||||||
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_ccf_->unique_id() << ")";
|
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_ccf_->unique_id() << ")";
|
||||||
}
|
}
|
||||||
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("float") == 0) && (output_item_type_.compare("gr_complex") == 0))
|
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("float") == 0) && (output_item_type_.compare("gr_complex") == 0))
|
||||||
{
|
{
|
||||||
item_size = sizeof(gr_complex);
|
item_size = sizeof(gr_complex);
|
||||||
input_size_ = sizeof(float); //input
|
input_size_ = sizeof(float); //input
|
||||||
freq_xlating_fir_filter_fcf_ = gr::filter::freq_xlating_fir_filter_fcf::make(decimation_factor, taps_, intermediate_freq_, sampling_freq_);
|
freq_xlating_fir_filter_fcf_ = gr::filter::freq_xlating_fir_filter_fcf::make(decimation_factor_, taps_, intermediate_freq_, sampling_freq_);
|
||||||
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_fcf_->unique_id() << ")";
|
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_fcf_->unique_id() << ")";
|
||||||
}
|
}
|
||||||
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("short") == 0) && (output_item_type_.compare("gr_complex") == 0))
|
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("short") == 0) && (output_item_type_.compare("gr_complex") == 0))
|
||||||
{
|
{
|
||||||
item_size = sizeof(gr_complex);
|
item_size = sizeof(gr_complex);
|
||||||
input_size_ = sizeof(int16_t); //input
|
input_size_ = sizeof(int16_t); //input
|
||||||
freq_xlating_fir_filter_scf_ = gr::filter::freq_xlating_fir_filter_scf::make(decimation_factor, taps_, intermediate_freq_, sampling_freq_);
|
freq_xlating_fir_filter_scf_ = gr::filter::freq_xlating_fir_filter_scf::make(decimation_factor_, taps_, intermediate_freq_, sampling_freq_);
|
||||||
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_scf_->unique_id() << ")";
|
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_scf_->unique_id() << ")";
|
||||||
}
|
}
|
||||||
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("short") == 0) && (output_item_type_.compare("cshort") == 0))
|
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("short") == 0) && (output_item_type_.compare("cshort") == 0))
|
||||||
{
|
{
|
||||||
item_size = sizeof(lv_16sc_t);
|
item_size = sizeof(lv_16sc_t);
|
||||||
input_size_ = sizeof(int16_t); //input
|
input_size_ = sizeof(int16_t); //input
|
||||||
freq_xlating_fir_filter_scf_ = gr::filter::freq_xlating_fir_filter_scf::make(decimation_factor, taps_, intermediate_freq_, sampling_freq_);
|
freq_xlating_fir_filter_scf_ = gr::filter::freq_xlating_fir_filter_scf::make(decimation_factor_, taps_, intermediate_freq_, sampling_freq_);
|
||||||
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_scf_->unique_id() << ")";
|
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_scf_->unique_id() << ")";
|
||||||
complex_to_float_ = gr::blocks::complex_to_float::make();
|
complex_to_float_ = gr::blocks::complex_to_float::make();
|
||||||
float_to_short_1_ = gr::blocks::float_to_short::make();
|
float_to_short_1_ = gr::blocks::float_to_short::make();
|
||||||
@ -86,7 +160,7 @@ FreqXlatingFirFilter::FreqXlatingFirFilter(ConfigurationInterface* configuration
|
|||||||
item_size = sizeof(gr_complex);
|
item_size = sizeof(gr_complex);
|
||||||
input_size_ = sizeof(int8_t); //input
|
input_size_ = sizeof(int8_t); //input
|
||||||
gr_char_to_short_ = gr::blocks::char_to_short::make();
|
gr_char_to_short_ = gr::blocks::char_to_short::make();
|
||||||
freq_xlating_fir_filter_scf_ = gr::filter::freq_xlating_fir_filter_scf::make(decimation_factor, taps_, intermediate_freq_, sampling_freq_);
|
freq_xlating_fir_filter_scf_ = gr::filter::freq_xlating_fir_filter_scf::make(decimation_factor_, taps_, intermediate_freq_, sampling_freq_);
|
||||||
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_scf_->unique_id() << ")";
|
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_scf_->unique_id() << ")";
|
||||||
}
|
}
|
||||||
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("byte") == 0) && (output_item_type_.compare("cbyte") == 0))
|
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("byte") == 0) && (output_item_type_.compare("cbyte") == 0))
|
||||||
@ -94,7 +168,7 @@ FreqXlatingFirFilter::FreqXlatingFirFilter(ConfigurationInterface* configuration
|
|||||||
item_size = sizeof(lv_8sc_t);
|
item_size = sizeof(lv_8sc_t);
|
||||||
input_size_ = sizeof(int8_t); //input
|
input_size_ = sizeof(int8_t); //input
|
||||||
gr_char_to_short_ = gr::blocks::char_to_short::make();
|
gr_char_to_short_ = gr::blocks::char_to_short::make();
|
||||||
freq_xlating_fir_filter_scf_ = gr::filter::freq_xlating_fir_filter_scf::make(decimation_factor, taps_, intermediate_freq_, sampling_freq_);
|
freq_xlating_fir_filter_scf_ = gr::filter::freq_xlating_fir_filter_scf::make(decimation_factor_, taps_, intermediate_freq_, sampling_freq_);
|
||||||
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_scf_->unique_id() << ")";
|
DLOG(INFO) << "input_filter(" << freq_xlating_fir_filter_scf_->unique_id() << ")";
|
||||||
complex_to_complex_byte_ = make_complex_float_to_complex_byte();
|
complex_to_complex_byte_ = make_complex_float_to_complex_byte();
|
||||||
}
|
}
|
||||||
@ -311,83 +385,3 @@ gr::basic_block_sptr FreqXlatingFirFilter::get_right_block()
|
|||||||
LOG(ERROR) << " Unknown input filter input/output item type conversion";
|
LOG(ERROR) << " Unknown input filter input/output item type conversion";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FreqXlatingFirFilter::init()
|
|
||||||
{
|
|
||||||
std::string default_input_item_type = "gr_complex";
|
|
||||||
std::string default_output_item_type = "gr_complex";
|
|
||||||
std::string default_taps_item_type = "float";
|
|
||||||
std::string default_dump_filename = "../data/input_filter.dat";
|
|
||||||
double default_intermediate_freq = 0.0;
|
|
||||||
double default_sampling_freq = 4000000.0;
|
|
||||||
int default_number_of_taps = 6;
|
|
||||||
unsigned int default_number_of_bands = 2;
|
|
||||||
std::vector<double> default_bands = {0.0, 0.4, 0.6, 1.0};
|
|
||||||
std::vector<double> default_ampl = {1.0, 1.0, 0.0, 0.0};
|
|
||||||
std::vector<double> default_error_w = {1.0, 1.0};
|
|
||||||
std::string default_filter_type = "bandpass";
|
|
||||||
int default_grid_density = 16;
|
|
||||||
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
intermediate_freq_ = config_->property(role_ + ".IF", default_intermediate_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);
|
|
||||||
unsigned int number_of_bands = config_->property(role_ + ".number_of_bands", default_number_of_bands);
|
|
||||||
std::string filter_type = config_->property(role_ + ".filter_type", default_filter_type);
|
|
||||||
|
|
||||||
if (filter_type.compare("lowpass") != 0)
|
|
||||||
{
|
|
||||||
std::vector<double> taps_d;
|
|
||||||
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_ / 10.0;
|
|
||||||
double tw_ = config_->property(role_ + ".tw", default_tw);
|
|
||||||
taps_ = gr::filter::firdes::low_pass(1.0, sampling_freq_, bw_, tw_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -95,6 +95,7 @@ private:
|
|||||||
gr::filter::freq_xlating_fir_filter_fcf::sptr freq_xlating_fir_filter_fcf_;
|
gr::filter::freq_xlating_fir_filter_fcf::sptr freq_xlating_fir_filter_fcf_;
|
||||||
gr::filter::freq_xlating_fir_filter_scf::sptr freq_xlating_fir_filter_scf_;
|
gr::filter::freq_xlating_fir_filter_scf::sptr freq_xlating_fir_filter_scf_;
|
||||||
ConfigurationInterface* config_;
|
ConfigurationInterface* config_;
|
||||||
|
int decimation_factor_;
|
||||||
bool dump_;
|
bool dump_;
|
||||||
std::string dump_filename_;
|
std::string dump_filename_;
|
||||||
std::string input_item_type_;
|
std::string input_item_type_;
|
||||||
@ -114,7 +115,6 @@ private:
|
|||||||
gr::blocks::float_to_short::sptr float_to_short_2_;
|
gr::blocks::float_to_short::sptr float_to_short_2_;
|
||||||
short_x2_to_cshort_sptr short_x2_to_cshort_;
|
short_x2_to_cshort_sptr short_x2_to_cshort_;
|
||||||
complex_float_to_complex_byte_sptr complex_to_complex_byte_;
|
complex_float_to_complex_byte_sptr complex_to_complex_byte_;
|
||||||
void init();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GNSS_SDR_FREQ_XLATING_FIR_FILTER_H_
|
#endif // GNSS_SDR_FREQ_XLATING_FIR_FILTER_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user