Last active
September 9, 2022 11:10
-
-
Save korjaa/2eb357a6a0bafd64a03711f4bfe6e004 to your computer and use it in GitHub Desktop.
Average dBm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def average_dbm(dbms): | |
# https://en.wikipedia.org/wiki/Decibel | |
# https://en.wikipedia.org/wiki/LogSumExp | |
# Less numerically stable version: | |
# 10*numpy.log10(numpy.mean(numpy.power(10, (dbms-30)/10))) | |
bel_np = 0.5 * numpy.log(10) # Bel & Neper by definition | |
dbel_np = bel_np / 10 | |
np_to_db = 1 / dbel_np | |
# B = 1/2 * ln(10) | |
# Lp = 1/2 * ln(P/P0) * Np | |
sum_dbm = 1/2 * np_to_db * scipy.special.logsumexp(dbms / (1/2 * np_to_db)) | |
avg_dbm = sum_dbm - 10 * numpy.log10(len(dbms)) # linear division is log subtraction | |
return avg_db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment