Expand description
Unit newtypes for the quantities that are routinely confused.
A decibel value is a Db, never a bare f64; an E_{b}/N_{0} is an EbN0 and
an E_{s}/N_{0} an EsN0, so that passing one where the other is expected is a
compile error. Conversions are explicit methods, never From impls that hide a
formula.
The decibel conversions of plain numbers (db2lin, lin2db, db2amp,
amp2db, dbm2w, w2dbm, db2np, np2db) are defined here, once: the
methods of the newtypes call them, and comnum_math re-exports them (comnum_math::db2lin
is this function), so that a value in dB converts to the same bits whichever way it
is written.
§Model
With k coded bits per symbol and a code rate R,
$$ \left.\frac{E_{s}}{N_{0}}\right|{\mathrm{dB}} = \left.\frac{E{b}}{N_{0}}\right|{\mathrm{dB}} + 10 \log{10}(k R) $$
§Examples
use comnum_core::units::{Db, EbN0};
let es = EbN0(Db(4.0)).to_es_n0(2.0, 1.0); // QPSK, uncoded
assert!((es.0.0 - 7.0103).abs() < 1e-4);
assert!((Db(3.0).to_linear() - 1.9953).abs() < 1e-4);
assert!((Db::from_linear(10.0).0 - 10.0).abs() < 1e-12);
// the newtype and the function are one conversion
assert_eq!(Db(3.0).to_linear(), comnum_core::units::db2lin(3.0));
// 2.6 information bits per symbol (a shaped or coded constellation)
let es = EbN0(Db(4.0)).to_es_n0(2.6, 1.0);
assert!((es.0.0 - (4.0 + comnum_core::units::lin2db(2.6))).abs() < 1e-12);Structs§
- Db
- A power ratio in decibels.
- EbN0
- Energy per information bit over the noise spectral density,
E_{b}/N_{0}. - EsN0
- Energy per symbol over the noise spectral density,
E_{s}/N_{0}. - Hertz
- A frequency or a rate (sample rate, symbol rate), in hertz.
- Seconds
- A duration, in seconds.
Functions§
- amp2db
- Linear amplitude ratio to dB:
20 log10(x). - db2amp
- Amplitude ratio in dB to linear:
10^{x/20}. - db2lin
- Power ratio in dB to linear:
10^{x/10}. - db2np
- Attenuation in dB per unit length to nepers (power):
α_dB / (10 log10 e). - dbm2w
- Power in dBm to watts:
10^{P/10} · 1 mW. - lin2db
- Linear power ratio to dB:
10 log10(x). - np2db
- Attenuation in nepers (power) per unit length to dB:
10 log10(e) · α. - w2dbm
- Power in watts to dBm.