mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-25 20:47:39 +00:00 
			
		
		
		
	Implement FIR filter configuration
This commit is contained in:
		| @@ -2577,7 +2577,7 @@ add_feature_info(ENABLE_UHD ENABLE_UHD "Enables UHD_Signal_Source for using RF f | ||||
| add_feature_info(ENABLE_OSMOSDR ENABLE_OSMOSDR "Enables Osmosdr_Signal_Source and RtlTcp_Signal_Source for using RF front-ends compatible with the OsmoSDR driver. Requires gr-osmosdr.") | ||||
| add_feature_info(ENABLE_FMCOMMS2 ENABLE_FMCOMMS2 "Enables Fmcomms2_Signal_Source for FMCOMMS2/3/4 devices. Requires gr-iio.") | ||||
| add_feature_info(ENABLE_PLUTOSDR ENABLE_PLUTOSDR "Enables Plutosdr_Signal_Source for using ADALM-PLUTO boards. Requires gr-iio.") | ||||
| add_feature_info(ENABLE_AD9361 ENABLE_AD9361 "Enables Ad9361_Fpga_Signal_Source for devices with the AD9361 chipset. Requires libiio.") | ||||
| add_feature_info(ENABLE_AD9361 ENABLE_AD9361 "Enables Ad9361_Fpga_Signal_Source for devices with the AD9361 chipset. Requires libiio and libad9361.") | ||||
| add_feature_info(ENABLE_RAW_UDP ENABLE_RAW_UDP "Enables Custom_UDP_Signal_Source for custom UDP packet sample source. Requires libpcap.") | ||||
| add_feature_info(ENABLE_FLEXIBAND ENABLE_FLEXIBAND "Enables Flexiband_Signal_Source for using Teleorbit's Flexiband RF front-end. Requires gr-teleorbit.") | ||||
| add_feature_info(ENABLE_GN3S ENABLE_GN3S "Enables Gn3s_Signal_Source for using the GN3S v2 dongle. Requires gr-gn3s.") | ||||
|   | ||||
| @@ -74,7 +74,7 @@ find_library( | ||||
|           /usr/local/lib | ||||
|           /usr/local/lib64 | ||||
|           /opt/local/lib | ||||
|           /Library/Frameworks/iio.framework/ | ||||
|           /Library/Frameworks/ad9361.framework | ||||
|           ${CMAKE_INSTALL_PREFIX}/lib | ||||
|           ${CMAKE_INSTALL_PREFIX}/lib64 | ||||
|           ${LIBAD9361_ROOT}/lib | ||||
| @@ -99,11 +99,11 @@ endif() | ||||
|  | ||||
| if(LIBAD9361_FOUND AND LIBAD9361_VERSION) | ||||
|     set_package_properties(LIBAD9361 PROPERTIES | ||||
|         DESCRIPTION "A library for interfacing with AD936X transceivers (found: v${LIBAD9361_VERSION})" | ||||
|         DESCRIPTION "A library for interfacing with AD936X RF transceivers (found: v${LIBAD9361_VERSION})" | ||||
|     ) | ||||
| else() | ||||
|     set_package_properties(LIBAD9361 PROPERTIES | ||||
|         DESCRIPTION "A library for interfacing with AD936X transceivers" | ||||
|         DESCRIPTION "A library for interfacing with AD936X RF transceivers" | ||||
|     ) | ||||
| endif() | ||||
|  | ||||
|   | ||||
| @@ -279,7 +279,7 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura | ||||
|     const std::string &role, unsigned int in_stream, unsigned int out_stream, | ||||
|     std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue) : role_(role), in_stream_(in_stream), out_stream_(out_stream), queue_(std::move(queue)) | ||||
| { | ||||
|     std::string default_gain_mode("slow attack"); | ||||
|     std::string default_gain_mode("slow_attack"); | ||||
|     double default_tx_attenuation_db = -10.0; | ||||
|     double default_manual_gain_rx1 = 64.0; | ||||
|     double default_manual_gain_rx2 = 64.0; | ||||
| @@ -297,8 +297,18 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura | ||||
|     rf_gain_rx2_ = configuration->property(role + ".gain_rx2", default_manual_gain_rx2); | ||||
|     rf_port_select_ = configuration->property(role + ".rf_port_select", default_rf_port_select); | ||||
|     filter_file_ = configuration->property(role + ".filter_file", std::string("")); | ||||
|     filter_filename_ = configuration->property(role + ".filter_filename", filter_file_); | ||||
|     filter_auto_ = configuration->property(role + ".filter_auto", false); | ||||
|  | ||||
|     if (filter_auto_) | ||||
|         { | ||||
|             filter_source_ = configuration->property(role + ".filter_source", std::string("Auto")); | ||||
|         } | ||||
|     else | ||||
|         { | ||||
|             filter_source_ = configuration->property(role + ".filter_source", std::string("Off")); | ||||
|         } | ||||
|     Fpass_ = configuration->property(role + ".Fpass", 0.0); | ||||
|     Fstop_ = configuration->property(role + ".Fstop", 0.0); | ||||
|     enable_dds_lo_ = configuration->property(role + ".enable_dds_lo", false); | ||||
|     freq_dds_tx_hz_ = configuration->property(role + ".freq_dds_tx_hz", 1000); | ||||
|     freq_rf_tx_hz_ = configuration->property(role + ".freq_rf_tx_hz", GPS_L1_FREQ_HZ - GPS_L2_FREQ_HZ - freq_dds_tx_hz_); | ||||
| @@ -410,6 +420,19 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura | ||||
|                         } | ||||
|                 } | ||||
|  | ||||
|             if ((filter_source_ != "Off") and (filter_source_ != "Auto") and (filter_source_ != "File") and (filter_source_ != "Design")) | ||||
|                 { | ||||
|                     std::cout << "Configuration parameter filter_source should take one of these values:" << std::endl; | ||||
|                     std::cout << "  Off: Disable filter" << std::endl; | ||||
|                     std::cout << "  Auto: Use auto-generated filters" << std::endl; | ||||
|                     std::cout << "  File: User-provided filter in filter_filename parameter" << std::endl; | ||||
|                     std::cout << "  Design: Create filter from Fpass, Fstop, sampling_frequency and bandwidth parameters" << std::endl; | ||||
|                     std::cout << "Error: provided value filter_source=" << filter_source_ << " is not among valid values" << std::endl; | ||||
|                     std::cout << " This parameter has been set to its default value filter_source=Off" << std::endl; | ||||
|                     filter_source_ = std::string("Off"); | ||||
|                     LOG(WARNING) << "Invalid configuration value for filter_source parameter. Set to filter_source=Off"; | ||||
|                 } | ||||
|  | ||||
|             if (bandwidth_ < 200000 or bandwidth_ > 56000000) | ||||
|                 { | ||||
|                     std::cout << "Configuration parameter bandwidth should take values between 200000 and 56000000 Hz" << std::endl; | ||||
| @@ -432,7 +455,11 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura | ||||
|                         rf_gain_rx2_, | ||||
|                         quadrature_, | ||||
|                         rf_dc_, | ||||
|                         bb_dc_); | ||||
|                         bb_dc_, | ||||
|                         filter_source_, | ||||
|                         filter_filename_, | ||||
|                         Fpass_, | ||||
|                         Fstop_); | ||||
|                 } | ||||
|             catch (const std::runtime_error &e) | ||||
|                 { | ||||
|   | ||||
| @@ -93,6 +93,10 @@ private: | ||||
|     std::string rf_port_select_; | ||||
|     std::string filter_file_; | ||||
|     bool filter_auto_; | ||||
|     std::string filter_source_; | ||||
|     std::string filter_filename_; | ||||
|     float Fpass_; | ||||
|     float Fstop_; | ||||
|  | ||||
|     // DDS configuration for LO generation for external mixer | ||||
|     bool enable_dds_lo_; | ||||
|   | ||||
| @@ -48,7 +48,7 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration | ||||
| { | ||||
|     std::string default_item_type = "gr_complex"; | ||||
|     std::string default_dump_file = "./data/signal_source.dat"; | ||||
|     std::string default_gain_mode("slow attack"); | ||||
|     std::string default_gain_mode("slow_attack"); | ||||
|     double default_tx_attenuation_db = -10.0; | ||||
|     uri_ = configuration->property(role + ".device_address", std::string("192.168.2.1")); | ||||
|     freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); | ||||
|   | ||||
| @@ -43,7 +43,7 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration | ||||
| { | ||||
|     std::string default_item_type = "gr_complex"; | ||||
|     std::string default_dump_file = "./data/signal_source.dat"; | ||||
|     std::string default_gain_mode("slow attack"); | ||||
|     std::string default_gain_mode("slow_attack"); | ||||
|     uri_ = configuration->property(role + ".device_address", std::string("192.168.2.1")); | ||||
|     freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); | ||||
|     sample_rate_ = configuration->property(role + ".sampling_frequency", 3000000); | ||||
|   | ||||
| @@ -188,23 +188,21 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, | ||||
|     double rf_gain_rx2_, | ||||
|     bool quadrature_, | ||||
|     bool rfdc_, | ||||
|     bool bbdc_) | ||||
|     bool bbdc_, | ||||
|     std::string filter_source_, | ||||
|     std::string filter_filename_, | ||||
|     float Fpass_, | ||||
|     float Fstop_) | ||||
|  | ||||
| { | ||||
|     // RX stream config | ||||
|     // Stream configurations | ||||
|     struct stream_cfg rxcfg; | ||||
|     rxcfg.bw_hz = bandwidth_; | ||||
|     rxcfg.fs_hz = sample_rate_; | ||||
|     rxcfg.lo_hz = freq_; | ||||
|     rxcfg.rfport = rf_port_select_.c_str(); | ||||
|  | ||||
|     std::cout << "AD9361 Acquiring IIO LOCAL context\n"; | ||||
|     struct iio_context *ctx; | ||||
|     // Streaming devices | ||||
|     struct iio_device *rx; | ||||
|     struct iio_channel *rx_chan1; | ||||
|     struct iio_channel *rx_chan2; | ||||
|     int ret; | ||||
|  | ||||
|     ctx = iio_create_default_context(); | ||||
|     if (!ctx) | ||||
| @@ -219,21 +217,16 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, | ||||
|             throw std::runtime_error("AD9361 IIO No devices"); | ||||
|         } | ||||
|  | ||||
|     std::cout << "* Acquiring AD9361 streaming devices\n"; | ||||
|     struct iio_device *ad9361_phy; | ||||
|     ad9361_phy = iio_context_find_device(ctx, "ad9361-phy"); | ||||
|  | ||||
|     std::cout << "* Acquiring AD9361 streaming devices\n"; | ||||
|     if (!get_ad9361_stream_dev(ctx, RX, &rx)) | ||||
|         { | ||||
|             std::cout << "No rx dev found\n"; | ||||
|             throw std::runtime_error("AD9361 IIO No rx dev found"); | ||||
|         }; | ||||
|  | ||||
|     std::cout << "* Configuring AD9361 for streaming\n"; | ||||
|     if (!cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, 0)) | ||||
|         { | ||||
|             std::cout << "RX port 0 not found\n"; | ||||
|             throw std::runtime_error("AD9361 IIO RX port 0 not found"); | ||||
|         } | ||||
|  | ||||
|     std::cout << "* Initializing AD9361 IIO streaming channels\n"; | ||||
|     if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1)) | ||||
|         { | ||||
| @@ -247,13 +240,106 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, | ||||
|             throw std::runtime_error("RX channel 2 not found"); | ||||
|         } | ||||
|  | ||||
|     if (filter_source_ == "Off") | ||||
|         { | ||||
|             struct stream_cfg rxcfg; | ||||
|             rxcfg.bw_hz = bandwidth_; | ||||
|             rxcfg.fs_hz = sample_rate_; | ||||
|             rxcfg.lo_hz = freq_; | ||||
|             rxcfg.rfport = rf_port_select_.c_str(); | ||||
|  | ||||
|             if (!cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, 0)) | ||||
|                 { | ||||
|                     std::cout << "RX port 0 not found\n"; | ||||
|                     throw std::runtime_error("AD9361 IIO RX port 0 not found"); | ||||
|                 } | ||||
|         } | ||||
|     else if (filter_source_ == "Auto") | ||||
|         { | ||||
|             ret = ad9361_set_bb_rate(ad9361_phy, sample_rate_); | ||||
|             if (ret) | ||||
|                 { | ||||
|                     throw std::runtime_error("Unable to set BB rate"); | ||||
|                     // set bw | ||||
|                     //params.push_back("in_voltage_rf_bandwidth=" + boost::to_string(bandwidth)); | ||||
|                 } | ||||
|             //wr_ch_str(rx_chan1, "rf_port_select", rf_port_select_.c_str()); | ||||
|             ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); | ||||
|             if (ret) | ||||
|                 { | ||||
|                     throw std::runtime_error("Unable to set rf_port_select"); | ||||
|                 } | ||||
|             wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); | ||||
|             if (!get_lo_chan(ctx, RX, &rx_chan1)) | ||||
|                 { | ||||
|                     return false; | ||||
|                 } | ||||
|             wr_ch_lli(rx_chan1, "frequency", freq_); | ||||
|         } | ||||
|     else if (filter_source_ == "File") | ||||
|         { | ||||
|             try | ||||
|                 { | ||||
|                     if (!load_fir_filter(filter_filename_, ad9361_phy)) | ||||
|                         { | ||||
|                             throw std::runtime_error("Unable to load filter file"); | ||||
|                         } | ||||
|                 } | ||||
|             catch (const std::runtime_error &e) | ||||
|                 { | ||||
|                     std::cout << "Exception cached when configuring the RX FIR filter: " << e.what() << std::endl; | ||||
|                 } | ||||
|             ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); | ||||
|             if (ret) | ||||
|                 { | ||||
|                     throw std::runtime_error("Unable to set rf_port_select"); | ||||
|                 } | ||||
|             wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); | ||||
|             if (!get_lo_chan(ctx, RX, &rx_chan1)) | ||||
|                 { | ||||
|                     return false; | ||||
|                 } | ||||
|             wr_ch_lli(rx_chan1, "frequency", freq_); | ||||
|         } | ||||
|     else if (filter_source_ == "Design") | ||||
|         { | ||||
|             ret = ad9361_set_bb_rate_custom_filter_manual( | ||||
|                 ad9361_phy, sample_rate_, static_cast<uint64_t>(Fpass_), static_cast<uint64_t>(Fstop_), bandwidth_, bandwidth_); | ||||
|             if (ret) | ||||
|                 { | ||||
|                     throw std::runtime_error("Unable to set BB rate"); | ||||
|                 } | ||||
|             ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); | ||||
|             if (ret) | ||||
|                 { | ||||
|                     throw std::runtime_error("Unable to set rf_port_select"); | ||||
|                 } | ||||
|             wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); | ||||
|             if (!get_lo_chan(ctx, RX, &rx_chan1)) | ||||
|                 { | ||||
|                     return false; | ||||
|                 } | ||||
|             wr_ch_lli(rx_chan1, "frequency", freq_); | ||||
|         } | ||||
|     else | ||||
|         { | ||||
|             throw std::runtime_error("Unknown filter configuration"); | ||||
|         } | ||||
|  | ||||
|     // Filters can only be disabled after the sample rate has been set | ||||
|     if (filter_source_ == "Off") | ||||
|         { | ||||
|             ret = ad9361_set_trx_fir_enable(ad9361_phy, false); | ||||
|             if (ret) | ||||
|                 { | ||||
|                     throw std::runtime_error("Unable to disable filters"); | ||||
|                 } | ||||
|         } | ||||
|  | ||||
|     std::cout << "* Enabling IIO streaming channels\n"; | ||||
|     iio_channel_enable(rx_chan1); | ||||
|     iio_channel_enable(rx_chan2); | ||||
|  | ||||
|     struct iio_device *ad9361_phy; | ||||
|     ad9361_phy = iio_context_find_device(ctx, "ad9361-phy"); | ||||
|     int ret; | ||||
|     ret = iio_device_attr_write(ad9361_phy, "trx_rate_governor", "nominal"); | ||||
|     if (ret < 0) | ||||
|         { | ||||
| @@ -322,13 +408,13 @@ bool config_ad9361_rx_remote(const std::string &remote_host, | ||||
|     double rf_gain_rx2_, | ||||
|     bool quadrature_, | ||||
|     bool rfdc_, | ||||
|     bool bbdc_) | ||||
|     bool bbdc_, | ||||
|     std::string filter_source_, | ||||
|     std::string filter_filename_, | ||||
|     float Fpass_, | ||||
|     float Fstop_) | ||||
| { | ||||
|     std::string filter_source_("Off"); | ||||
|     float Fpass_ = 0.0, Fstop_ = 0.0; | ||||
|     std::string filter_filename_; | ||||
|     // RX stream config | ||||
|  | ||||
|     std::cout << "AD9361 Acquiring IIO REMOTE context in host " << remote_host << std::endl; | ||||
|     struct iio_context *ctx; | ||||
|     // Streaming devices | ||||
|   | ||||
| @@ -92,7 +92,11 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, | ||||
|     double rf_gain_rx2_, | ||||
|     bool quadrature_, | ||||
|     bool rfdc_, | ||||
|     bool bbdc_); | ||||
|     bool bbdc_, | ||||
|     std::string filter_source_, | ||||
|     std::string filter_filename_, | ||||
|     float Fpass_, | ||||
|     float Fstop_); | ||||
|  | ||||
| bool config_ad9361_rx_remote(const std::string &remote_host, | ||||
|     uint64_t bandwidth_, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Carles Fernandez
					Carles Fernandez