mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-06-25 07:10:43 -04:00
Extract complex16_mag_squared_to_dbv_norm to utility.
This commit is contained in:
parent
d855336985
commit
efaf13d2d1
3 changed files with 10 additions and 7 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "utility.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
|
||||
#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
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue