Ultra-wideband (UWB)
Pulse radio, time-of-flight ranging, TWR and TDoA.
A radio for measuring distance
Ultra-wideband (UWB) transmits extremely short pulses, around 2 nanoseconds, spread across a very wide band (at least 500 MHz, in channels between roughly 6.5 and 8 GHz). Its main use is not data but precise ranging and positioning: measuring the distance between two devices to within about 10 cm, and their direction with antenna arrays.
The standard is IEEE 802.15.4z (an amendment to the 802.15.4 family Zigbee and Thread use), which added the secure ranging features modern products rely on. Common chips: Qorvo (DW3000 series), NXP Trimension, Apple U1/U2.
Why short pulses measure distance well
Distance comes from time of flight: radio travels about 30 cm per nanosecond. Narrowband radios (BLE, Wi-Fi) estimate distance from signal strength (RSSI), which varies by metres with walls, bodies and orientation. UWB measures when a pulse arrived. A pulse 2 ns wide has a sharp leading edge, so the receiver can timestamp the first path precisely, even with reflections arriving later (multipath), which narrowband signals smear together.
#include <stdio.h>
int main(void) {
double c = 299792458.0; /* m/s */
double tick_ps = 15.65; /* typical UWB chip timestamp resolution, picoseconds */
printf("light travels %.1f cm per ns\n", c * 1e-9 * 100);
printf("one timestamp tick of %.2f ps = %.1f mm of range\n", tick_ps, c * tick_ps * 1e-12 * 1000);
printf("a 1 ns timing error = %.0f cm of range error\n", c * 1e-9 * 100);
return 0;
}
Two-way ranging (TWR)
Two devices need no shared clock if they exchange messages and each measures time intervals on its own clock.
Single-sided TWR: device A sends a poll at t1; B receives it, waits a known reply delay Treply, and responds; A receives at t4. Then:
time of flight = ((t4 - t1) - Treply) / 2
Clock drift between A and B over Treply introduces error (a 10 ppm offset over 300 µs is 3 ns, about 1 m), so:
Double-sided TWR: a third message lets both sides measure a round trip and a reply time; combining them cancels most clock-offset error:
ToF = (Tround1 × Tround2 − Treply1 × Treply2) / (Tround1 + Tround2 + Treply1 + Treply2)
#include <stdio.h>
int main(void) {
/* Double-sided TWR with a deliberate 20 ppm clock error on device B. True distance: 12.0 m. */
double c = 299792458.0, tof = 12.0 / c;
double reply1_true = 300e-6, reply2_true = 300e-6;
double drift_b = 1.0 + 20e-6; /* B's clock runs fast */
double tround1 = 2 * tof + reply1_true; /* measured by A */
double treply1 = reply1_true * drift_b; /* measured by B on its own clock */
double tround2 = (2 * tof + reply2_true) * drift_b; /* measured by B */
double treply2 = reply2_true; /* measured by A */
double ss = (tround1 - treply1) / 2; /* single-sided, using B's reported reply time */
double ds = (tround1 * tround2 - treply1 * treply2) / (tround1 + tround2 + treply1 + treply2);
printf("single-sided estimate: %.2f m\n", ss * c);
printf("double-sided estimate: %.2f m\n", ds * c);
return 0;
}
Time difference of arrival (TDoA)
For tracking many tags in a building (a warehouse, a factory, a hospital), tags only transmit short "blinks". Fixed anchors with synchronised clocks timestamp each blink; the differences in arrival time at several anchors place the tag on hyperbolas whose intersection is its position. Tags transmit only, so they use little power and the system scales to thousands of tags. The cost is the anchor infrastructure and clock synchronisation (wired or over UWB).
| TWR | TDoA | |
|---|---|---|
| Messages | Exchange between two devices | Tag blinks only |
| Clock sync | Not needed | Anchors must be synchronised |
| Tag power | Higher (transmit and receive) | Very low (transmit only) |
| Scaling | Limited by message exchanges | Thousands of tags |
| Typical use | Phone-to-device, car keys, item finders | Real-time location systems (RTLS) in buildings |
Angle of arrival (AoA): a device with two or more antennas measures the phase difference of the arriving signal to find the direction, giving position from a single device (how a phone points at an AirTag).
Secure ranging and digital car keys
Distance measurement is a security feature: a car should unlock only when the real key is actually nearby. Older keyless-entry systems were defeated by relay attacks that forwarded signals between a car and a key in the owner's house. Measuring time of flight defeats this because relaying adds delay, but only if the timestamps cannot be faked.
802.15.4z adds the Scrambled Timestamp Sequence (STS): a cryptographically generated pulse sequence derived from a shared key, so an attacker cannot predict it to fake an early arrival. The Car Connectivity Consortium Digital Key 3.0 standard uses BLE to discover and authenticate, then UWB with STS for secure ranging; phones from Apple, Samsung and Google support it.
Other uses
- Item finders (AirTag, Galaxy SmartTag) with precise "point and find".
- Indoor navigation and asset tracking in factories and hospitals.
- Hands-free access control (doors that open as an authorised person approaches).
- Short-range radar: presence detection, vital-sign monitoring, gesture sensing.
Design considerations
- Antenna delay calibration: the time signals spend in the antenna and RF path adds a constant offset to every measurement; calibrate each design (and ideally each unit) against known distances.
- Line of sight: bodies and walls delay or block the direct path; non-line-of-sight conditions add error, so filter and detect them using signal quality metrics.
- Regulation: UWB is allowed at very low power spectral density; available channels differ by region (channel 9 at 7.99 GHz is widely supported).
- Power: receiving costs more than transmitting; schedule ranging sessions and use BLE to wake UWB only when needed.
Interview question: Explain two-way ranging and why double-sided TWR is used.
Answer: In two-way ranging, device A sends a message and records when it left; B replies after a delay it measures; A records the arrival. The round trip minus B's reply delay, halved, is the time of flight, and multiplying by the speed of light gives distance, with no shared clock needed. But the two devices' clocks run at slightly different rates, and over a reply delay of hundreds of microseconds a few ppm of offset causes errors of tens of centimetres. Double-sided TWR adds a third message so both devices measure a round trip and a reply; combining the four intervals cancels most of the clock-offset error.
Interview question: How does UWB defend against relay attacks on keyless car entry?
Answer: Relay attacks forward the radio exchange between car and key over a longer distance. UWB measures time of flight, and any relay adds delay, so the measured distance grows. To stop an attacker faking an earlier arrival, 802.15.4z uses a Scrambled Timestamp Sequence: a cryptographically generated pulse sequence from a key shared during secure BLE authentication, which the attacker cannot predict or advance. The car only unlocks when the securely measured distance is within the threshold.
Build it: find the container to within centimetres
This is step 7, the last of the module project. A warehouse can hold the same container type in hundreds of identical rows, so "somewhere in warehouse 4" is not good enough: the tag carries a UWB radio and measures its distance to anchors fixed on the walls, from which the site's server works out its position. Each distance comes from double-sided two-way ranging between the tag (A) and an anchor (B), whose crystals never run at exactly the same rate.
Lab: Distance from double-sided two-way ranging
A ranging exchange gives six timestamps from two clocks, in radio ticks of about 15.65 ps. A sends a poll and B receives it; B replies and A receives that; A sends a final message and B receives it. The timestamp counters are 40 bits wide and wrap around about every 17 s, so an interval is the difference masked to 40 bits (& TS_MASK), computed in 64-bit arithmetic.
twr_distance_mm(t) returns the distance in millimetres:
- the four intervals are A's round trip
Ra = rx_resp − tx_poll, B's reply timeDb = tx_resp − rx_poll, B's round tripRb = rx_final − tx_respand A's reply timeDa = tx_final − rx_resp; - a round trip must be longer than the other side's reply time. If
Ra <= DborRb <= Dathe timestamps are wrong (a missed message, a corrupted frame): return -1; - the time of flight is
(Ra × Rb − Da × Db) / (Ra + Rb + Da + Db)ticks, rounded to the nearest tick. The products fit in 64 bits, though not in 32; - one tick of flight is 4.6917 mm (the speed of light times 15.65 ps): the distance is
tof × 46917 / 10000.
The simpler single-sided formula, (Ra − Db) / 2, needs no third message, but a clock error of 20 ppm on a 300 µs reply already moves the result by almost a metre.
Going deeper
Interview question: How would you make a car key unlock only when the owner is really next to the car?
Answer: Measure the distance between key and car with ultra-wideband two-way ranging, which a relay attacker cannot shorten, alongside the existing secure challenge-response. Unlock only within a short range and in the right zone around the car, and fall back to a button press if ranging fails.
Interview question: Why can UWB measure position but BLE RSSI cannot do it accurately?
Answer: BLE RSSI estimates distance from received signal strength, which varies by many decibels with orientation, bodies, walls and reflections, giving errors of metres. UWB measures the arrival time of very short pulses, and because each pulse is about 2 ns long, the first-arriving direct path can be distinguished from later reflections and timestamped precisely, giving errors of around 10 cm.
Interview question: What limits UWB accuracy in practice?
Answer: Non-line-of-sight conditions, where the direct path is blocked and only delayed reflections arrive, adding positive range error; antenna delay errors if uncalibrated; clock drift between devices (mitigated by double-sided ranging); anchor geometry in TDoA systems; and multipath close to the direct path. Systems detect NLOS from signal quality metrics and filter positions over time.
Explain it: In your own words, explain how two-way ranging measures distance without the devices sharing a clock.
Answer: Device A sends a message and records when it left on its own clock. Device B receives it, waits a known time measured on B's clock, and replies. A records when the reply arrives. The total round-trip time on A's clock minus B's reply delay is twice the time the signal spent in flight, so halving it and multiplying by the speed of light gives the distance. Each device only measures intervals on its own clock, so no shared time is needed; a double-sided exchange cancels the small error from the clocks running at slightly different rates.