Feature proposal: linear-domain averaging for logarithmic values (e.g. dB/dBm)

Martijn Hiemstra via NumPy-Discussion <[email protected]> Mon, 27 Jul 2026 20:14:40 +0200
Newsgroups gmane.comp.python.numeric.general
Message-ID <CAHm=M4d_MZXcPPCWx9Vv48=q-LQb9r6LPGaqYnOTynrJvEhkqg@mail.gmail.com>
--===============6361754974492922338==
Content-Type: multipart/alternative; boundary="000000000000df572a06579bb28c"

--000000000000df572a06579bb28c
Content-Type: text/plain; charset="UTF-8"

Hello NumPy developers,

I would like to propose adding a helper function for averaging values that
are represented in logarithmic units.

A common situation in signal processing and related fields is that values
are stored as logarithms (for example dB or dBm), but the physically
meaningful average is the arithmetic mean in the linear domain. The result
then needs to be converted back to logarithmic units.

For dB-like quantities this operation is:

log_mean = 10 * log10(mean(10 ** (x / 10)))

where x contains logarithmic values. For x = [-30, -20] the function would
yield -21.19 (and not -25).

Currently this requires users to manually write the conversion, which is
easy to get wrong because taking the arithmetic mean directly in dB space
is not equivalent. Another motivation for providing this as a dedicated
NumPy feature is performance. While the operation can currently be
expressed using existing NumPy primitives, the expression requires multiple
passes and intermediate arrays

A possible API could be something like:

np.logmean(x, base=10, factor=10, axis=-1)

The function would be analogous to other reduction operations such as mean,
but would perform the averaging in the corresponding linear domain.

I understand NumPy generally avoids domain-specific functions, so I am
interested in feedback on whether this belongs in NumPy or whether it would
be better suited for another package. I mainly wanted to raise the question
because this operation appears frequently in RF, acoustics, and
signal-processing workflows and has a clear mathematical definition.

Thanks for your thoughts.

Best regards,
Martijn Hiemstra

--000000000000df572a06579bb28c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><font size=3D"2"><br>Hello NumPy developers,<br><br>I woul=
d like to propose adding a helper function for averaging values that are re=
presented in logarithmic units.<br><br>A common situation in signal process=
ing and related fields is that values are stored as logarithms (for example=
 dB or dBm), but the physically meaningful average is the arithmetic mean i=
n the linear domain. The result then needs to be converted back to logarith=
mic units.<br><br>For dB-like quantities this operation is:<br><br>log_mean=
 =3D 10 * log10(mean(10 ** (x / 10)))<br><br>where x contains logarithmic v=
alues. For x =3D [-30, -20] the function would yield -21.19 (and not -25).<=
br><br>Currently this requires users to manually write the conversion, whic=
h is easy to get wrong because taking the arithmetic mean directly in dB sp=
ace is not equivalent.</font>
Another motivation for providing this as a dedicated NumPy feature is perfo=
rmance. While the operation can currently be expressed using existing NumPy=
 primitives, the expression requires multiple passes and intermediate array=
s

<br><font size=3D"2"><br>A possible API could be something like:<br><br></f=
ont><div><font size=3D"2">np.logmean(x, base=3D10, factor=3D10, axis=3D-1)<=
/font></div><font size=3D"2"><br>The function would be analogous to other r=
eduction operations such as mean, but would perform the averaging in the co=
rresponding linear domain.<br><br>I understand NumPy generally avoids domai=
n-specific functions, so I am interested in feedback on whether this belong=
s in NumPy or whether it would be better suited for another package. I main=
ly wanted to raise the question because this operation appears frequently i=
n RF, acoustics, and signal-processing workflows and has a clear mathematic=
al definition.<br><br>Thanks for your thoughts.<br><br>Best regards,<br>Mar=
tijn Hiemstra</font></div>

--000000000000df572a06579bb28c--

--===============6361754974492922338==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: [email protected]

--===============6361754974492922338==--