Skip to content

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“‘ WiFi-Based-Human-Detection-through-Signal-Analysis

Detect human presence in a room using only WiFi signals β€” no cameras, no special sensors, no extra hardware.

Python PyTorch Platform License Status


🧠 What is this?

This project detects whether a human is present in a room by analyzing fluctuations in WiFi signal patterns β€” caused by the human body absorbing and reflecting radio frequency signals.

When a person is in a room, their body subtly disturbs the WiFi environment. These disturbances show up as microscopic changes in signal strength (RSSI) and ping latency. This system captures those changes, extracts statistical patterns, and uses Machine Learning to classify them in real time.

Inspired by research systems like MIT WiTrack and Meta WiFi DensePose β€” but built entirely with consumer hardware and free software.


βœ… What it can do

Capability Status
Human presence detection (present / absent) βœ… Working
Real-time inference with live terminal dashboard βœ… Working
Auto-labeling via webcam during data collection βœ… Working
GPU-accelerated LSTM training (CUDA) βœ… Working
Through-wall detection ⏳ Future (needs CSI hardware)
Activity recognition (walking, sitting) ⏳ Future

πŸ› οΈ Hardware Used

Component Details
Laptop ASUS TUF F15 β€” GTX 1650, 8GB RAM
Router Any standard home WiFi router
Webcam Built-in laptop webcam (for labeling only)
Special sensors ❌ None

Zero extra cost. If you have a laptop and a WiFi router, you can run this.


πŸ”¬ How It Works

Router ──ping──► Laptop
                    β”‚
             RSSI + Latency
             sampled at 2 Hz
                    β”‚
           Sliding window
           (last 20 samples)
                    β”‚
        11 statistical features
        (std, variance, peaks, ROC...)
                    β”‚
         Random Forest / LSTM
                    β”‚
        "πŸ‘€ PERSON PRESENT β€” 91.5%"

Why does it work?

The human body is an RF (radio frequency) absorber and reflector. When a person enters a room, WiFi signals bounce differently β€” causing measurable (but invisible to the naked eye) changes in:

  • Latency β€” how long a ping takes to reach the router
  • RSSI β€” received signal strength

These patterns differ between an occupied and empty room. ML learns these patterns from labeled data and generalizes to new readings.


πŸ“ Project Structure

wifi_detection/
β”œβ”€β”€ collect.py      # Stage 1 β€” RSSI + latency collection + webcam auto-labeling
β”œβ”€β”€ features.py     # Stage 2 β€” Sliding window feature extraction
β”œβ”€β”€ train.py        # Stage 3 β€” Random Forest + LSTM (PyTorch) training
β”œβ”€β”€ detect.py       # Stage 4 β€” Real-time inference + terminal dashboard
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw_samples.csv    # Raw collected signal data
β”‚   └── features.csv       # Extracted feature windows
└── models/
    β”œβ”€β”€ rf_model.pkl        # Trained Random Forest
    β”œβ”€β”€ lstm_model.pt       # Trained LSTM weights
    └── scaler.pkl          # Feature normalizer

βš™οΈ Setup

1. Clone the repo

git clone https://github.com/YOUR_USERNAME/wifi_detection.git
cd wifi_detection

2. Install dependencies

pip install -r requirements.txt

3. Install PyTorch (with CUDA for GPU training)

# For NVIDIA GPU (recommended)
pip install torch --index-url https://download.pytorch.org/whl/cu121

# CPU only
pip install torch

πŸš€ Usage β€” Step by Step

Step 1 β€” Find your router IP

ipconfig
# Look for "Default Gateway" β†’ usually 192.168.1.1

Step 2 β€” Collect training data

python collect.py --router 192.168.1.1 --duration 600
  • Run for at least 10 minutes
  • Spend ~5 min in the room (person present) and ~5 min outside (room empty)
  • Webcam automatically labels frames using motion detection
  • No camera? Use --no-cam flag and label manually

Data saved to data/raw_samples.csv

Step 3 β€” Extract features

python features.py

Converts raw signal readings into 11 statistical features using sliding windows. Output β†’ data/features.csv

Step 4 β€” Train models

python train.py

Trains two models:

  • Random Forest β€” fast, interpretable baseline
  • LSTM (PyTorch) β€” captures temporal patterns, uses GPU if available

Models saved to models/

Step 5 β€” Real-time detection

# Random Forest (recommended for low data)
python detect.py --router 192.168.1.1 --model rf

# LSTM (better with 1000+ training samples)
python detect.py --router 192.168.1.1 --model lstm

Live output:

πŸ‘€ PERSON PRESENT  [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]  91.5%  RSSI=82.0%  Lat=2.0ms  n=0114
πŸ”² ROOM EMPTY      [β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]  28.2%  RSSI=82.0%  Lat=1.0ms  n=0195

πŸ“Š Features Extracted

Feature Description
rssi_mean Average signal strength in window
rssi_std How much signal fluctuated
rssi_range Max βˆ’ Min signal value
rssi_roc Rate of change (speed of fluctuation)
rssi_peak_cnt Number of signal spikes
lat_mean Average ping latency
lat_std Latency variance
lat_max Worst latency in window
lat_roc Latency change rate
lat_peak_cnt Number of latency spikes
rssi_lat_corr Correlation between RSSI and latency

πŸ“ˆ Results

Tested on ASUS TUF F15 with a standard home router:

Model Accuracy Training Data
Random Forest ~69% 668 samples (~10 min)
LSTM ~53% Needs more data (1000+ samples)

Accuracy improves significantly with more training data. 30+ minutes of varied movement data can push RF accuracy above 85%.

Top predictive features (Random Forest importance):

lat_std       β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  0.275
lat_mean      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   0.261
lat_roc       β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ        0.207
lat_max       β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ           0.157
lat_peak_cnt  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ               0.100

Latency features dominate because RSSI stays relatively stable on consumer hardware, while latency shows more sensitivity to human presence.


πŸ”­ Why not CSI?

Real research-grade WiFi sensing (WiTrack, DensePose) uses Channel State Information (CSI) β€” raw physical layer data with amplitude and phase across multiple frequency subcarriers. Far richer than RSSI.

CSI requires special hardware (Intel 5300 NIC, ESP32 with modified firmware). This project intentionally avoids that to stay zero-cost and fully accessible.


πŸ—ΊοΈ Future Roadmap

  • Collect 2000+ samples and retrain for 85%+ accuracy
  • Add CSI support via ESP32 (optional hardware upgrade path)
  • Activity recognition: walking vs sitting vs stationary
  • Multi-person occupancy counting
  • Web dashboard (Flask + React) for visualization
  • Integration with smart home systems (Home Assistant, MQTT)
  • Paranormal activity detection (EMF anomaly classification)

πŸ§ͺ Tech Stack

Tool Use
Python 3.10+ Core language
OpenCV Webcam motion-based labeling
NumPy / Pandas Data processing
SciPy Peak detection, signal processing
Scikit-learn Random Forest, preprocessing
PyTorch LSTM model + CUDA training
Windows netsh RSSI extraction
Windows ping Latency measurement

⚠️ Limitations

  • Detection is coarse (present/absent), not fine-grained activity recognition
  • Consumer RSSI is often stable β€” model relies mainly on latency variance
  • Accuracy varies with room size, router placement, and wall materials
  • Through-wall detection not possible without CSI hardware
  • Currently Windows only (uses netsh and ping commands)

πŸ“š References & Inspiration


πŸ‘¨β€πŸ’» Author Nishant Singh

πŸ“§ Email: ns1199816@gmail.com

πŸ”— GitHub: https://github.com/nishant1199816

πŸ”— LinkedIn: https://www.linkedin.com/in/nishant-singh-tech/

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages