diff options
author | Martin Braun <martin.braun@ettus.com> | 2021-08-31 11:49:51 +0200 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-10-19 12:21:33 -0700 |
commit | 5ee6b828debbd60e03aff805bfd80e2030715a6f (patch) | |
tree | ef3a02b0c2dd055988c376f4bbf1c8e71ea6a330 /host/lib/usrp/usrp1/codec_ctrl.cpp | |
parent | 91c10b66c23178e27bbff0e9173570c63e342736 (diff) | |
download | uhd-5ee6b828debbd60e03aff805bfd80e2030715a6f.tar.gz uhd-5ee6b828debbd60e03aff805bfd80e2030715a6f.tar.bz2 uhd-5ee6b828debbd60e03aff805bfd80e2030715a6f.zip |
uhd: math: Replace wrap-frequency math with a single function
In multiple places in the UHD code, we were doing the same calculation
for a wrapped frequency (wrap it into the first Nyquist zone). This math
was using boost::math, too. Instead of editing every instance, we create
a new function, uhd::math::wrap_frequency(), and replace all of its
separate implementations with this function. The new function also no
longer relies on boost::math::sign.
Diffstat (limited to 'host/lib/usrp/usrp1/codec_ctrl.cpp')
-rw-r--r-- | host/lib/usrp/usrp1/codec_ctrl.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/host/lib/usrp/usrp1/codec_ctrl.cpp b/host/lib/usrp/usrp1/codec_ctrl.cpp index 413caaf67..c5268b3c4 100644 --- a/host/lib/usrp/usrp1/codec_ctrl.cpp +++ b/host/lib/usrp/usrp1/codec_ctrl.cpp @@ -12,13 +12,13 @@ #include <uhd/utils/algorithm.hpp> #include <uhd/utils/byteswap.hpp> #include <uhd/utils/log.hpp> +#include <uhd/utils/math.hpp> #include <uhd/utils/safe_call.hpp> #include <uhdlib/utils/narrow.hpp> -#include <cstdint> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> -#include <boost/math/special_functions/sign.hpp> #include <cmath> +#include <cstdint> #include <iomanip> #include <tuple> @@ -380,15 +380,10 @@ double usrp1_codec_ctrl_impl::fine_tune(double codec_rate, double target_freq) void usrp1_codec_ctrl_impl::set_duc_freq(double freq, double rate) { - double codec_rate = rate * 2; - - // correct for outside of rate (wrap around) - freq = std::fmod(freq, rate); - if (std::abs(freq) > rate / 2.0) - freq -= boost::math::sign(freq) * rate; - - double coarse_freq = coarse_tune(codec_rate, freq); - double fine_freq = fine_tune(codec_rate / 4, freq - coarse_freq); + const double codec_rate = rate * 2; + freq = uhd::math::wrap_frequency(freq, rate); + const double coarse_freq = coarse_tune(codec_rate, freq); + const double fine_freq = fine_tune(codec_rate / 4, freq - coarse_freq); UHD_LOGGER_DEBUG("USRP1") << "ad9862 tuning result:" << " requested: " << freq |