Part IX: Radar, Lidar, Depth, Thermal, Event, and RF Sensing
Chapter 47: RF and Wireless Sensing

Robustness across layouts and environments

"You trained me in a bare 4-by-5 meter lab and shipped me to a furnished studio with a couch where a wall used to be. The gesture is identical. The multipath that spelled it out is gone. Ninety-eight percent in the lab, forty percent here, and you are calling it my mistake."

A Relocated AI Agent

Prerequisites

This section assumes the CSI vocabulary of Section 47.1 (subcarriers, complex per-subcarrier gain, clock and frequency offsets) and the device-free pipeline of Section 47.2, including the Doppler Frequency Shift (DFS) spectrogram and the Body-coordinate Velocity Profile (BVP) introduced with Widar3.0. It is, at heart, a distribution-shift problem, so it is the RF-specific companion to the general treatment in Chapter 66, and every accuracy number here lives or dies by the leakage-safe splitting discipline of Chapter 5. Familiarity with the domain-invariant and self-supervised representations of Chapter 17 will help with the last subsection.

The property that makes RF sensing work is the same property that breaks it

A Wi-Fi sensing model reads the human body through multipath: the tangle of echoes bouncing off walls, furniture, and floor before reaching the receiver. That tangle is exactly what encodes a gesture into the channel. It is also exactly what changes when you move the link one meter, rotate the person forty-five degrees, swap the router, or carry the whole system into a different room. The activity is invariant; the channel that spells it out is not. This is why a device-free classifier routinely posts 95%-plus accuracy on a test set drawn from the same room and then collapses toward chance in an unseen environment. The gap is not overfitting in the usual sense of too many parameters. It is domain shift: the model learned the room, the geometry, and the antenna as much as it learned the motion. Making RF sensing shippable means attacking that shift on three fronts at once, the feature, the training objective, and the evaluation, and refusing to report the in-room number as if it were the field number.

The anatomy of RF domain shift

What shifts between a lab demo and a deployment is not one thing but a stack of nuisance factors, and naming them is the first engineering step. A CSI sample can be written as a function of the activity you want, \(a\), and a vector of domain factors \(d\) you do not: \(H = g(a, d) + \text{noise}\). Why this matters is that \(d\) has structure, and each component fails differently. The dominant factors, roughly in order of how much damage they do, are: (1) environment, the static multipath geometry of a specific room, which rewrites the entire background channel; (2) link geometry and location, where the person stands relative to the transmit and receive antennas, because the same gesture at a different position and range produces a different Doppler projection; (3) orientation, the direction the person faces, since radial velocity onto each link depends on body heading; (4) subject, body size and gait, which shift reflection strength and cadence; and (5) device and hardware, the specific NIC, its automatic gain control, antenna spacing, and firmware, which change amplitude scaling and phase behavior. How you diagnose which factor is hurting you is by holding the others fixed and varying one: a model robust to subject swaps but not to room swaps tells you the environment term dominates, and that steers you toward environment-invariant features rather than more subjects.

Domain generalization, not domain adaptation, is the honest target

There is a tempting shortcut: collect a little labeled or unlabeled data from each new room and adapt. That is domain adaptation, and it works, but it quietly assumes you get a calibration session in every deployment site before the system is trusted. For a product a customer installs and expects to work on day one, the real target is domain generalization: train on a set of source environments and generalize to a target environment you never saw and never sampled. The distinction changes everything downstream. Domain adaptation lets you use the target's statistics; domain generalization forbids it, so it forces the harder work of building representations that are invariant to \(d\) by construction. When a paper reports cross-domain accuracy, always ask which one it measured. An adaptation number with target data is not comparable to a generalization number without it, and conflating them is one of the most common ways RF-sensing results are oversold. This is the RF instance of the leave-one-domain-out principle from Chapter 66.

Building invariance into the signal and the feature

What the strongest classical defense does is transform the raw CSI into a representation where the nuisance factors have already been divided out, so the classifier never sees them. How this is done stacks several tricks. At the signal level, the CSI ratio from Section 47.2 cancels the clock-offset and hardware-phase term shared across antennas, removing much of the device factor for free. At the feature level, the DFS spectrogram is far more transferable than raw CSI because it discards the static-path structure and keeps only motion-induced frequency content; normalizing each spectrogram (per-sample energy normalization, and mapping to a canonical frequency axis) further suppresses gain and range effects. The decisive step is Widar3.0's BVP: by fusing DFS from several spatially separated links and solving for the distribution of body-part velocities in a coordinate frame anchored to the person, it cancels the location and orientation factors that a single-link spectrogram bakes in. A gesture yields nearly the same BVP whether performed facing north in room A or east in room B, which is precisely why BVP-trained classifiers survive the cross-room test that sinks raw-DFS classifiers. Why this is not the whole answer is that BVP still needs multiple synchronized links and does not fully cancel the environment's static multipath or subject-specific gait, so feature invariance buys a large gain but not immunity.

A smart-home gesture control that shipped only after the split changed

A consumer-electronics team built a Wi-Fi gesture remote: swipe to change the channel, push to pause, all from the couch, no wearable and no camera. Their internal benchmark showed 97% accuracy and they scheduled a launch. A skeptical evaluation lead re-ran the numbers with a leave-one-room-out split across the six apartments in the data instead of the random per-gesture split the team had used. Accuracy fell to 61%. The random split had leaked: gestures from the same room, same person, and same afternoon landed in both train and test, so the model was rewarded for recognizing the room. The fix was three-layered and mirrors this section. They moved the feature from single-link DFS to a BVP-style velocity profile to kill orientation dependence; they trained across all-but-one room with an environment-adversarial head (below) to strip residual room identity; and they adopted the leave-one-room-out number, 84% after the changes, as the only figure allowed on a slide. The launch slipped a quarter and shipped something that actually worked in a stranger's living room. The leakage they nearly shipped is the exact failure mode catalogued in Chapter 5.

Learning to generalize: adaptation, augmentation, and invariant training

What you add on top of invariant features are training objectives that actively discourage the model from encoding \(d\). Three families dominate. Adversarial domain-invariant learning (the DANN recipe) attaches a domain-classifier head to the shared encoder through a gradient-reversal layer, so the encoder is trained to make features from which the room cannot be predicted while the activity still can; this is the CSI cousin of the invariance objectives in Chapter 17. Data augmentation and virtual sampling synthesize new domains cheaply: Widar3.0's virtual-sample generation rotates and translates the BVP to fabricate gestures at unseen positions and orientations, and more recent work simulates propagation to render CSI for room layouts never physically measured, connecting to the synthetic-data and digital-twin methods of Chapter 55. Few-shot and meta-learning accept a tiny labeled set from the target and adapt fast, trading the day-one promise for a short enrollment. Why you usually combine them is that each attacks a different factor: augmentation covers geometry and orientation, adversarial training strips environment identity, and few-shot mops up the residual subject and device gap. When to reach for which is set by your deployment contract: pure generalization if the customer installs unattended, few-shot if a 30-second enrollment is acceptable.

Code 47.6.1 makes the leakage-versus-generalization gap concrete without needing a router. It builds a synthetic CSI-feature set where each activity has a true signature plus a large room-specific offset, then trains one linear classifier and evaluates it two ways: a random split that leaks the room, and a leave-one-room-out split that does not. The two accuracies are the illusion and the truth, and the code is referenced by the exercise below.

import numpy as np
from sklearn.linear_model import LogisticRegression

rng = np.random.default_rng(0)
n_rooms, n_acts, per = 6, 4, 60
act_sig  = rng.standard_normal((n_acts, 16))          # true, room-invariant per-activity signature
room_off = 3.0 * rng.standard_normal((n_rooms, 16))   # large static-multipath offset per room

X, y, room = [], [], []
for r in range(n_rooms):
    for a in range(n_acts):
        feats = act_sig[a] + room_off[r] + 0.4 * rng.standard_normal((per, 16))
        X.append(feats); y += [a] * per; room += [r] * per
X = np.vstack(X); y = np.array(y); room = np.array(room)

# (1) Random split: rows from every room appear in train AND test -> leaks the room
idx = rng.permutation(len(y)); cut = int(0.7 * len(y))
tr, te = idx[:cut], idx[cut:]
acc_leak = LogisticRegression(max_iter=2000).fit(X[tr], y[tr]).score(X[te], y[te])

# (2) Leave-one-room-out: test room never seen in training -> honest generalization
accs = []
for held in range(n_rooms):
    tr, te = room != held, room == held
    accs.append(LogisticRegression(max_iter=2000).fit(X[tr], y[tr]).score(X[te], y[te]))
print(f"random split (leaked):     {acc_leak:.2f}")
print(f"leave-one-room-out (honest): {np.mean(accs):.2f}")
# random split (leaked):     1.00
# leave-one-room-out (honest): 0.32
Code 47.6.1: The domain-shift illusion in twenty lines. A random split lets the large per-room offset act as a giveaway feature, yielding near-perfect accuracy; the leave-one-room-out split withholds the target room's offset entirely, and accuracy collapses toward the 0.25 chance level of four classes. The gap between the two numbers is the domain shift a real deployment must pay. Invariant features and adversarial training are what close it.

Right tool: cross-domain splits and adversarial heads you do not hand-roll

Two chores in this section are library-sized. First, the leave-one-domain-out cross-validation loop is exactly scikit-learn's LeaveOneGroupOut: pass the room label as the group and it yields every held-out-room fold, replacing the hand-written loop in Code 47.6.1 and guaranteeing you never leak a group. Second, the gradient-reversal layer behind adversarial domain-invariant training is a one-line autograd Function in PyTorch (a custom backward that negates the gradient), but packages such as pytorch-adapt and Dassl ship DANN, CORAL, and domain-generalization trainers as configurable objects, turning a careful 200-line implementation into roughly 20 lines of setup. What no library supplies is the domain labels themselves: you still have to record which room, link, and subject produced each sample, and that metadata is the leakage-safe backbone from Chapter 5.

Measuring robustness so the number survives contact with a new room

What a trustworthy RF-sensing evaluation reports is not one accuracy but a matrix of them, factored by the domain axes above. How to build it: hold out an entire environment (leave-one-room-out), then separately hold out orientation, location, and subject, and report each gap against the in-domain baseline. A model that loses two points across subjects but thirty across rooms has told you where the engineering must go. Why the single-number habit is dangerous is that it hides which factor is fragile and invites the random-split leakage of Code 47.6.1. Two practices harden the report. First, always pair the cross-domain accuracy with the in-domain accuracy on the same data; the gap, not the absolute, is the generalization claim. Second, calibrate under shift: a model that stays accurate but becomes wildly overconfident off-domain is often worse than one that degrades and knows it, which is why the conformal and calibration tooling of the broader distribution-shift treatment in Chapter 66 belongs in the same evaluation harness. The Widar3.0 lab for this chapter is designed around exactly this discipline: train on a subset of rooms and orientations, test on the withheld ones, and read the cross-domain gap rather than the flattering in-domain peak.

Where cross-environment RF sensing is headed

The frontier is converging on foundation-scale CSI pretraining: self-supervised encoders trained on large unlabeled multi-environment CSI corpora, so a downstream classifier inherits an already-invariant representation and needs few or zero target samples, echoing the transfer that reshaped the wearable models of Chapter 20. Physics-based augmentation is maturing in parallel: ray-tracing and differentiable propagation simulators (the digital-twin idea of Chapter 55) render CSI for room geometries never measured, manufacturing the environment diversity that hand-collection cannot. A third thread rides the standardization wave of Section 47.5: IEEE 802.11bf defines sensing measurements uniformly across vendors, which shrinks the device factor that today forces per-NIC retraining. The open problem underneath all three is the smart-home team's: a model a stranger installs in an unseen room and trusts on day one, with a calibrated confidence that admits when the room is too unlike anything it has seen.

Exercise: quantify each domain factor's damage

Extend Code 47.6.1. (1) Add an orientation factor: give each sample one of three orientation offsets and re-run leave-one-orientation-out alongside leave-one-room-out; rank the two factors by the accuracy gap they cause. (2) Shrink room_off toward zero and watch the leaked and honest accuracies converge; explain in one sentence what a small offset means physically. (3) Add a crude invariant feature by subtracting each sample's own room-mean (a stand-in for BVP-style anchoring) and show that leave-one-room-out accuracy recovers; state why this is cheating in a way BVP is not (hint: you used the target room's statistics). (4) Replace the hand-written fold loop with scikit-learn's LeaveOneGroupOut and confirm the numbers match. Then connect (3) to the domain-adaptation-versus-generalization distinction in the key-insight callout.

Self-check

1. A model scores 96% with a random split and 58% with leave-one-room-out on the same data. What is the 96% actually measuring, and which number do you put in the datasheet?

2. Name three domain factors in the vector \(d\) and, for each, one technique from this section that specifically attacks it.

3. Why does a BVP transfer across rooms better than a single-link DFS spectrogram, and what does BVP still fail to cancel?

4. A colleague reports strong "cross-domain" accuracy but used 30 labeled samples from the target room. Is this domain generalization or domain adaptation, and why does the distinction change what you can claim?

What's Next

In Section 47.7, we turn from making RF sensing robust to reckoning with what robust, ubiquitous RF sensing means for people who never consented to being sensed. The same multipath perturbation that a well-generalized model reads as a gesture can, at scale, read presence, count, and activity through walls in any Wi-Fi-covered space, and the privacy implications are the subject that closes the chapter.