8000 GitHub - ekowtaylor/gnss_sim · GitHub
[go: up one dir, main page]

Skip to content
ekowtaylorPublic

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Python GNSS Simulator

A pure Python software-defined GNSS signal simulator. This project generates GPS L1 C/A baseband signal IQ data, which can be transmitted using Software Defined Radio (SDR) hardware like the HackRF One.

Features

  • Multi-Constellation Support:
    • GPS L1 C/A (✅ ICD-compliant)
    • Galileo E1 (✅ ICD-compliant with CBOC modulation)
    • GLONASS G1 FDMA (✅ ICD-compliant with FDMA)
  • Ephemeris Handling:
    • Automatically downloads and parses RINEX navigation files (from CDDIS/IGS)
    • NEW: SGP4 orbit propagation with TLE files for high-fidelity multi-day scenarios
  • Orbit Propagation:
    • Keplerian orbit propagation for precise satellite positioning (GPS/Galileo)
    • GLONASS state-vector propagation
    • NEW: SGP4 perturbation model via Skyfield library
  • Trajectory Options:
    • Static receiver position
    • Circular motion (testing)
    • NEW: KML file ingestion for realistic flight paths (Google Earth compatible)
  • SDR Integration: Direct interface with HackRF and other SDRs via SoapySDR.

Signal Support

Signal Center Freq Status with SDR
L1 C/A 1575.42 MHz ✅ Production (ICD-compliant)
E1 1575.42 MHz ✅ Production (ICD-compliant with CBOC, secondary codes)
G1 1602 + k*0.5625 MHz ✅ Production (ICD-compliant with FDMA)

Tip

All signal generators are now ICD-compliant (~95% implementation) with proper PRN code generation, navigation message structures, and error correction codes. See ICD_COMPLIANCE.md for detailed specifications.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/gnss_sim.git
    cd gnss_sim
  2. Set up the environment:

    # Create and activate virtual environment
    python3 -m venv .venv
    source .venv/bin/activate
    
    # Install dependencies
    pip install -r requirements.txt
  3. Install SoapySDR (Optional): If you plan to use transmit_iq.py, you need SoapySDR bindings.

    • macOS: brew install soapy-sdr
    • Linux: sudo apt install python3-soapysdr or build from source.

Usage

1. Generate Signal

Run the simulation to generate an IQ file. By default, this generates a 1-second GPS L1 C/A signal for San Francisco and saves it to output/gps_sim_test.iq.

export PYTHONPATH=src
python run_sim.py

Customize with CLI options:

# London, 10 seconds, GPS only
python run_sim.py --lat 51.5074 --lon -0.1278 --duration 10 --constellations G --output output/london.iq

# Tokyo, 30 seconds, all constellations (GPS + Galileo + GLONASS)
python run_sim.py --lat 35.6762 --lon 139.6503 --duration 30 --constellations GER

# Sydney, 60 seconds, with GLONASS FDMA enabled
python run_sim.py --lat -33.8688 --lon 151.2093 --duration 60 --constellations R --glonass-fdma

# Custom sample rate and output file
python run_sim.py --rate 2000000 --output output/my_signal.iq

# 🆕 Use SGP4 orbit propagation with TLE file
python run_sim.py --sgp4 --tle data/ephemeris/gps_sample.tle --duration 60

# 🆕 Load trajectory from Google Earth KML file
python run_sim.py --kml data/trajectory/sf_flight.kml --duration 30

# 🆕 Combine SGP4 + KML for realistic flight simulation
python run_sim.py --kml flight_path.kml --sgp4 --tle gps.tle --duration 300

Available options:

  • --lat / --lon / --alt: Receiver position (lat/lon in degrees, alt in meters)
  • --kml: NEW Load trajectory from KML file (overrides lat/lon/alt)
  • --duration: Signal duration in seconds (default: 1)
  • --rate: Sample rate in Hz (default: 4000000 / 4 MHz)
  • --constellations: Constellation codes to include (G=GPS, E=Galileo, R=GLONASS)
  • --glonass-fdma: Enable GLONASS FDMA mode (wider bandwidth)
  • --sgp4: NEW Use SGP4 propagation (requires --tle)
  • --tle: NEW Path to TLE file for SGP4 mode
  • --6dof: NEW Enable 6DOF motion (acceleration + attitude)
  • --multipath: NEW Multipath environment (open-sky, ground, urban, indoor, severe)
  • --output: Output IQ file name (default: output/gps_sim_test.iq)
  • --ephemeris: Path to RINEX navigation file

See python run_sim.py --help for all options.

1.5. Web GUI 🌐 (NEW)

Launch the web interface for visual scenario creation:

cd web
./start_server.sh

Then open http://localhost:5001 in your browser.

Features:

  • 🗺️ Interactive map (Leaflet.js) - click to set location
  • 🛣️ Trajectory options: static, circular, or KML upload
  • ⚙️ Full parameter control: duration, sample rate, constellations
  • 🏢 Multipath presets: open-sky, ground, urban, indoor, severe
  • 📊 Real-time visualization: spectrum display with Plotly.js
  • 📁 File management: browse and download generated signals
  • 🚀 One-click generation: no command line needed!

API Access: The web GUI provides RESTful endpoints for programmatic access:

# Generate signal via API
curl -X POST http://localhost:5001/api/simulate \
  -H "Content-Type: application/json" \
  -d '{"location": {"lat": 37.7749, "lon": -122.4194, "alt": 100}, 
       "duration": 10, "multipath": "urban", "enable_6dof": true}'

# Download file
curl -O http://localhost:5001/api/download/sim_20260216_123045.iq

# Get spectrum data
curl http://localhost:5001/api/spectrum/sim_20260216_123045.iq

See web/README.md for complete documentation.

2. Playback & Analyze IQ Files

You can view, analyze, and record IQ files in three ways:

Option A: Statistical Analysis (CLI)

Analyze signal statistics and generate plots:

python tools/verify_iq.py output/gps_sim_test.iq --rate 4000000

Generates plots showing:

  • Time-domain I/Q signals
  • Constellation diagram
  • Power spectrum
  • Power vs time
  • Amplitude distribution

Output: images/gps_sim_test_analysis.png

Option B: Record from SDR

Capture real signals from your HackRF (or other SDR) to test against the simulation:

./receive.sh output/captured.iq --duration 30 --gain 20

Options:

  • --duration: Recording time in seconds (default: 10)
  • --gain: RX gain in dB (default: 0)
  • --freq: Center frequency (default: 1575.42 MHz = GPS L1)
  • --rate: Sample rate (default: 4 MHz)
  • --device: Device type (default: driver=hackrf)

Then compare generated vs. captured:

python tools/verify_iq.py output/captured.iq --duration 1.0
python tools/verify_iq.py output/gps_sim_test.iq --duration 1.0

Option C: Visual Playback (GUI)

Use GQRX to visualize and play back signals in real-time:

gqrx

In GQRX:

  1. Select Device → HackRF One
  2. File → Open IQ file (select output/gps_sim_test.iq)
  3. Set frequency to 1575.42 MHz
  4. Adjust gain to see signal spectrum

Useful for:

  • Spectral inspection
  • Waterfall visualization
  • Real-time frequency analysis

3. Transmit using SDR

Warning

Legal Warning: Transmitting GNSS signals over the air is illegal in most jurisdictions without a license. Always perform tests in a shielded environment (Faraday cage) or via conducted path (cables + attenuators) to prevent interference with live GPS signals.

Option A: Quick transmission (HackRF only)

Connect your HackRF and run:

./transmit.sh output/gps_sim_test.iq --rate 4000000 --freq 1575420000 --gain 40

Option B: Manual transmission (any SoapySDR device)

Identify your device:

SoapySDRUtil --find

Then transmit:

python tools/transmit_iq.py output/gps_sim_test.iq --device "driver=hackrf" --rate 4000000 --freq 1575420000 --gain 40

Replace driver=hackrf with your device args. Examples:

  • USRP: driver=uhd,serial=XXXX
  • PlutoSDR: driver=plutosdr
  • LimeSDR: driver=lime
  • BladeRF: driver=bladerf

Project Structure

  • src/gnss_sim/: Core source code
    • ephemeris/: RINEX downloading and parsing, SGP4 propagator
    • trajectory/: Receiver path generation, KML loader, 6DOF dynamics
    • signal/: Signal modulation logic, multipath model
    • nav/: Navigation message generation
    • sdr/: Hardware interface
  • web/: NEW Flask web GUI
    • app.py: Web server and API endpoints
    • templates/index.html: Interactive web interface
    • README.md: Web GUI documentation
  • tools/: Utility scripts
    • transmit_iq.py: Transmit IQ data via SDR
    • receive_iq.py: Record IQ data from SDR
    • verify_iq.py: Analyze and visualize IQ files
  • tests/: NEW Automated test suite
    • test_signal_accuracy.py: 11 validation tests
  • run_sim.py: Main entry point - Generate GNSS signals (configurable via CLI)
  • output/: Generated IQ files
  • data/: Storage for downloaded ephemeris files and trajectories
    • ephemeris/: RINEX and TLE files
    • trajectory/: KML trajectory files

Advanced Features

SGP4 Orbit Propagation

For high-fidelity multi-day simulations, use SGP4 with TLE files:

# Download TLE from space-track.org or celestrak.org
python run_sim.py --sgp4 --tle gps_constellation.tle --duration 86400

Benefits:

  • Accurate long-term propagation (days/weeks)
  • Accounts for atmospheric drag and perturbations
  • Compatible with all GNSS constellations

Getting TLE files:

See QUICK_WINS_STATUS.md for more details.

KML Trajectory Import

Create realistic flight paths using Google Earth:

  1. Open Google Earth
  2. Draw a path with "Add Path" tool
  3. Right-click → Save Place As → KML
  4. Use with simulator:
    python run_sim.py --kml my_flight_path.kml --duration 600

Features:

  • Cubic spline interpolation for smooth motion
  • Automatic velocity computation
  • Supports arbitrary waypoints
  • Compatible with Google Earth, QGIS, etc.

Example: data/trajectory/sf_flight.kml

Roadmap

See IMPLEMENTATION_STATUS.md for complete details on all features:

  • ✅ SGP4 orbit propagation
  • ✅ KML trajectory ingestion
  • ✅ 6DOF motion (acceleration + attitude)
  • ✅ Multipath model (5 environment presets)
  • ✅ Web GUI (Flask + Leaflet.js + Plotly.js)
  • ✅ Automated test suite (11 validation tests)

All quick wins complete! (6/6) 🎉

The simulator now rivals professional systems like CLAW GPS Simulator with production-grade features for research and SDR applications.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0