How far will the link reach?
Use a link budget to find the longest distance that keeps a fade margin. An easy embedded C problem (Choosing a wireless technology), run and graded in the…
easy · Choosing a wireless technology · wireless · link-budget · rf
A radio link works while the received power stays above the receiver's sensitivity, with a fade margin to spare for walls, rain and movement. In free space, every doubling of distance costs 6 dB.
Write max_range_m(tx_dbm, antenna_gain_db, loss_at_1m_db, sensitivity_dbm, fade_margin_db): the received power at 1 m is tx_dbm + antenna_gain_db − loss_at_1m_db. Starting at 1 m, keep doubling the distance (each doubling 6 dB weaker) while the link still has at least the fade margin; return the longest distance in metres that does. Return 0 if even 1 m does not work.
Starter code
uint32_t max_range_m(int tx_dbm, int antenna_gain_db, int loss_at_1m_db, int sensitivity_dbm, int fade_margin_db) {
int budget = tx_dbm + antenna_gain_db - loss_at_1m_db - sensitivity_dbm;
(void)fade_margin_db;
return (uint32_t)(budget / 6); // metres?
}Example tests
BLE
show(0, 0, 40, -95, 20);Expected output:
0 dBm, 0 dBi, 40 dB at 1 m, sensitivity -95 dBm, margin 20 dB: 32 mLoRa
show(14, 2, 32, -137, 30);Expected output:
14 dBm, 2 dBi, 32 dB at 1 m, sensitivity -137 dBm, margin 30 dB: 32768 mLearn it first
- Choosing a wireless technology · Range, data rate, power and cost: a decision guide.