summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
Diffstat (limited to 'host')
-rw-r--r--host/utils/uhd_cal_rx_iq_balance.cpp4
-rw-r--r--host/utils/uhd_cal_tx_dc_offset.cpp4
-rw-r--r--host/utils/uhd_cal_tx_iq_balance.cpp4
-rw-r--r--host/utils/usrp_cal_utils.hpp36
4 files changed, 20 insertions, 28 deletions
diff --git a/host/utils/uhd_cal_rx_iq_balance.cpp b/host/utils/uhd_cal_rx_iq_balance.cpp
index da9ccbdb3..34a0a63fe 100644
--- a/host/utils/uhd_cal_rx_iq_balance.cpp
+++ b/host/utils/uhd_cal_rx_iq_balance.cpp
@@ -45,7 +45,7 @@ static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_amp
//setup variables and allocate buffer
uhd::tx_metadata_t md;
md.has_time_spec = false;
- std::vector<std::complex<float> > buff(tx_stream->get_max_num_samps()*10);
+ std::vector<samp_type> buff(tx_stream->get_max_num_samps()*10);
//fill buff and send until interrupted
while (not boost::this_thread::interruption_requested()){
@@ -147,7 +147,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_ampl));
//re-usable buffer for samples
- std::vector<std::complex<float> > buff;
+ std::vector<samp_type> buff;
//store the results here
std::vector<result_t> results;
diff --git a/host/utils/uhd_cal_tx_dc_offset.cpp b/host/utils/uhd_cal_tx_dc_offset.cpp
index af5b60d14..1b2510ba4 100644
--- a/host/utils/uhd_cal_tx_dc_offset.cpp
+++ b/host/utils/uhd_cal_tx_dc_offset.cpp
@@ -44,7 +44,7 @@ static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_fre
//setup variables and allocate buffer
uhd::tx_metadata_t md;
md.has_time_spec = false;
- std::vector<std::complex<float> > buff(tx_stream->get_max_num_samps()*10);
+ std::vector<samp_type> buff(tx_stream->get_max_num_samps()*10);
//values for the wave table lookup
size_t index = 0;
@@ -150,7 +150,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl));
//re-usable buffer for samples
- std::vector<std::complex<float> > buff;
+ std::vector<samp_type> buff;
//store the results here
std::vector<result_t> results;
diff --git a/host/utils/uhd_cal_tx_iq_balance.cpp b/host/utils/uhd_cal_tx_iq_balance.cpp
index ff965e040..c2222e777 100644
--- a/host/utils/uhd_cal_tx_iq_balance.cpp
+++ b/host/utils/uhd_cal_tx_iq_balance.cpp
@@ -44,7 +44,7 @@ static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_fre
//setup variables and allocate buffer
uhd::tx_metadata_t md;
md.has_time_spec = false;
- std::vector<std::complex<float> > buff(tx_stream->get_max_num_samps()*10);
+ std::vector<samp_type> buff(tx_stream->get_max_num_samps()*10);
//values for the wave table lookup
size_t index = 0;
@@ -150,7 +150,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl));
//re-usable buffer for samples
- std::vector<std::complex<float> > buff;
+ std::vector<samp_type> buff;
//store the results here
std::vector<result_t> results;
diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp
index 71951c361..6d0c500e3 100644
--- a/host/utils/usrp_cal_utils.hpp
+++ b/host/utils/usrp_cal_utils.hpp
@@ -30,15 +30,15 @@ namespace fs = boost::filesystem;
struct result_t{double freq, real_corr, imag_corr, best, delta;};
+typedef std::complex<float> samp_type;
+
/***********************************************************************
* Constants
**********************************************************************/
static const double tau = 6.28318531;
-static const double alpha = 0.0001; //very tight iir filter
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 = 7.3e6;
static const size_t default_num_samps = 10000;
@@ -94,51 +94,43 @@ public:
wave_table(const double ampl){
_table.resize(wave_table_len);
for (size_t i = 0; i < wave_table_len; i++){
- _table[i] = std::complex<float>(std::polar(ampl, (tau*i)/wave_table_len));
+ _table[i] = samp_type(std::polar(ampl, (tau*i)/wave_table_len));
}
}
- inline std::complex<float> operator()(const size_t index) const{
+ inline samp_type operator()(const size_t index) const{
return _table[index % wave_table_len];
}
private:
- std::vector<std::complex<float> > _table;
+ std::vector<samp_type > _table;
};
/***********************************************************************
* Compute power of a tone
**********************************************************************/
static inline double compute_tone_dbrms(
- const std::vector<std::complex<float> > &samples,
+ const std::vector<samp_type > &samples,
const double freq //freq is fractional
){
//shift the samples so the tone at freq is down at DC
- std::vector<std::complex<float> > shifted(samples.size() - skip_initial_samps);
- for (size_t i = 0; i < shifted.size(); i++){
- shifted[i] = samples[i+skip_initial_samps] * std::complex<float>(std::polar(1.0, -freq*tau*i));
- }
-
- //filter the samples with a narrow low pass
- std::complex<float> iir_output = 0, iir_last = 0;
- double output = 0;
- for (size_t i = 0; i < shifted.size(); i++){
- iir_output = float(alpha) * shifted[i] + float(1-alpha)*iir_last;
- iir_last = iir_output;
- output += std::abs(iir_output);
+ //and average the samples to measure the DC component
+ samp_type average = 0;
+ for (size_t i = 0; i < samples.size(); i++){
+ average += samp_type(std::polar(1.0, -freq*tau*i)) * samples[i];
}
- return 20*std::log10(output/shifted.size());
+ return 20*std::log10(std::abs(average/float(samples.size())));
}
/***********************************************************************
* Write a dat file
**********************************************************************/
static inline void write_samples_to_file(
- const std::vector<std::complex<float> > &samples, const std::string &file
+ const std::vector<samp_type > &samples, const std::string &file
){
std::ofstream outfile(file.c_str(), std::ofstream::binary);
- outfile.write((const char*)&samples.front(), samples.size()*sizeof(std::complex<float>));
+ outfile.write((const char*)&samples.front(), samples.size()*sizeof(samp_type));
outfile.close();
}
@@ -196,7 +188,7 @@ static void store_results(
static void capture_samples(
uhd::usrp::multi_usrp::sptr usrp,
uhd::rx_streamer::sptr rx_stream,
- std::vector<std::complex<float> > &buff,
+ std::vector<samp_type > &buff,
const size_t nsamps_requested
){
buff.resize(nsamps_requested);