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.
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. Constants
Physical constants used internally, available for your own calculations.
use constants;
let c = SPEED_OF_LIGHT; // 299_792_458.0 m/s
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) |
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 calculation |
constants |
SPEED_OF_LIGHT |
299 792 458 m/s |
License
MIT