Audio, filter, and control-system specifications express signal levels and filter performance in decibels (dB) because the human auditory system and most engineering metrics scale logarithmically with amplitude ratio. Specifying a stop-band attenuation of 60 dB or a pass-band ripple of 0.1 dB is natural and compact; the equivalent linear ratios (1 000 : 1 and 1.01161 : 1) are not. A small set of conversion primitives — ToDecibels, FromDecibels, and two derived helpers for attenuation and ripple — centralises this conversion and eliminates scattered, error-prone inline 20·log10 expressions throughout the rest of the library.
For a positive amplitude ratio
The factor 20 (rather than 10) reflects the voltage/pressure convention: power is proportional to the square of amplitude, so a doubling of amplitude (
This inverse is exact for all finite
A floor of
Stop-band attenuation between a pass-band ratio
Pass-band ripple between the maximum and minimum in-band ratios
Both are simple differences in decibel space, exploiting the logarithm identity
| Operation | Time | Space | Notes |
|---|---|---|---|
ToDecibels |
O(1) | O(1) | One log10 + one max + one mul |
FromDecibels |
O(1) | O(1) | One pow |
AttenuationDb |
O(1) | O(1) | Two ToDecibels + one subtraction |
RippleDb |
O(1) | O(1) | Two ToDecibels + one subtraction |
No state, no buffers. All operations are pure functions.
Converting a ratio of 10 to decibels:
- Input
$r = 10$ ; guard passes ($r > 0$ ). - Compute
$20 \cdot \log_{10}(10) = 20 \cdot 1 = 20$ . - Apply floor:
$\max(20, -160) = 20$ . - Output:
$20,\mathrm{dB}$ .
Round-trip for
-
ToDecibels(0.5)=$20 \cdot \log_{10}(0.5) \approx -6.0206,\mathrm{dB}$ . -
FromDecibels(-6.0206)=$10^{-6.0206/20} \approx 0.5$ .
- Passing
$r = 0$ produces$-\infty$ fromlog10; the floor guard prevents propagation into downstream computations. - Negative ratios indicate a programming error (signed sample values must not be passed directly as ratios without taking absolute value first); they are silently floored rather than raising an exception, consistent with the no-exception policy.
- With
fast-mathenabled, the compiler may fuse or reorder floating-point operations. Thelog10result is still monotone and the floor remains correct because it usesstd::max, which is not reordered away. -
FromDecibelshas no floor; at very large positive dB values the result overflows to+infin float — this is expected behaviour for out-of-range inputs.
- Power decibels use
$10 \log_{10}(\cdot)$ (factor 10 rather than 20). The amplitude convention used here ($\times 20$ ) is correct for voltage, pressure, and filter transfer-function magnitude. - Field-quantity vs. power-quantity disambiguation: IEEE 60268 / IEC 61672 mandate
$20 \log_{10}$ for sound pressure level; the same convention applies to filter magnitude response. - The floor can be parameterised if a stricter or looser sentinel is required; the default of
$-160,\mathrm{dB}$ is conservative for 32-bit float.
- Filter specification: stop-band attenuation and pass-band ripple in dB are the primary acceptance criteria for IIR/FIR designs.
- Frequency response plots:
FrequencyResponse::Calculate()already returns magnitude in dB using$20 \log_{10}$ ; these helpers provide the same conversion for ad-hoc analysis. - Controller gain margin is expressed in dB; converting from a linear ratio with
ToDecibelsavoids duplication. - Audio dynamic processing (compressor thresholds, limiter ceilings) and acoustic measurement both use dB natively.
-
control_analysis::FrequencyResponseinternally applies$20 \log_{10}(|H|)$ on its magnitude output vector; these helpers are the scalar equivalent exposed for library consumers. - Pass-band ripple computed by
RippleDbfeeds directly into filter-design acceptance testing alongside the step/transient-response metrics in the evaluation primitives family.
- Proakis, J. & Manolakis, D., "Digital Signal Processing", 4th ed., Prentice Hall, 2007 — Appendix A (decibel notation).
- Zolzer, U., "DAFX: Digital Audio Effects", 2nd ed., Wiley, 2011 — Chapter 2 (level and gain in dB).
- IEC 61672-1:2013, "Electroacoustics — Sound level meters — Part 1: Specifications."