From 9a1e306791360a19ebea01e8b59c585b24fb585c Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 8 Jan 2023 14:17:15 -0500 Subject: [PATCH] cwDsp.h: Initial implementation of ampl_to_db() and db_to_ampl() --- cwDsp.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cwDsp.h b/cwDsp.h index da6feb8..f44de65 100644 --- a/cwDsp.h +++ b/cwDsp.h @@ -16,6 +16,15 @@ namespace cw typedef std::complex complex_d_t; typedef std::complex complex_f_t; + template< typename T > + T ampl_to_db( T ampl, T ref=1.0, T minDb=-200.0 ) + { return ampl<1e-10 ? minDb : 20.0 * log10(ampl/ref); } + + template< typename T > + T db_to_ampl( T db ) + { return pow(10.0,db/20.0); } + + //--------------------------------------------------------------------------------------------------------------------------------- // Window functions //