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
_______________________________________________
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]

Reply via email to