rfconversions
Common conversion equations for RF Engineering.
This guide walks through the library progressively — power, frequency, noise, and compression point conversions — with examples you can copy into your own code.
When To Use This Crate
Use rfconversions for scalar RF math and unit normalization: dBm, dBW, watts,
dB/linear ratios, frequency/wavelength, noise figure/factor/temperature, kTB
noise power, G/T, N0, and P1dB conversions.
If your task is an ordered RF hardware chain, use gainlineup. If it starts
from .sNp S-parameter data, use touchstone. If it is an end-to-end radio
link question involving EIRP, path loss, C/No, Eb/No, BER, margin, orbit,
Doppler, PFD, or modulation, use linkbudget.
Keep dB values in dB for additions/subtractions only. Convert to linear values before multiplying ratios, averaging, or applying formulas that require linear quantities.
1. Power Conversions
Convert between watts and dBm, or between dB and linear scale.
use power;
// Watts ↔ dBm
let dbm = watts_to_dbm; // 30.0 dBm
let watts = dbm_to_watts; // 1.0 W
// Milliwatts ↔ dBm
let mw = dbm_to_milliwatts; // 1.0 mW
let dbm = milliwatts_to_dbm; // 0.0 dBm
// Watts ↔ dBW
let dbw = watts_to_dbw; // 0.0 dBW
let watts = dbw_to_watts; // 1.0 W
// Milliwatts ↔ dBW
let dbw = milliwatts_to_dbw; // 0.0 dBW
let mw = dbw_to_milliwatts; // 1000.0 mW
// dBm ↔ dBW
let dbw = dbm_to_dbw; // 0.0 dBW
let dbm = dbw_to_dbm; // 30.0 dBm
// dB ↔ Linear
let linear = db_to_linear; // 1000.0
let db = linear_to_db; // 30.0 dB
2. Frequency Conversions
Scale between Hz, kHz, MHz, GHz, and THz, or convert frequency to wavelength.
use frequency;
// Unit scaling
let ghz = mhz_to_ghz; // 2.4 GHz
let hz = ghz_to_hz; // 1_000_000_000.0 Hz
let mhz = khz_to_mhz; // 1.5 MHz
let thz = ghz_to_thz; // 1.0 THz
// Frequency → Wavelength (meters, in vacuum)
let wavelength = frequency_to_wavelength; // 0.299792458 m
3. Noise
Convert between noise figure (dB), noise factor (linear), and noise temperature (K). Compute noise power from bandwidth.
use noise;
// Noise factor (linear) ↔ Noise figure (dB)
let nf_db = noise_figure_from_noise_factor; // ~3.01 dB
let nf_linear = noise_factor_from_noise_figure; // 2.0
// Noise temperature ↔ Noise factor
let temp = noise_temperature_from_noise_factor; // 290.0 K
let factor = noise_factor_from_noise_temperature; // 2.0
// Noise temperature ↔ Noise figure
let temp2 = noise_temperature_from_noise_figure; // ~864.51 K
let nf_db2 = noise_figure_from_noise_temperature; // ~3.01 dB
// Noise power (W) from temperature and bandwidth
let noise_power = noise_power_from_bandwidth; // kTB in watts
4. P1dB Compression Point
Convert between input and output 1 dB compression points.
The relationship is: OP1dB = IP1dB + (Gain - 1) (all in dB).
use p1db;
let output_p1db = input_to_output_db; // 34.0 dBm
let input_p1db = output_to_input_db; // 5.0 dBm
5. Friis Cascade (Noise)
Cascade noise figure, noise factor, or noise temperature through a chain of stages using the Friis formula.
use noise;
// LNA (NF=0.5dB, G=20dB) → Cable (NF=1dB, G=-1dB) → Mixer (NF=8dB, G=-7dB)
let stages = vec!;
let nf_total = cascade_noise_figure;
assert!; // LNA dominates
// Same chain in linear domain: stages are (noise_factor, gain_linear)
let linear_stages = vec!;
let f_total = cascade_noise_factor;
assert!;
// Noise temperature cascade: stages are (Te_kelvin, gain_linear)
let temp_stages = vec!;
let t_total = cascade_noise_temperature;
assert!;
6. System-Level Helpers
G/T (figure of merit) and noise power spectral density N₀.
use noise;
// G/T: 40 dBi antenna, 200 K system noise → 17.0 dB/K
let got = g_over_t;
assert!;
// N₀: thermal noise floor at 290 K → -174 dBm/Hz
let n0 = noise_density_dbm_per_hz;
assert!;
7. Constants
Physical constants used internally, available for your own calculations.
use constants;
let c = SPEED_OF_LIGHT; // 299_792_458.0 m/s
let k = BOLTZMANN; // 1.380649e-23 J/K
let t0 = T0; // 290.0 K (standard reference)
API Summary
| Module | Function | Description |
|---|---|---|
power |
watts_to_dbm(f64) → f64 |
Watts to dBm |
power |
dbm_to_watts(f64) → f64 |
dBm to Watts |
power |
dbm_to_milliwatts(f64) → f64 |
dBm to milliwatts |
power |
milliwatts_to_dbm(f64) → f64 |
Milliwatts to dBm |
power |
watts_to_dbw(f64) → f64 |
Watts to dBW |
power |
dbw_to_watts(f64) → f64 |
dBW to Watts |
power |
milliwatts_to_dbw(f64) → f64 |
Milliwatts to dBW |
power |
dbw_to_milliwatts(f64) → f64 |
dBW to milliwatts |
power |
dbm_to_dbw(f64) → f64 |
dBm to dBW |
power |
dbw_to_dbm(f64) → f64 |
dBW to dBm |
power |
db_to_linear(f64) → f64 |
dB to linear ratio |
power |
linear_to_db(f64) → f64 |
Linear ratio to dB |
frequency |
frequency_to_wavelength(f64) → f64 |
Frequency (Hz) to wavelength (m) |
frequency |
wavelength_to_frequency(f64) → f64 |
Wavelength (m) to frequency (Hz) |
frequency |
hz_to_khz, hz_to_mhz, hz_to_ghz, hz_to_thz |
Hz scaling up |
frequency |
khz_to_hz, khz_to_mhz, khz_to_ghz, khz_to_thz |
kHz scaling |
frequency |
mhz_to_hz, mhz_to_khz, mhz_to_ghz, mhz_to_thz |
MHz scaling |
frequency |
ghz_to_hz, ghz_to_khz, ghz_to_mhz, ghz_to_thz |
GHz scaling |
frequency |
thz_to_hz, thz_to_khz, thz_to_mhz, thz_to_ghz |
THz scaling |
noise |
noise_figure_from_noise_factor(f64) → f64 |
Factor → Figure (dB) |
noise |
noise_factor_from_noise_figure(f64) → f64 |
Figure → Factor |
noise |
noise_temperature_from_noise_factor(f64) → f64 |
Factor → Temperature (K) |
noise |
noise_temperature_from_noise_figure(f64) → f64 |
Figure → Temperature (K) |
noise |
noise_factor_from_noise_temperature(f64) → f64 |
Temperature → Factor |
noise |
noise_figure_from_noise_temperature(f64) → f64 |
Temperature → Figure (dB) |
noise |
noise_power_from_bandwidth(f64, f64) → f64 |
kTB noise power (W) |
noise |
cascade_noise_factor(&[(f64, f64)]) → f64 |
Friis cascade (linear) |
noise |
cascade_noise_figure(&[(f64, f64)]) → f64 |
Friis cascade (dB) |
noise |
cascade_noise_temperature(&[(f64, f64)]) → f64 |
Friis cascade (Kelvin) |
noise |
g_over_t(f64, f64) → f64 |
G/T figure of merit (dB/K) |
noise |
noise_density_dbm_per_hz(f64) → f64 |
N₀ noise density (dBm/Hz) |
p1db |
input_to_output_db(f64, f64) → f64 |
IP1dB + Gain → OP1dB |
p1db |
output_to_input_db(f64, f64) → f64 |
OP1dB − Gain → IP1dB |
p1db |
cascade_output_p1db(f64, f64, f64) → f64 |
Cascade OP1dB (dB) |
p1db |
cascade_output_p1db_linear(f64, f64, f64) → f64 |
Cascade OP1dB (linear) |
constants |
SPEED_OF_LIGHT |
299 792 458 m/s |
constants |
BOLTZMANN |
1.380649e-23 J/K |
constants |
T0 |
290 K reference temperature |
License
MIT