summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/lib/usrp/dsp_utils.cpp13
-rw-r--r--host/lib/usrp/tune_helper.cpp7
-rw-r--r--host/test/tune_helper_test.cpp2
3 files changed, 12 insertions, 10 deletions
diff --git a/host/lib/usrp/dsp_utils.cpp b/host/lib/usrp/dsp_utils.cpp
index 2553e4a25..576c4639f 100644
--- a/host/lib/usrp/dsp_utils.cpp
+++ b/host/lib/usrp/dsp_utils.cpp
@@ -21,6 +21,8 @@
#include <boost/assign/list_of.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/math/special_functions/round.hpp>
+#include <boost/math/special_functions/sign.hpp>
+#include <algorithm>
#include <cmath>
using namespace uhd;
@@ -65,13 +67,16 @@ boost::uint32_t dsp_type1::calc_tx_mux_word(subdev_conn_t subdev_conn){
}
boost::uint32_t dsp_type1::calc_cordic_word_and_update(
- double &freq,
- double codec_rate
+ double &freq, double codec_rate
){
- UHD_ASSERT_THROW(std::abs(freq) <= codec_rate/2.0);
- static const double scale_factor = std::pow(2.0, 32);
+ //correct for outside of rate (wrap around)
+ freq = std::fmod(freq, codec_rate);
+ if (std::abs(freq) > codec_rate/2.0)
+ freq -= boost::math::sign(freq)*codec_rate;
//calculate the freq register word (signed)
+ UHD_ASSERT_THROW(std::abs(freq) <= codec_rate/2.0);
+ static const double scale_factor = std::pow(2.0, 32);
boost::int32_t freq_word = boost::int32_t(boost::math::round((freq / codec_rate) * scale_factor));
//update the actual frequency
diff --git a/host/lib/usrp/tune_helper.cpp b/host/lib/usrp/tune_helper.cpp
index fa40a8a26..eccee7f4b 100644
--- a/host/lib/usrp/tune_helper.cpp
+++ b/host/lib/usrp/tune_helper.cpp
@@ -20,7 +20,6 @@
#include <uhd/usrp/dsp_props.hpp>
#include <uhd/usrp/dboard_iface.hpp> //unit_t
#include <uhd/utils/algorithm.hpp>
-#include <boost/math/special_functions/sign.hpp>
#include <cmath>
using namespace uhd;
@@ -37,7 +36,6 @@ static tune_result_t tune_xx_subdev_and_dsp(
wax::obj subdev_freq_proxy = subdev[SUBDEV_PROP_FREQ];
std::string freq_name = dsp[DSP_PROP_FREQ_SHIFT_NAMES].as<prop_names_t>().at(chan);
wax::obj dsp_freq_proxy = dsp[named_prop_t(DSP_PROP_FREQ_SHIFT, freq_name)];
- double dsp_sample_rate = dsp[DSP_PROP_CODEC_RATE].as<double>();
//------------------------------------------------------------------
//-- calculate the LO offset, only used with automatic policy
@@ -73,10 +71,7 @@ static tune_result_t tune_xx_subdev_and_dsp(
//------------------------------------------------------------------
//-- calculate the dsp freq, only used with automatic policy
//------------------------------------------------------------------
- double delta_freq = std::fmod(tune_request.target_freq - actual_inter_freq, dsp_sample_rate);
- bool outside_of_nyquist = std::abs(delta_freq) > dsp_sample_rate/2.0;
- double target_dsp_freq = (outside_of_nyquist)?
- boost::math::sign(delta_freq)*dsp_sample_rate - delta_freq : -delta_freq;
+ double target_dsp_freq = actual_inter_freq - tune_request.target_freq;
//invert the sign on the dsp freq given the following conditions
if (unit == dboard_iface::UNIT_TX) target_dsp_freq *= -1.0;
diff --git a/host/test/tune_helper_test.cpp b/host/test/tune_helper_test.cpp
index e0500ae3f..735e7e948 100644
--- a/host/test/tune_helper_test.cpp
+++ b/host/test/tune_helper_test.cpp
@@ -19,6 +19,7 @@
#include <uhd/usrp/tune_helper.hpp>
#include <uhd/usrp/subdev_props.hpp>
#include <uhd/usrp/dsp_props.hpp>
+#include <uhd/usrp/dsp_utils.hpp>
#include <iostream>
using namespace uhd;
@@ -165,6 +166,7 @@ private:
switch(key.as<dsp_prop_t>()){
case DSP_PROP_FREQ_SHIFT:
_freq_shift = val.as<double>();
+ dsp_type1::calc_cordic_word_and_update(_freq_shift, _codec_rate);
return;
case DSP_PROP_HOST_RATE: