diff options
Diffstat (limited to 'host/utils')
-rw-r--r-- | host/utils/usrp_cal_rx_iq_balance.cpp | 20 | ||||
-rw-r--r-- | host/utils/usrp_cal_tx_dc_offset.cpp | 22 | ||||
-rw-r--r-- | host/utils/usrp_cal_tx_iq_balance.cpp | 20 | ||||
-rw-r--r-- | host/utils/usrp_cal_utils.hpp | 27 |
4 files changed, 60 insertions, 29 deletions
diff --git a/host/utils/usrp_cal_rx_iq_balance.cpp b/host/utils/usrp_cal_rx_iq_balance.cpp index 7b7fdaec9..7924323a5 100644 --- a/host/utils/usrp_cal_rx_iq_balance.cpp +++ b/host/utils/usrp_cal_rx_iq_balance.cpp @@ -115,7 +115,8 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer:: **********************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::string args; - double rate, tx_wave_ampl, tx_offset, freq_step, tx_gain, rx_gain; + double rate, tx_wave_ampl, tx_offset; + double freq_start, freq_stop, freq_step; size_t nsamps; po::options_description desc("Allowed options"); @@ -126,8 +127,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("rate", po::value<double>(&rate)->default_value(12.5e6), "RX and TX sample rate in Hz") ("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts") ("tx_offset", po::value<double>(&tx_offset)->default_value(.9344e6), "TX LO offset from the RX LO in Hz") - ("tx_gain", po::value<double>(&tx_gain)->default_value(0), "TX gain in dB") - ("rx_gain", po::value<double>(&rx_gain)->default_value(0), "RX gain in dB") + ("freq_start", po::value<double>(&freq_start), "Frequency start in Hz (do not specify for default)") + ("freq_stop", po::value<double>(&freq_stop), "Frequency stop in Hz (do not specify for default)") ("freq_step", po::value<double>(&freq_step)->default_value(default_freq_step), "Step size for LO sweep in Hz") ("nsamps", po::value<size_t>(&nsamps)->default_value(default_num_samps), "Samples per data capture") ; @@ -157,14 +158,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ usrp->set_rx_antenna("CAL"); usrp->set_tx_antenna("CAL"); + //set optimum gain settings + set_optimum_gain(usrp); + //set the sample rates usrp->set_rx_rate(rate); usrp->set_tx_rate(rate); - //set midrange rx gain, default 0 tx gain - usrp->set_tx_gain(tx_gain); - usrp->set_rx_gain(rx_gain); - //create a receive streamer uhd::stream_args_t stream_args("fc32"); //complex floats uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args); @@ -179,8 +179,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //store the results here std::vector<result_t> results; - const uhd::meta_range_t freq_range = usrp->get_rx_freq_range(); - for (double rx_lo_i = freq_range.start()+50e6; rx_lo_i < freq_range.stop()-50e6; rx_lo_i += freq_step){ + if (not vm.count("freq_start")) freq_start = usrp->get_rx_freq_range().start() + 50e6; + if (not vm.count("freq_stop")) freq_stop = usrp->get_rx_freq_range().stop() - 50e6; + + for (double rx_lo_i = freq_start; rx_lo_i <= freq_stop; rx_lo_i += freq_step){ const double rx_lo = tune_rx_and_tx(usrp, rx_lo_i, tx_offset); //frequency constants for this tune event diff --git a/host/utils/usrp_cal_tx_dc_offset.cpp b/host/utils/usrp_cal_tx_dc_offset.cpp index 2c75242c7..8615e231c 100644 --- a/host/utils/usrp_cal_tx_dc_offset.cpp +++ b/host/utils/usrp_cal_tx_dc_offset.cpp @@ -116,7 +116,8 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer:: **********************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::string args; - double rate, tx_wave_freq, tx_wave_ampl, rx_offset, freq_step, tx_gain, rx_gain; + double rate, tx_wave_freq, tx_wave_ampl, rx_offset; + double freq_start, freq_stop, freq_step; size_t nsamps; po::options_description desc("Allowed options"); @@ -128,8 +129,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("tx_wave_freq", po::value<double>(&tx_wave_freq)->default_value(507.123e3), "Transmit wave frequency in Hz") ("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts") ("rx_offset", po::value<double>(&rx_offset)->default_value(.9344e6), "RX LO offset from the TX LO in Hz") - ("tx_gain", po::value<double>(&tx_gain)->default_value(0), "TX gain in dB") - ("rx_gain", po::value<double>(&rx_gain)->default_value(0), "RX gain in dB") + ("freq_start", po::value<double>(&freq_start), "Frequency start in Hz (do not specify for default)") + ("freq_stop", po::value<double>(&freq_stop), "Frequency stop in Hz (do not specify for default)") ("freq_step", po::value<double>(&freq_step)->default_value(default_freq_step), "Step size for LO sweep in Hz") ("nsamps", po::value<size_t>(&nsamps)->default_value(default_num_samps), "Samples per data capture") ; @@ -159,14 +160,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ usrp->set_rx_antenna("CAL"); usrp->set_tx_antenna("CAL"); + //set optimum gain settings + set_optimum_gain(usrp); + //set the sample rates usrp->set_rx_rate(rate); usrp->set_tx_rate(rate); - //set midrange rx gain, default 0 tx gain - usrp->set_tx_gain(tx_gain); - usrp->set_rx_gain(rx_gain); - //create a receive streamer uhd::stream_args_t stream_args("fc32"); //complex floats uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args); @@ -181,8 +181,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //store the results here std::vector<result_t> results; - const uhd::meta_range_t freq_range = usrp->get_tx_freq_range(); - for (double tx_lo_i = freq_range.start()+50e6; tx_lo_i < freq_range.stop()-50e6; tx_lo_i += freq_step){ + if (not vm.count("freq_start")) freq_start = usrp->get_tx_freq_range().start() + 50e6; + if (not vm.count("freq_stop")) freq_stop = usrp->get_tx_freq_range().stop() - 50e6; + + for (double tx_lo_i = freq_start; tx_lo_i <= freq_stop; tx_lo_i += freq_step){ const double tx_lo = tune_rx_and_tx(usrp, tx_lo_i, rx_offset); //frequency constants for this tune event @@ -235,7 +237,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ dc_q_stop = best_dc_q + dc_q_step; } - if (lowest_offset < -90){ //most likely valid, keep result + if (lowest_offset < initial_dc_dbrms){ //most likely valid, keep result result_t result; result.freq = tx_lo; result.real_corr = best_dc_i; diff --git a/host/utils/usrp_cal_tx_iq_balance.cpp b/host/utils/usrp_cal_tx_iq_balance.cpp index c7cda49c7..29b6f5ede 100644 --- a/host/utils/usrp_cal_tx_iq_balance.cpp +++ b/host/utils/usrp_cal_tx_iq_balance.cpp @@ -116,7 +116,8 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer:: **********************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::string args; - double rate, tx_wave_freq, tx_wave_ampl, rx_offset, freq_step, tx_gain, rx_gain; + double rate, tx_wave_freq, tx_wave_ampl, rx_offset; + double freq_start, freq_stop, freq_step; size_t nsamps; po::options_description desc("Allowed options"); @@ -128,8 +129,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("tx_wave_freq", po::value<double>(&tx_wave_freq)->default_value(507.123e3), "Transmit wave frequency in Hz") ("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts") ("rx_offset", po::value<double>(&rx_offset)->default_value(.9344e6), "RX LO offset from the TX LO in Hz") - ("tx_gain", po::value<double>(&tx_gain)->default_value(0), "TX gain in dB") - ("rx_gain", po::value<double>(&rx_gain)->default_value(0), "RX gain in dB") + ("freq_start", po::value<double>(&freq_start), "Frequency start in Hz (do not specify for default)") + ("freq_stop", po::value<double>(&freq_stop), "Frequency stop in Hz (do not specify for default)") ("freq_step", po::value<double>(&freq_step)->default_value(default_freq_step), "Step size for LO sweep in Hz") ("nsamps", po::value<size_t>(&nsamps)->default_value(default_num_samps), "Samples per data capture") ; @@ -159,14 +160,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ usrp->set_rx_antenna("CAL"); usrp->set_tx_antenna("CAL"); + //set optimum gain settings + set_optimum_gain(usrp); + //set the sample rates usrp->set_rx_rate(rate); usrp->set_tx_rate(rate); - //set midrange rx gain, default 0 tx gain - usrp->set_tx_gain(tx_gain); - usrp->set_rx_gain(rx_gain); - //create a receive streamer uhd::stream_args_t stream_args("fc32"); //complex floats uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args); @@ -181,8 +181,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //store the results here std::vector<result_t> results; - const uhd::meta_range_t freq_range = usrp->get_tx_freq_range(); - for (double tx_lo_i = freq_range.start()+50e6; tx_lo_i < freq_range.stop()-50e6; tx_lo_i += freq_step){ + if (not vm.count("freq_start")) freq_start = usrp->get_tx_freq_range().start() + 50e6; + if (not vm.count("freq_stop")) freq_stop = usrp->get_tx_freq_range().stop() - 50e6; + + for (double tx_lo_i = freq_start; tx_lo_i <= freq_stop; tx_lo_i += freq_step){ const double tx_lo = tune_rx_and_tx(usrp, tx_lo_i, rx_offset); //frequency constants for this tune event diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp index c08d869ed..5378b0d69 100644 --- a/host/utils/usrp_cal_utils.hpp +++ b/host/utils/usrp_cal_utils.hpp @@ -39,10 +39,35 @@ static const size_t wave_table_len = 8192; static const size_t num_search_steps = 5; static const size_t num_search_iters = 7; static const size_t skip_initial_samps = 20; -static const double default_freq_step = 13.7e6; +static const double default_freq_step = 7.3e6; static const size_t default_num_samps = 10000; /*********************************************************************** + * Determine gain settings + **********************************************************************/ +static inline void set_optimum_gain(uhd::usrp::multi_usrp::sptr usrp){ + uhd::property_tree::sptr tree = usrp->get_device()->get_tree(); + const uhd::fs_path tx_fe_path = "/mboards/0/dboards/A/tx_frontends/0"; + const std::string tx_name = tree->access<std::string>(tx_fe_path / "name").get(); + if (tx_name.find("WBX") != std::string::npos or tx_name.find("SBX") != std::string::npos){ + usrp->set_tx_gain(0); + } + else{ + throw std::runtime_error("self-calibration is not supported for this hardware"); + } + + const uhd::fs_path rx_fe_path = "/mboards/0/dboards/A/tx_frontends/0"; + const std::string rx_name = tree->access<std::string>(rx_fe_path / "name").get(); + if (rx_name.find("WBX") != std::string::npos or rx_name.find("SBX") != std::string::npos){ + usrp->set_rx_gain(25); + } + else{ + throw std::runtime_error("self-calibration is not supported for this hardware"); + } + +} + +/*********************************************************************** * Sinusoid wave table **********************************************************************/ static inline std::vector<std::complex<float> > gen_table(void){ |