This repository contains Python code for a real-time closed-loop Brain-Computer Interface (BCI) experiment investigating the "point of no return" in sensorimotor decision-making. The experiment implements a Random Dot Motion (RDM) task with evidence termination paradigm to test the double integration framework in motor control.
The experiment aims to determine:
- When a motor action becomes irreversible after initial motor preparation begins
- The minimum time required for an EMG burst to trigger a completed action
- Whether changing perceptual evidence after EMG onset can affect action completion
- Real-time EMG monitoring with <10ms latency for onset detection
- Continuous Random Dot Motion stimulus presentation to avoid visual evoked potentials
- Closed-loop paradigm where visual evidence terminates based on EMG activity
- Precise timing control with hardware-accelerated PsychoPy implementation
- Lab Streaming Layer (LSL) integration for EMG-PsychoPy communication
- Adaptive delay mechanisms (10, 20, 30ms increments) between EMG onset and evidence termination
- High-refresh monitor (60Hz minimum, 120Hz recommended)
- EMG recording system with real-time processing (1000Hz+ sampling)
- EEG system (optional, for offline analysis)
- Response buttons/keypads
- Lab Streaming Layer (LSL) compatible setup
- Dot Motion: 16.7 dots/degree², 2-3 pixel dots, 5°/s speed, 50ms lifetime
- Coherence Levels: 50% (high) and 0% (termination)
- Aperture: 7.1° diameter circular field
- Fixation: Continuous 5×5 pixel white square (0.5° visual angle)
- Frame Rate: 60fps minimum
- ITI: Randomly varied (3, 6, 9 seconds)
- High Coherence Phase: Up to 1.5 seconds
- Evidence Termination: Triggered by EMG onset + variable delay (Δt)
- Confidence Rating: 1-7 scale (post-response)
# Clone the repository
git clone https://github.com/yourusername/emg-eeg-bci-experiment.git
cd emg-eeg-bci-experiment
# Install Python dependencies
pip install -r requirements.txt
# Required packages include:
# - psychopy>=2023.1.0
# - numpy>=1.21.0
# - pylsl>=1.16.0
# - scipy>=1.8.0
# - matplotlib>=3.5.0# Test EMG connection
python src/emg_interface.py --test
# Calibrate timing precision
python tests/timing_validation.py
# Run practice session
python src/main_experiment.py --participant P001 --practiceThe experiment generates several data files:
- Behavioral data: Response times, accuracy, confidence ratings
- EMG data: Onset times, burst characteristics, response completion
- Stimulus timing: Coherence change timestamps, frame timing validation
- Trial metadata: Condition parameters, trial outcomes
- High-pass filtering (10Hz cutoff) with full-wave rectification
- Threshold detection (2-3 SD above baseline)
- Maximum 10ms latency from onset to PsychoPy trigger
- Hardware-accelerated stimulus presentation
- Frame drop monitoring and trial exclusion
- Photodiode validation for critical timing events
- Seamless coherence transitions (50% → 0%) without VEPs
- Variable EMG-to-termination delays (Δt: 10, 20, 30ms)
- Continuous fixation maintenance throughout trials
- 10-12 blocks of 60-80 trials each
- Counterbalanced motion directions (left/right)
- Systematic variation of EMG-coherence delays across blocks
- Adaptive procedures to focus on individual "point of no return"
- Fork the repository
- Create a feature branch (
git checkout -b feature/emg-optimization) - Test timing accuracy with provided validation tools
- Commit changes with detailed descriptions
- Submit pull request with performance metrics
[Hamed Ghane] - [[email protected]] Project Link: https://github.com/HamedGhanes/Emg-EEG-BCI Project Lab: https://mphiliastides.org/
- Lab Streaming Layer (LSL) community for real-time data streaming
- PsychoPy development team for precise stimulus control