aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-04-15 15:03:11 -0700
committerAaron Rossetto <aaron.rossetto@ni.com>2020-04-17 10:27:49 -0500
commit18e41b32ffa9046287d7cb1d438ad1343a50fd71 (patch)
tree12c85472dfdd61ab7a83a8583470de85ce5efd7b /host
parent261ee6d677b83ca15a3d38ddbb0c02ad5d4602fe (diff)
downloaduhd-18e41b32ffa9046287d7cb1d438ad1343a50fd71.tar.gz
uhd-18e41b32ffa9046287d7cb1d438ad1343a50fd71.tar.bz2
uhd-18e41b32ffa9046287d7cb1d438ad1343a50fd71.zip
math: Add dB_to_lin() and lin_to_dB()
These are simply shorthands, but make the code a little more readable with respect to intent. It allows to replace const double power_db = 10 * std::log10(power_lin); with const double power_db = lin_to_dB(power_lin); which expresses the intent a little more clearly and concisely.
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/utils/math.hpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp
index aca0b7c92..d442d6a94 100644
--- a/host/include/uhd/utils/math.hpp
+++ b/host/include/uhd/utils/math.hpp
@@ -234,6 +234,17 @@ UHD_INLINE bool frequencies_are_equal(double lhs, double rhs)
== fp_compare::fp_compare_delta<double>(rhs, FREQ_COMPARISON_DELTA_HZ));
}
+inline double dB_to_lin(const double dB_val)
+{
+ return std::pow(10, (dB_val) / 10.0);
+}
+
+inline double lin_to_dB(const double val)
+{
+ return 10 * std::log10(val);
+}
+
+
//! Portable version of lcm() across Boost versions
template <typename IntegerType>
inline IntegerType lcm(IntegerType x, IntegerType y)