aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp1/io_impl.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2021-08-31 11:49:51 +0200
committerAaron Rossetto <aaron.rossetto@ni.com>2021-10-19 12:21:33 -0700
commit5ee6b828debbd60e03aff805bfd80e2030715a6f (patch)
treeef3a02b0c2dd055988c376f4bbf1c8e71ea6a330 /host/lib/usrp/usrp1/io_impl.cpp
parent91c10b66c23178e27bbff0e9173570c63e342736 (diff)
downloaduhd-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/io_impl.cpp')
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index 5d7b4a77b..713dc4c77 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -14,10 +14,10 @@
#include "../../transport/super_send_packet_handler.hpp"
#include <uhd/transport/bounded_buffer.hpp>
#include <uhd/utils/log.hpp>
+#include <uhd/utils/math.hpp>
#include <uhd/utils/safe_call.hpp>
#include <uhd/utils/tasks.hpp>
#include <boost/format.hpp>
-#include <boost/math/special_functions/sign.hpp>
#include <boost/thread/thread.hpp>
#include <atomic>
#include <chrono>
@@ -582,10 +582,13 @@ void usrp1_impl::update_rates(void)
double usrp1_impl::update_rx_dsp_freq(const size_t dspno, const double freq_)
{
- // correct for outside of rate (wrap around)
- double freq = std::fmod(freq_, _master_clock_rate);
- if (std::abs(freq) > _master_clock_rate / 2.0)
- freq -= boost::math::sign(freq) * _master_clock_rate;
+ // Note: The calculation of freq and freq_word could be done by
+ // get_freq_and_freq_word(), which has implemented this algorithm for all
+ // other USRPs.
+ // We'll not refactor this because it's ancient code, but note that
+ // get_freq_and_freq_word() fixes a numerical overflow issue that is not
+ // fixed here.
+ const double freq = uhd::math::wrap_frequency(freq_, _master_clock_rate);
// calculate the freq register word (signed)
UHD_ASSERT_THROW(std::abs(freq) <= _master_clock_rate / 2.0);