Sitemap

How I Turned My Wi-Fi Into a Motion Sensor…

9 min read2 days ago

… using only the waves emitted by my router and a bit of mathematics.

Press enter or click to view image in full size
My home “laboratory”: an ESP32-S3 with external antenna.

The Moment of Impatience

On September 26, 2025, the IEEE 802.11bf standard was published, enabling Wi-Fi to natively detect motion. But I didn’t want to wait.

The first compatible devices will arrive in a few months (maybe), but as a home automation enthusiast, I have a problem with waiting 😅.

So I developed a small motion detection system based on Wi-Fi spectrum analysis that:

  • Uses a microcontroller costing less than $10 (ESP32-S3) as a detector
  • Integrates natively with Home Assistant
  • Detects movement even through walls (privacy “almost” guaranteed)
  • Uses only mathematics and signal processing (no AI)

The LinkedIn post I wrote that day went viral in a very short time, surpassing 4000 likes, and the GitHub project (ESPectre) reached almost 2000 stars in two weeks. Perhaps I wasn’t the only impatient one!

Who I Am and Why I Did It

My name is Francesco Pace, I have a degree in mathematics and have been working in IT for over 20 years. Home automation is one of my passions, and recently I came across the world of Wi-Fi Sensing.

Although the 802.11bf standard has just been released, the underlying technology isn’t actually new and dates back to the late 1990s. It’s called Channel State Information (CSI) and involves processing a large amount of physical information from the various subcarriers of the Wi-Fi signal.

The problem? The signal is extremely noisy. Appliances, TVs, cell phones, and people themselves generate continuous interference. For this reason, most existing solutions use Machine Learning techniques to clean the data and recognize specific patterns of human movement.

In a world now dominated by AI and Machine Learning, I wanted to demonstrate that it was possible to achieve excellent results even with inexpensive hardware, using only mathematics and signal processing. No neural networks, no model training, no gigabyte datasets: just mathematical algorithms, digital filters, and classic signal analysis.

How It Works: Making the Invisible Visible

The Flashlight Analogy

Imagine holding a lit flashlight in a dark room. If you move your hand in front of the light, the shadow changes. If someone walks in the room, the shadows move differently.

Wi-Fi works the same way, but with invisible electromagnetic waves instead of light. When someone moves in a room, they “disturb” the Wi-Fi waves traveling between the router and the sensor. The sensor “listens” to these changes and understands if there is movement.

What CSI Data Is

Technically, what we analyze is called CSI (Channel State Information): information about the state of the radio channel.

In modern Wi-Fi systems (OFDM, Orthogonal Frequency-Division Multiplexing), the signal is transmitted over dozens of subcarriers, i.e., different frequencies traveling in parallel. For each subcarrier, the receiver calculates:

  • Amplitude: how strong the signal is
  • Phase: how much it is “shifted” compared to the original signal

When a person moves, it changes:

  • Multipath propagation (the signal bounces off walls, furniture, human body)
  • Doppler effect (movement creates micro-variations in frequency)
  • Electromagnetic field distribution in space

These changes are mathematically detectable even through walls, without the need for cameras or microphones. But how does it work exactly? Let’s dive into the details.

The Basic Mathematics

Here’s where it gets interesting. How do you go from radio waves to “someone is home”?

1. Subcarrier Selection with PCA

The ESP32-S3 provides 64 subcarriers (128 bytes total). Each subcarrier is represented as a complex number with two components:

  • I (In-phase): the “real” component of the signal, aligned with the reference wave
  • Q (Quadrature): the “imaginary” component, 90° out of phase with the first

This I/Q representation captures both the amplitude and phase of the signal:

  • Amplitude = √(I² + Q²) → how strong the signal is
  • Phase = arctan(Q/I) → how much it is “shifted” compared to the original signal

Why is this important? Because when a person moves, both the amplitude (the signal attenuates or strengthens) and the phase (the signal arrives with a different delay due to reflections) change. Complex numbers allow us to capture both pieces of information in a single value.

But not all 64 subcarriers are equally useful. Some are noisier, others more sensitive to movement.

Here, a technique called Principal Component Analysis (PCA) helps us identify which subcarriers contain the most useful information. In my case, these are subcarriers 47 to 58.

This choice is not arbitrary; it’s the result of mathematical analysis that maximizes the signal-to-noise ratio. Scientific literature confirms that subcarrier selection is crucial for achieving good performance with low-cost hardware like the ESP32-S3.

2. Moving Variance Segmentation (MVS)

The heart of the system is an algorithm we’ll call Moving Variance Segmentation. It works like this:

Step 1: Spatial Turbulence Calculation

For each CSI packet, I calculate the standard deviation of the amplitudes of the selected subcarriers:

turbulence = std(amplitudes[47:58])

This metric captures how “disturbed” the signal is in the frequency space.

Step 2: Moving Variance

I maintain a circular buffer of the last 20 turbulence measurements and calculate the moving variance:

moving_variance = var(turbulence_buffer[t-20:t])

Why variance and not mean? Because movement creates fluctuations, not just level changes. Variance captures precisely these fluctuations.

Step 3: Adaptive Threshold

During an initial calibration phase (2–3 minutes in a quiet environment), I collect the moving variances and calculate:

threshold = mean(variances) + K * std(variances)

Where K=2.5 is an empirical factor. This is an adaptive threshold that automatically adjusts to the specific environment (room size, materials, interference).

Step 4: State Machine

The system operates with a simple 2-level state machine:

  • IDLE: moving_variance < threshold → no movement
  • MOTION: moving_variance ≥ threshold → movement detected
Press enter or click to view image in full size
In the image: the two upper graphs show the quiet state (baseline), while the lower ones show motion detection. The blue graphs represent the spatial “turbulence” of the signal.

3. Digital Filter Pipeline

At this point, we know how to detect movement (thanks to Moving Variance Segmentation), but for more advanced tasks like classification (distinguishing between walking, running, falling, gestures), we need to go further.

To classify the type of movement, we need to extract more detailed information from the signal, called features. But before doing so, it’s essential to clean the signal from background noise (denoising): appliances, Wi-Fi interference, environmental vibrations create “noise” that masks human movement patterns.

To do this, we apply a digital filter pipeline in sequence, each specialized in removing a specific type of noise:

Butterworth Low-Pass (8Hz)

Removes high-frequency noise (>8Hz) caused by environmental interference:

H(s) = 1 / (1 + (s/ωc)^(2n))

Where ωc = 8Hz and n=4 (filter order).

Wavelet Daubechies db4

This is the most interesting filter. Based on a 2022 study (Location Intelligence System), I discovered that wavelet db4 outperforms traditional filters (Butterworth, Gaussian) for CSI denoising on ESP32.

The db4 wavelet decomposes the signal into:

  • Approximation coefficients (low-pass): clean signal
  • Detail coefficients (high-pass): noise

I keep only the approximation coefficients, eliminating persistent low-frequency noise.

Hampel Filter

Removes outliers using Median Absolute Deviation (MAD):

MAD = median(|x_i - median(x)|)
outlier if |x_i - median(x)| > k * MAD

With k=3, this filter is robust and non-parametric.

Savitzky-Golay

Polynomial smoothing that preserves signal peaks (important for detecting rapid movements).

4. Mathematical Feature Extraction

After detecting movement and obtaining a clean signal, we can now extract features from the filtered signal:

Statistical Features (5)

  1. Variance: var(signal) - signal variability
  2. Skewness: E[(X-μ)³]/σ³ - distribution asymmetry
  3. Kurtosis: E[(X-μ)⁴]/σ⁴ - 3 - "heavy tails" of the distribution
  4. Shannon Entropy: H(X) = -Σ p(x) log₂ p(x) - signal disorder
  5. IQR (Interquartile Range): Q3 - Q1 - robust spread

Spatial Features (3)

  1. Spatial variance: variability between adjacent subcarriers
  2. Spatial correlation: corr(subcarrier[i], subcarrier[i+1])
  3. Spatial gradient: mean(|subcarrier[i+1] - subcarrier[i]|)

Temporal Features (2)

  1. Delta mean: mean(|CSI[t] - CSI[t-1]|) - average change
  2. Delta variance: var(|CSI[t] - CSI[t-1]|) - variability of change

These features can be used for more advanced tasks (people counting, activity recognition), but they are not necessary for simple motion detection.

The Results

System Performance

After weeks of testing and studying dozens of papers, the results are excellent:

  • Presence detection: ~95% accuracy (IDLE vs MOTION)
  • Latency: <50ms per packet (the system processes ~20–100 packets/second in real-time)

Real-World Use Cases

The limit is only your imagination, but here are some practical scenarios:

  1. Home security: notifications when movement is detected
  2. Smart automations: lights that turn on only when needed
  3. Energy saving: heating that turns off in empty rooms
  4. Elderly monitoring: alerts if there’s no movement for too long
  5. Office presence: workspace optimization

Why Mathematics and Not AI?

  1. No training required: works out-of-the-box after 2 minutes of calibration
  2. Lightweight: runs on a microcontroller costing less than $10 in real-time
  3. Deterministic: same input → same output (no “black box”)

Limitations of the Mathematical Approach

The mathematical approach has limitations:

  • Doesn’t distinguish between people and pets
  • Doesn’t count how many people there are
  • Doesn’t recognize specific activities (walking, running, falling…)

For these more complex tasks, ML models are needed. But the beauty of ESPectre is that the mathematical features extracted are perfect as input for a neural network.

ML-Ready Integration via MQTT

Each ESP32 device publishes a JSON message on MQTT containing both segmentation data and extracted features. Here’s an example:

{
"movement": 2.45,
"threshold": 2.20,
"state": "motion",
"segments_total": 6,
"features": {
"variance": 315.5,
"skewness": 0.85,
"kurtosis": 1.23,
"entropy": 4.56,
"iqr": 89.2,
"spatial_variance": 234.1,
"spatial_correlation": 0.67,
"spatial_gradient": 12.3,
"temporal_delta_mean": 45.6,
"temporal_delta_variance": 78.9
},
"timestamp": 1730066405
}

Privacy and Ethical Considerations

Although CSI data is technically anonymous (it doesn’t contain images or audio), the system can detect the presence and movement of people. This raises important ethical and legal questions.

Potential Risks

The system can be used for:

  • Non-consensual monitoring
  • Behavioral profiling
  • Violation of domestic privacy

Legal Compliance

Important: Privacy laws vary by jurisdiction, but behavioral pattern data is often considered personal data requiring proper handling.

  • European Union: GDPR applies
  • United States: State laws vary (CCPA in California, CDPA in Virginia, etc.)
  • Canada: PIPEDA may apply
  • United Kingdom: UK GDPR and Data Protection Act apply
  • Other regions: Consult local privacy regulations

Users are personally responsible for:

  1. Obtaining explicit and informed consent from all monitored persons
  2. Complying with applicable privacy laws in their jurisdiction
  3. Clearly informing about the system’s presence (e.g., visible signage)
  4. Limiting use to legitimate purposes (personal security, permitted home automation)
  5. Implementing adequate security measures to protect collected data
  6. Providing data access and deletion rights where required by law

Like all tools, this technology can be used ethically or unethically. Legal responsibility falls entirely on the end user, not on the opensource project.

Practical Recommendations

  • Use the system only in environments you control (your home)
  • Don’t install devices in shared spaces without explicit consent from all occupants
  • Document the use of the system and its purposes
  • Consider the privacy impact on occasional visitors
  • Consult legal counsel if deploying in commercial or public settings

Privacy is not just a legal requirement, it’s a fundamental right. Use this technology responsibly.

Resources

Project and Contacts

Scientific References

This project is based on in-depth research in the field of Wi-Fi Sensing and CSI analysis:

[1] University of Bologna. Wi-Fi Sensing for Human Identification through CSI. University thesis, 2021. Available: https://amslaurea.unibo.it/id/eprint/29166/1/tesi.pdf

[2] Polytechnic University of Milan. Channel State Information (CSI) Features Collection in Wi-Fi. Master’s thesis, 2022. Available: https://www.politesi.polimi.it/handle/10589/196727

[3] Wang, W., Liu, A. X., Shahzad, M., Ling, K., & Lu, S. Indoor Motion Detection Using Wi-Fi Channel State Information in Flat Fading Environments. Sensors, 18(7), 2018. Available: https://pmc.ncbi.nlm.nih.gov/articles/PMC6068568/

[4] Hernandez, S. M., & Bulut, E. WiFi Motion Detection: A Study into Efficacy and Classification. arXiv preprint arXiv:1908.08476, 2019. Available: https://arxiv.org/abs/1908.08476

[5] Zou, H., Zhou, Y., Yang, J., Gu, W., Xie, L., & Spanos, C. CSI-HC: A WiFi-Based Indoor Complex Human Motion Recognition Method. Mobile Information Systems, 2020. Available: https://onlinelibrary.wiley.com/doi/10.1155/2020/3185416

[6] Hernandez, S. M., Seker, R., & Bulut, E. Location Intelligence System for People Estimation During Emergency Using WiFi Channel State Information. Proceedings of the 55th Hawaii International Conference on System Sciences (HICSS), 2022. Available: https://scholarspace.manoa.hawaii.edu/server/api/core/bitstreams/a2d2de7c-7697-485b-97c5-62f4bf1260d0/content

Conclusions

ESPectre demonstrates that it’s possible to create advanced sensing systems with inexpensive hardware and classic mathematical approaches.

The future of Wi-Fi Sensing is promising, and projects like this allow anyone to experiment today with technologies that will become standard tomorrow.

The code is completely open source (GPLv3): experiment, modify, improve, and if you liked it, leave a star ⭐ on GitHub!

Francesco Pace
Francesco Pace

Written by Francesco Pace

Math background, 20+ years in software (dev, architecture, leadership). Now commercial but still building: home automation, IoT, signal processing.

No responses yet

Write a response