This system uses a Software Defined Radio (SDR) with machine learning to detect drones in the vicinity.
- Python 3.6+
- PlutoSDR or compatible SDR hardware
- libiio library
- Clone this repository:
git clone https://github.com/yourusername/drone-detection-system.git
cd drone-detection-system
- Install required Python packages:
pip install -r requirements.txt
- Connect your PlutoSDR device via USB or network.
To train an accurate model, you'll need to collect both drone data and background/noise data:
# To collect drone data (with drone flying nearby):
python drone_detection_system.py --collect-data --num-samples 1000
# To collect background data (with no drone):
python drone_detection_system.py --collect-data --num-samples 1000
After collecting background data, rename the output file:
mv drone_dataset/drone_data_*.npz drone_dataset/background_*.npz
You have two options for training models:
python train_drone_model.py
python advanced_model_training.py
The advanced training script:
- Uses more sophisticated features
- Trains multiple model types (XGBoost, Random Forest, SVM)
- Performs hyperparameter tuning
- Handles class imbalance with SMOTE
- Generates performance comparisons
- Selects the best model automatically
Start the detection system:
python drone_detection_system.py
This will:
- Connect to your SDR
- Load the trained model
- Display a real-time waterfall display
- Show drone detection probabilities
- Alert when a drone is detected
python drone_detection_system.py --collect-data [--num-samples N]
--collect-data: Enables data collection mode--num-samples N: Number of samples to collect (default: 1000)
python drone_detection_system.py [--tx-channel N] [--rx-channel N]
--tx-channel N: Transmit channel to use (default: 0)--rx-channel N: Receive channel to use (default: 0)
python train_drone_model.py [--dataset-dir DIR] [--output FILE] [--test-size S]
--dataset-dir DIR: Directory containing the dataset (default: 'drone_dataset')--output FILE: Output model filename (default: 'xgboost_drone_detection_model.json')--test-size S: Fraction of data to use for testing (default: 0.2)
python advanced_model_training.py [--dataset-dir DIR] [--output-dir DIR] [--test-size S] [--no-smote] [--no-advanced-features]
--dataset-dir DIR: Directory containing the dataset (default: 'drone_dataset')--output-dir DIR: Directory to save models and plots (default: 'models')--test-size S: Fraction of data to use for testing (default: 0.2)--no-smote: Disable SMOTE class balancing--no-advanced-features: Use simple feature extraction instead of advanced features
The system extracts advanced features from the radio signals:
-
Frequency Domain Features:
- Spectral statistics (mean, std, skewness, kurtosis)
- Spectral entropy
- Peak analysis
-
Time Domain Features:
- Statistical features of I/Q components
- Zero-crossing rate
- Envelope analysis
-
Modulation Features:
- AM component detection
- FM/PM component detection
-
Drone-Specific Features:
- Control band energy ratios
- Frequency hopping detection
-
Wavelet Features:
- Multi-resolution time-frequency analysis
-
Collect diverse data: Include drone data from different drones at various distances and angles.
-
Include environmental variations: Collect background data in different environments and conditions.
-
Use advanced training: The advanced training script will typically yield better results than the basic one.
-
Try different models: The system will compare XGBoost, Random Forest, and SVM models to find the best one.
-
Adjust SDR parameters: Try different gain settings and sample rates for optimal performance.
-
Hardware placement: Place your SDR antenna with clear line of sight for best reception.
If you have trouble connecting to your SDR:
- Check USB connection or network settings
- Ensure the SDR is powered properly
- Verify libiio is installed correctly
- Try unplugging and reconnecting the device
If the system is running slowly:
- Reduce the sample rate
- Close other applications consuming CPU resources
- Adjust buffer sizes for better performance
- Use simpler feature extraction with
--no-advanced-features
If detection accuracy is poor:
- Collect more training data from your specific drone
- Ensure training data includes both drone and background samples
- Adjust detection threshold in the code (
PROBABILITY_THRESHOLDin drone_detection_system.py) - Try running the advanced model training
If model training fails:
- Make sure you have sufficient drone and background samples
- Check that PyWavelets is installed if using advanced features
- Try using simpler features with
--no-advanced-features - Disable SMOTE with
--no-smoteif you encounter memory errors
This project is licensed under the MIT License - see the LICENSE file for details.