summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-11-10 20:22:54 -0800
committerJosh Blum <josh@joshknows.com>2011-11-10 20:22:54 -0800
commit8459432067055759bd1d9b04f0e7943f1cf35d2d (patch)
treeb647f54fa9ccbbcd289acc21a8806e940b7a9c4b /host
parent3cb60c974fff6779396294fd456904d1f6addd71 (diff)
downloaduhd-8459432067055759bd1d9b04f0e7943f1cf35d2d.tar.gz
uhd-8459432067055759bd1d9b04f0e7943f1cf35d2d.tar.bz2
uhd-8459432067055759bd1d9b04f0e7943f1cf35d2d.zip
usrp: basically working iq cal on tx
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/utils/CMakeLists.txt2
-rw-r--r--host/include/uhd/utils/csv.hpp35
-rw-r--r--host/include/uhd/utils/paths.hpp34
-rw-r--r--host/lib/usrp/common/CMakeLists.txt1
-rw-r--r--host/lib/usrp/common/apply_corrections.cpp136
-rw-r--r--host/lib/usrp/common/apply_corrections.hpp35
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp12
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp2
-rw-r--r--host/lib/utils/CMakeLists.txt1
-rw-r--r--host/lib/utils/csv.cpp52
-rw-r--r--host/lib/utils/paths.cpp27
-rw-r--r--host/utils/usrp_gen_db_cal_table.cpp92
12 files changed, 396 insertions, 33 deletions
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index 48b8db885..5a434fd9a 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -21,10 +21,12 @@ INSTALL(FILES
assert_has.ipp
byteswap.hpp
byteswap.ipp
+ csv.hpp
gain_group.hpp
images.hpp
log.hpp
msg.hpp
+ paths.hpp
pimpl.hpp
safe_call.hpp
safe_main.hpp
diff --git a/host/include/uhd/utils/csv.hpp b/host/include/uhd/utils/csv.hpp
new file mode 100644
index 000000000..8dbb28377
--- /dev/null
+++ b/host/include/uhd/utils/csv.hpp
@@ -0,0 +1,35 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_UTILS_CSV_HPP
+#define INCLUDED_UHD_UTILS_CSV_HPP
+
+#include <uhd/config.hpp>
+#include <vector>
+#include <string>
+#include <istream>
+
+namespace uhd{ namespace csv{
+ typedef std::vector<std::string> row_type;
+ typedef std::vector<row_type> rows_type;
+
+ //! Convert an input stream to csv rows.
+ UHD_API rows_type to_rows(std::istream &input);
+
+}} //namespace uhd::csv
+
+#endif /* INCLUDED_UHD_UTILS_CSV_HPP */
diff --git a/host/include/uhd/utils/paths.hpp b/host/include/uhd/utils/paths.hpp
new file mode 100644
index 000000000..2261f1b77
--- /dev/null
+++ b/host/include/uhd/utils/paths.hpp
@@ -0,0 +1,34 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_UTILS_PATHS_HPP
+#define INCLUDED_UHD_UTILS_PATHS_HPP
+
+#include <uhd/config.hpp>
+#include <string>
+
+namespace uhd{
+
+ //! Get a string representing the system's temporary directory
+ UHD_API std::string get_tmp_path(void);
+
+ //! Get a string representing the system's appdata directory
+ UHD_API std::string get_app_path(void);
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_UTILS_PATHS_HPP */
diff --git a/host/lib/usrp/common/CMakeLists.txt b/host/lib/usrp/common/CMakeLists.txt
index ec8b60fec..9abd34afa 100644
--- a/host/lib/usrp/common/CMakeLists.txt
+++ b/host/lib/usrp/common/CMakeLists.txt
@@ -29,6 +29,7 @@ ENDIF(ENABLE_USB)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
LIBUHD_APPEND_SOURCES(
+ ${CMAKE_CURRENT_SOURCE_DIR}/apply_corrections.cpp
${CMAKE_CURRENT_SOURCE_DIR}/validate_subdev_spec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/recv_packet_demuxer.cpp
)
diff --git a/host/lib/usrp/common/apply_corrections.cpp b/host/lib/usrp/common/apply_corrections.cpp
new file mode 100644
index 000000000..95036e386
--- /dev/null
+++ b/host/lib/usrp/common/apply_corrections.cpp
@@ -0,0 +1,136 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include "apply_corrections.hpp"
+#include <uhd/usrp/dboard_eeprom.hpp>
+#include <uhd/utils/paths.hpp>
+#include <uhd/utils/msg.hpp>
+#include <uhd/utils/csv.hpp>
+#include <uhd/types/dict.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/foreach.hpp>
+#include <cstdio>
+#include <complex>
+#include <fstream>
+
+namespace fs = boost::filesystem;
+
+struct tx_fe_cal_t{
+ double tx_lo_freq;
+ double iq_corr_real;
+ double iq_corr_imag;
+};
+
+static bool tx_fe_cal_comp(tx_fe_cal_t a, tx_fe_cal_t b){
+ return (a.tx_lo_freq < b.tx_lo_freq);
+}
+
+//TODO should lock access to this
+static uhd::dict<std::string, std::vector<tx_fe_cal_t> > cache;
+
+static double linear_interp(double x, double x0, double y0, double x1, double y1){
+ return y0 + (x - x0)*(y1 - y0)/(x1 - x0);
+}
+
+static std::complex<double> get_tx_fe_iq_correction(
+ const std::string &key, const double tx_lo_freq
+){
+ const std::vector<tx_fe_cal_t> &datas = cache[key];
+
+ //search for lo freq
+ size_t lo_index = 0;
+ size_t hi_index = datas.size()-1;
+ for (size_t i = 0; i < datas.size(); i++){
+ if (datas[i].tx_lo_freq > tx_lo_freq){
+ hi_index = i;
+ break;
+ }
+ lo_index = i;
+ }
+
+ if (lo_index == 0) return std::complex<double>(datas[lo_index].iq_corr_real, datas[lo_index].iq_corr_imag);
+ if (hi_index == lo_index) return std::complex<double>(datas[hi_index].iq_corr_real, datas[hi_index].iq_corr_imag);
+
+ //interpolation time
+ return std::complex<double>(
+ linear_interp(tx_lo_freq, datas[lo_index].tx_lo_freq, datas[lo_index].iq_corr_real, datas[hi_index].tx_lo_freq, datas[hi_index].iq_corr_real),
+ linear_interp(tx_lo_freq, datas[lo_index].tx_lo_freq, datas[lo_index].iq_corr_imag, datas[hi_index].tx_lo_freq, datas[hi_index].iq_corr_imag)
+ );
+}
+
+static void _apply_tx_fe_corrections(
+ uhd::property_tree::sptr sub_tree, //starts at mboards/x
+ const std::string &slot, //name of dboard slot
+ const double tx_lo_freq //actual lo freq
+){
+ //path constants
+ const uhd::fs_path tx_db_path = "dboards/" + slot + "/tx_eeprom";
+ const uhd::fs_path tx_fe_path = "tx_frontends/" + slot + "/iq_balance/value";
+
+ //extract eeprom serial
+ const uhd::usrp::dboard_eeprom_t db_eeprom = sub_tree->access<uhd::usrp::dboard_eeprom_t>(tx_db_path).get();
+
+ //make the calibration file path
+ const fs::path cal_data_path = fs::path(uhd::get_app_path()) / ".uhd" / "cal" / ("tx_fe_cal_v0.1_" + db_eeprom.serial + ".csv");
+ if (not fs::exists(cal_data_path)) return;
+
+ //parse csv file or get from cache
+ if (not cache.has_key(cal_data_path.string())){
+ std::ifstream cal_data(cal_data_path.string().c_str());
+ const uhd::csv::rows_type rows = uhd::csv::to_rows(cal_data);
+
+ bool read_data = false, skip_next = false;;
+ std::vector<tx_fe_cal_t> datas;
+ BOOST_FOREACH(const uhd::csv::row_type &row, rows){
+ if (not read_data and not row.empty() and row[0] == "DATA STARTS HERE"){
+ read_data = true;
+ skip_next = true;
+ continue;
+ }
+ if (not read_data) continue;
+ if (skip_next){
+ skip_next = false;
+ continue;
+ }
+ tx_fe_cal_t data;
+ std::sscanf(row[0].c_str(), "%lf" , &data.tx_lo_freq);
+ std::sscanf(row[1].c_str(), "%lf" , &data.iq_corr_real);
+ std::sscanf(row[2].c_str(), "%lf" , &data.iq_corr_imag);
+ datas.push_back(data);
+ }
+ std::sort(datas.begin(), datas.end(), tx_fe_cal_comp);
+ cache[cal_data_path.string()] = datas;
+ UHD_MSG(status) << "Loaded " << cal_data_path.string() << std::endl;
+
+ }
+
+ sub_tree->access<std::complex<double> >(tx_fe_path)
+ .set(get_tx_fe_iq_correction(cal_data_path.string(), tx_lo_freq));
+}
+
+void uhd::usrp::apply_tx_fe_corrections(
+ property_tree::sptr sub_tree, //starts at mboards/x
+ const std::string &slot, //name of dboard slot
+ const double tx_lo_freq //actual lo freq
+){
+ try{
+ _apply_tx_fe_corrections(sub_tree, slot, tx_lo_freq);
+ }
+ catch(const std::exception &e){
+ UHD_MSG(error) << "Failure in apply_tx_fe_corrections: " << e.what() << std::endl;
+ }
+}
diff --git a/host/lib/usrp/common/apply_corrections.hpp b/host/lib/usrp/common/apply_corrections.hpp
new file mode 100644
index 000000000..8aabab636
--- /dev/null
+++ b/host/lib/usrp/common/apply_corrections.hpp
@@ -0,0 +1,35 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_LIBUHD_USRP_COMMON_APPLY_CORRECTIONS_HPP
+#define INCLUDED_LIBUHD_USRP_COMMON_APPLY_CORRECTIONS_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/property_tree.hpp>
+#include <string>
+
+namespace uhd{ namespace usrp{
+
+ void apply_tx_fe_corrections(
+ property_tree::sptr sub_tree, //starts at mboards/x
+ const std::string &slot, //name of dboard slot
+ const double tx_lo_freq //actual lo freq
+ );
+
+}} //namespace uhd::usrp
+
+#endif /* INCLUDED_LIBUHD_USRP_COMMON_APPLY_CORRECTIONS_HPP */
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index bb3bfc7e4..6170948ca 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -17,6 +17,7 @@
#include "usrp2_impl.hpp"
#include "fw_common.h"
+#include "apply_corrections.hpp"
#include <uhd/utils/log.hpp>
#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
@@ -600,6 +601,13 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){
rx_db_eeprom.id, tx_db_eeprom.id, gdb_eeprom.id,
_mbc[mb].dboard_iface, _tree->subtree(mb_path / "dboards/A")
);
+
+ //bind frontend corrections to the dboard freq props
+ const fs_path db_tx_fe_path = mb_path / "dboards" / "A" / "tx_frontends";
+ BOOST_FOREACH(const std::string &name, _tree->list(db_tx_fe_path)){
+ _tree->access<double>(db_tx_fe_path / name / "freq" / "value")
+ .subscribe(boost::bind(&usrp2_impl::set_tx_fe_corrections, this, mb, _1));
+ }
}
//initialize io handling
@@ -653,6 +661,10 @@ sensor_value_t usrp2_impl::get_ref_locked(const std::string &mb){
return sensor_value_t("Ref", lock, "locked", "unlocked");
}
+void usrp2_impl::set_tx_fe_corrections(const std::string &mb, const double tx_lo_freq){
+ apply_tx_fe_corrections(this->get_tree()->subtree("/mboards/" + mb), "A", tx_lo_freq);
+}
+
#include <boost/math/special_functions/round.hpp>
#include <boost/math/special_functions/sign.hpp>
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 535397d84..74ef3d460 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -106,6 +106,8 @@ private:
uhd::sensor_value_t get_mimo_locked(const std::string &);
uhd::sensor_value_t get_ref_locked(const std::string &);
+ void set_tx_fe_corrections(const std::string &mb, const double tx_lo_freq);
+
//device properties interface
uhd::property_tree::sptr get_tree(void) const{
return _tree;
diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt
index 19dde9a56..b50e91299 100644
--- a/host/lib/utils/CMakeLists.txt
+++ b/host/lib/utils/CMakeLists.txt
@@ -128,6 +128,7 @@ SET_SOURCE_FILES_PROPERTIES(
# Append sources
########################################################################
LIBUHD_APPEND_SOURCES(
+ ${CMAKE_CURRENT_SOURCE_DIR}/csv.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gain_group.cpp
${CMAKE_CURRENT_SOURCE_DIR}/images.cpp
${CMAKE_CURRENT_SOURCE_DIR}/load_modules.cpp
diff --git a/host/lib/utils/csv.cpp b/host/lib/utils/csv.cpp
new file mode 100644
index 000000000..2ffa70196
--- /dev/null
+++ b/host/lib/utils/csv.cpp
@@ -0,0 +1,52 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/utils/csv.hpp>
+#include <boost/foreach.hpp>
+
+using namespace uhd;
+
+csv::rows_type csv::to_rows(std::istream &input){
+ csv::rows_type rows;
+ std::string line;
+ //for each line in the input stream
+ while (std::getline(input, line)){
+ csv::row_type row(1, "");
+ bool in_quote = false;
+ char last_ch, next_ch = ' ';
+ //for each character in the line
+ BOOST_FOREACH(char ch, line){
+ last_ch = next_ch;
+ next_ch = ch;
+ //catch a quote character and change the state
+ //we handle double quotes by checking last_ch
+ if (ch == '"'){
+ in_quote = not in_quote;
+ if (last_ch != '"') continue;
+ }
+ //a comma not inside quotes is a column delimiter
+ if (not in_quote and ch == ','){
+ row.push_back("");
+ continue;
+ }
+ //if we got here we record the character
+ row.back() += ch;
+ }
+ rows.push_back(row);
+ }
+ return rows;
+}
diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp
index a3dd377e5..4fc877d5d 100644
--- a/host/lib/utils/paths.cpp
+++ b/host/lib/utils/paths.cpp
@@ -16,6 +16,7 @@
//
#include <uhd/config.hpp>
+#include <uhd/utils/paths.hpp>
#include <boost/tokenizer.hpp>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
@@ -23,6 +24,8 @@
#include <cstdlib>
#include <string>
#include <vector>
+#include <cstdlib> //getenv
+#include <cstdio> //P_tmpdir
namespace fs = boost::filesystem;
@@ -79,3 +82,27 @@ std::vector<fs::path> get_module_paths(void){
paths.push_back(get_uhd_pkg_data_path() / "modules");
return paths;
}
+
+/***********************************************************************
+ * Implement the functions in paths.hpp
+ **********************************************************************/
+std::string uhd::get_tmp_path(void){
+ const char *tmp_path = std::getenv("TMP");
+ if (tmp_path != NULL) return tmp_path;
+
+ #ifdef P_tmpdir
+ if (P_tmpdir != NULL) return P_tmpdir;
+ #endif
+
+ return "/tmp";
+}
+
+std::string uhd::get_app_path(void){
+ const char *appdata_path = std::getenv("APPDATA");
+ if (appdata_path != NULL) return appdata_path;
+
+ const char *home_path = std::getenv("HOME");
+ if (home_path != NULL) return home_path;
+
+ return uhd::get_tmp_path();
+}
diff --git a/host/utils/usrp_gen_db_cal_table.cpp b/host/utils/usrp_gen_db_cal_table.cpp
index 100e2368e..50f473809 100644
--- a/host/utils/usrp_gen_db_cal_table.cpp
+++ b/host/utils/usrp_gen_db_cal_table.cpp
@@ -17,17 +17,23 @@
#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>
+#include <uhd/utils/paths.hpp>
+#include <uhd/property_tree.hpp>
#include <uhd/usrp/multi_usrp.hpp>
+#include <uhd/usrp/dboard_eeprom.hpp>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
#include <boost/thread/thread.hpp>
+#include <boost/filesystem.hpp>
#include <boost/math/special_functions/round.hpp>
#include <iostream>
#include <fstream>
#include <complex>
#include <cmath>
+#include <ctime>
namespace po = boost::program_options;
+namespace fs = boost::filesystem;
/***********************************************************************
* Constants
@@ -74,11 +80,6 @@ static double compute_tone_dbrms(
shifted[i] = std::complex<double>(samples[i]) * std::pow(e, std::complex<double>(0, -freq*tau*i));
}
- std::vector<std::complex<float> > buff(shifted.size());
- for (size_t i = 0; i < buff.size(); i++) buff[i] = shifted[i];
- std::ofstream outfile("/home/jblum/Desktop/gen.dat", std::ofstream::binary);
- outfile.write((const char*)&buff.front(), buff.size() * 8);
-
//filter the samples with a narrow low pass
std::complex<double> iir_output = 0, iir_last = 0;
double output = 0;
@@ -169,16 +170,51 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::
}
}
- struct result_t{
- double freq, ampl, phase, sup;
- };
+/***********************************************************************
+ * Store data to file
+ **********************************************************************/
+struct result_t{double freq, real_corr, imag_corr, sup;};
+static void store_results(uhd::usrp::multi_usrp::sptr usrp, const std::vector<result_t> &results){
+ //extract eeprom serial
+ uhd::property_tree::sptr tree = usrp->get_device()->get_tree();
+ const uhd::fs_path db_path = "/mboards/0/dboards/A/tx_eeprom";
+ const uhd::usrp::dboard_eeprom_t db_eeprom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path).get();
+ if (db_eeprom.serial.empty()) throw std::runtime_error("TX dboard has empty serial!");
+
+ //make the calibration file path
+ fs::path cal_data_path = fs::path(uhd::get_app_path()) / ".uhd";
+ fs::create_directory(cal_data_path);
+ cal_data_path = cal_data_path / "cal";
+ fs::create_directory(cal_data_path);
+ cal_data_path = cal_data_path / ("tx_fe_cal_v0.1_" + db_eeprom.serial + ".csv");
+
+ //fill the calibration file
+ std::ofstream cal_data(cal_data_path.string().c_str());
+ cal_data << boost::format("name, TX Frontend Calibration\n");
+ cal_data << boost::format("serial, %s\n") % db_eeprom.serial;
+ cal_data << boost::format("timestamp, %d\n") % time(NULL);
+ cal_data << boost::format("version, 0, 1\n");
+ cal_data << boost::format("DATA STARTS HERE\n");
+ cal_data << "tx_lo_frequency, tx_iq_correction_real, tx_iq_correction_imag, measured_suppression\n";
+
+ for (size_t i = 0; i < results.size(); i++){
+ cal_data
+ << results[i].freq << ", "
+ << results[i].real_corr << ", "
+ << results[i].imag_corr << ", "
+ << results[i].sup << "\n"
+ ;
+ }
+
+ std::cout << "wrote cal data to " << cal_data_path << std::endl;
+}
/***********************************************************************
* Main
**********************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[]){
std::string args;
- double rate, tx_wave_freq, tx_wave_ampl, rx_offset;
+ double rate, tx_wave_freq, tx_wave_ampl, rx_offset, freq_step;
size_t nsamps;
po::options_description desc("Allowed options");
@@ -189,6 +225,7 @@ 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")
+ ("freq_step", po::value<double>(&freq_step)->default_value(20e6), "Step size for LO sweep in Hz")
("nsamps", po::value<size_t>(&nsamps)->default_value(10000), "Samples per data capture")
;
@@ -229,13 +266,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
std::vector<std::complex<float> > buff(nsamps);
const uhd::meta_range_t freq_range = usrp->get_tx_freq_range();
- const double freq_step = 100e6;
-
std::vector<result_t> results;
for (double tx_lo = freq_range.start()+freq_step; tx_lo < freq_range.stop()-freq_step; tx_lo += freq_step){
- //const double tx_lo = 2.155e9;{
- //tune the LOs
+
tune_rx_and_tx(usrp, tx_lo, rx_offset);
double phase_corr_start = -.3;
@@ -247,7 +281,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
double ampl_corr_step;
std::complex<double> best_correction;
- double best_supression = 0;
+ double best_suppression = 0;
double best_phase_corr = 0;
double best_ampl_corr = 0;
@@ -273,27 +307,27 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
const double tone_dbrms = compute_tone_dbrms(buff, bb_tone_freq/actual_rx_rate);
const double imag_dbrms = compute_tone_dbrms(buff, bb_imag_freq/actual_rx_rate);
- const double supression = tone_dbrms - imag_dbrms;
+ const double suppression = tone_dbrms - imag_dbrms;
//std::cout << "bb_tone_freq " << bb_tone_freq << std::endl;
//std::cout << "bb_imag_freq " << bb_imag_freq << std::endl;
//std::cout << "tone_dbrms " << tone_dbrms << std::endl;
//std::cout << "imag_dbrms " << imag_dbrms << std::endl;
- //std::cout << "supression " << (tone_dbrms - imag_dbrms) << std::endl;
+ //std::cout << "suppression " << (tone_dbrms - imag_dbrms) << std::endl;
- if (supression > best_supression){
+ if (suppression > best_suppression){
best_correction = correction;
- best_supression = supression;
+ best_suppression = suppression;
best_phase_corr = phase_corr;
best_ampl_corr = ampl_corr;
- //std::cout << " supression! " << supression << std::endl;
+ //std::cout << " suppression! " << suppression << std::endl;
}
}}
//std::cout << "best_phase_corr " << best_phase_corr << std::endl;
//std::cout << "best_ampl_corr " << best_ampl_corr << std::endl;
- //std::cout << "best_supression " << best_supression << std::endl;
+ //std::cout << "best_suppression " << best_suppression << std::endl;
phase_corr_start = best_phase_corr - phase_corr_step;
phase_corr_stop = best_phase_corr + phase_corr_step;
@@ -301,12 +335,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
ampl_corr_stop = best_ampl_corr + ampl_corr_step;
}
- if (best_supression > 30){ //most likely valid, keep result
+ if (best_suppression > 30){ //most likely valid, keep result
result_t result;
result.freq = tx_lo;
- result.ampl = best_ampl_corr;
- result.phase = best_phase_corr;
- result.sup = best_supression;
+ result.real_corr = best_correction.real();
+ result.imag_corr = best_correction.imag();
+ result.sup = best_suppression;
results.push_back(result);
}
std::cout << "." << std::flush;
@@ -318,15 +352,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
threads.interrupt_all();
threads.join_all();
-
- for (size_t i = 0; i < results.size(); i++){
- std::cout
- << results[i].freq << ", "
- << results[i].ampl << ", "
- << results[i].phase << ", "
- << results[i].sup << ", "
- << std::endl;
- }
+ store_results(usrp, results);
return 0;
}