From efaf13d2d1b14bd5ab54a67c334c4c7881cb20b6 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 4 Aug 2015 12:03:10 -0700 Subject: [PATCH] Extract complex16_mag_squared_to_dbv_norm to utility. --- firmware/baseband/main.cpp | 7 ------- firmware/common/utility.cpp | 8 ++++++++ firmware/common/utility.hpp | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index 3b1f9a280..1b98df09b 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -70,13 +70,6 @@ constexpr auto baseband_thread_priority = NORMALPRIO + 20; constexpr auto rssi_thread_priority = NORMALPRIO + 10; -static float complex16_mag_squared_to_dbv_norm(const float c16_mag_squared) { - constexpr float mag2_max = -32768.0f * -32768.0f + -32768.0f * -32768.0f; - constexpr float mag2_log10_max = std::log10(mag2_max); - constexpr float mag2_to_db_factor = 20.0f / 2.0f; - return (std::log10(c16_mag_squared) - mag2_log10_max) * mag2_to_db_factor; -} - class BasebandStatsCollector { public: template diff --git a/firmware/common/utility.cpp b/firmware/common/utility.cpp index 63213e924..857bbb73a 100644 --- a/firmware/common/utility.cpp +++ b/firmware/common/utility.cpp @@ -24,6 +24,7 @@ #include "utility.hpp" #include +#include #if 0 uint32_t gcd(const uint32_t u, const uint32_t v) { @@ -61,6 +62,13 @@ uint32_t gcd(const uint32_t u, const uint32_t v) { } #endif +float complex16_mag_squared_to_dbv_norm(const float c16_mag_squared) { + constexpr float mag2_max = -32768.0f * -32768.0f + -32768.0f * -32768.0f; + constexpr float mag2_log10_max = std::log10(mag2_max); + constexpr float mag2_to_db_factor = 20.0f / 2.0f; + return (std::log10(c16_mag_squared) - mag2_log10_max) * mag2_to_db_factor; +} + /* GCD implementation derived from recursive implementation at * http://en.wikipedia.org/wiki/Binary_GCD_algorithm */ diff --git a/firmware/common/utility.hpp b/firmware/common/utility.hpp index e001193e0..b8bb5f57b 100644 --- a/firmware/common/utility.hpp +++ b/firmware/common/utility.hpp @@ -65,6 +65,8 @@ static inline void clear_m4_flag_saturation() { #endif +float complex16_mag_squared_to_dbv_norm(const float c16_mag_squared); + /* Override new/delete to use Chibi/OS heap functions */ /* NOTE: Do not inline these, it doesn't work. ;-) */ void* operator new(size_t size);