aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/dsp_utils.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-12-14 14:54:26 -0800
committerJosh Blum <josh@joshknows.com>2010-12-14 14:54:26 -0800
commit1c06810258ae657ce373da2333f8fa98afb1981d (patch)
tree7473b292e8ea19b0a7294d3832503357502b5f25 /host/lib/usrp/dsp_utils.cpp
parent3ed60b62eaf2d907ec7797f61ca60420bfd2ee5b (diff)
parentf3bf32df9f747aa47f8463516e817c305e731231 (diff)
downloaduhd-1c06810258ae657ce373da2333f8fa98afb1981d.tar.gz
uhd-1c06810258ae657ce373da2333f8fa98afb1981d.tar.bz2
uhd-1c06810258ae657ce373da2333f8fa98afb1981d.zip
Merge branch 'dsp_tune'
Diffstat (limited to 'host/lib/usrp/dsp_utils.cpp')
-rw-r--r--host/lib/usrp/dsp_utils.cpp13
1 files changed, 9 insertions, 4 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