diff options
author | Josh Blum <josh@joshknows.com> | 2010-12-03 11:46:47 -0500 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-12-03 11:46:47 -0500 |
commit | c67b06fd6541bbcd59de459e82735974cbdb3d88 (patch) | |
tree | 4122a67bf685b0200aa66e86e8230477ced782b5 /host/lib/usrp/dsp_utils.cpp | |
parent | 9d13960d8fb4303979b7986db8c9e1f2c8565312 (diff) | |
download | uhd-c67b06fd6541bbcd59de459e82735974cbdb3d88.tar.gz uhd-c67b06fd6541bbcd59de459e82735974cbdb3d88.tar.bz2 uhd-c67b06fd6541bbcd59de459e82735974cbdb3d88.zip |
usrp: move dsp tuning wrap-around into the dsp utils (allows the dsp handler to get the full value)
Diffstat (limited to 'host/lib/usrp/dsp_utils.cpp')
-rw-r--r-- | host/lib/usrp/dsp_utils.cpp | 13 |
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 |