Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BCI-CPP-FRAMEWORK - Brain-Computer Interface Research Platform

🧠 Advanced Brain-Computer Interface Research Platform

BCI-CPP-Framework is a comprehensive, enterprise-grade research platform for Brain-Computer Interface (BCI) development. It combines real-time 3D neural visualization, advanced signal processing algorithms (Kalman Filter, CSP, t-test), and publication-ready graph generation in a single integrated environment.

"Real-time neural decoding with 3D visualization - From raw EEG to research publication"


⚠️ DISCLAIMER

This software is intended for research, educational, and development purposes only. It simulates neural signals and is not a medical device. The developers are not responsible for any misuse or damage caused by this program. Always ensure proper ethical guidelines and institutional approvals when conducting research involving human subjects.


🚀 Key Features

🧠 Real-time 3D Neural Visualization

  • 3D Brain Mesh: 128-node Fibonacci lattice topology with synaptic connections
  • Dynamic Neural Activity: Real-time pulsing nodes with color-coded activity
  • Interactive Camera: 360-degree orbit control with mouse drag
  • Synaptic Electricity Lines: Visual connections between neural nodes
  • Mode-based Coloring: Speech (Blue), Motor (Gold), Visual (Green)

🔬 Advanced Signal Processing

  • Kalman Filter: Real-time motor decoding with 9D state space (position, velocity, acceleration)
  • Common Spatial Pattern (CSP): Feature extraction for EEG signal classification
  • Realistic EEG Generation: Multi-band simulation (Alpha, Beta, Gamma, Theta, Delta)
  • fMRI BOLD Simulation: Hemodynamic response function modeling
  • Power Spectrum Analysis: Real-time frequency domain visualization

📊 Research-Grade Analytics

  • 10-Fold Cross-Validation: Robust model validation with mean accuracy & standard deviation
  • Statistical t-test: Significance testing with p-values and Cohen's d effect size
  • Ablation Studies: Component importance analysis
  • Confusion Matrix: 3-class classification performance
  • ROC Curve: Model performance with AUC score
  • Feature Importance Heatmap: CSP feature ranking
  • Spectrogram: Time-frequency analysis
  • EEG Topomap: 2D scalp potential distribution

🔒 Clinical Safety & Monitoring

  • IEC 60601-1 Compliance: Tissue temperature monitoring
  • Electrode Impedance Tracking: Real-time impedance monitoring
  • Seizure Detection: Emergency alert system with NDN routing
  • Hardware Health Monitoring: NPU load, battery, RSSI tracking

🌐 Quantum-Secured Networking

  • NDN (Named Data Networking): Quantum-secured packet routing (Kyber-1024)
  • PIT Table Management: Pending Interest Table monitoring
  • Content Store Cache: Cache hit ratio and bandwidth tracking

📈 Data Logging & Visualization

  • CSV Data Export: Real-time data logging with timestamps
  • 10 Publication-Ready Figures: Automated graph generation
  • Performance Trends: Temporal analysis of all metrics
  • Correlation Heatmap: Feature correlation analysis

🎯 Research Applications

  • Motor Decoding: Real-time limb movement prediction
  • Speech Restoration: Thought-to-text decoding
  • Visual Cortex Mapping: Phosphene grid reconstruction
  • Seizure Prediction: Anomaly detection in neural signals
  • Neuroplasticity Tracking: Adaptive learning rate monitoring

📦 Installation Guide

System Requirements

  • Windows 10/11, Linux, or macOS
  • C++17 Compiler (GCC/MinGW)
  • Python 3.8 or higher
  • Raylib Library

Quick Installation

# Clone the repository
git clone https://github.com/alihusnain404/bci-cpp-framework
cd bci-cpp-framework

# Ensure Raylib is in the correct directory
# The repository includes raylib/ folder with include/ and lib/

# Compile the C++ program (Windows)
g++ -std=c++17 main.cpp -Iraylib/include -Lraylib/lib -lraylib -lopengl32 -lgdi32 -lwinmm -o App.exe

# Compile the C++ program (Linux/macOS)
g++ -std=c++17 main.cpp -Iraylib/include -Lraylib/lib -lraylib -lGL -lm -lpthread -ldl -lrt -o App

# Install Python dependencies
pip install pandas numpy matplotlib seaborn scipy

🛠 Usage

Running the C++ Application

# Windows
App.exe

# Linux/macOS
./App

Controls

Key Function
1 Speech Decoding Mode
2 Motor Control Mode
3 Visual Cortex Mode
4 Reset Mode
S Seizure Alert Simulation
C Calibrate CSP
L Log Data to CSV
A Toggle Ablation Study View
V Toggle Advanced Visualizations
K System Reset
R Reset Camera
Mouse Drag 360° Orbit Camera

Generating Research Graphs

# After running the C++ program and generating CSV data
python graphs.py

📋 Output Sections

Left Panel: Neural Signal Acquisition

  • EEG Raw Signal: Real-time voltage waveform with seizure detection
  • fMRI BOLD Response: Hemodynamic response function
  • Power Spectral Density: 1-100Hz frequency spectrum
  • Kalman Filter Position: 3D decoded position [x, y, z]
  • Performance Metrics: Accuracy, NPU load, SNR, temperature

Right Panel: Controls & Visualizations

  • NDN Packets: Quantum-secured routing table
  • CSP Calibration: Feature extraction training
  • Safety Monitor: IEC 60601-1 compliance
  • Controls: All keyboard shortcuts
  • Research Parameters: Neuroplasticity, learning rate

Advanced Visualizations (Press V)

  • Confusion Matrix: 3-class classification results
  • ROC Curve: Model performance with AUC
  • Feature Importance: CSP feature ranking
  • Spectrogram: Time-frequency representation
  • EEG Topomap: 2D scalp potential distribution

📊 Generated Figures

Figure Description
Figure 1 EEG Waveform with Seizure Detection
Figure 2 Confusion Matrix - 3-Class Classification
Figure 3 ROC Curve with AUC
Figure 4 CSP Feature Importance Heatmap
Figure 5 Spectrogram - Time-Frequency Analysis
Figure 6 EEG Topomap - Scalp Potential Distribution
Figure 7 Performance Trends Over Time
Figure 8 Correlation Matrix of Neural Metrics
Figure 9 Ablation Study - Component Importance
Table 1 Performance Summary Statistics

🎯 Example Output

🧠 NEURAL SIGNAL ACQUISITION
Device: Neuralink N1 vFW-2.5.3-2026.03.15 | Implant: ACTIVE

EEG RAW SIGNAL (uV):    [━━━━━━━━━━━━━━━━] 42.3 µV
fMRI BOLD (HRF):        [━━━━━━━━━━━━━━━━] 0.23
Kalman Pos: [0.42, 0.18, 0.05] | Accuracy: 96.7%
NPU Load: 58.3% | SNR: 44.1 dB
Tissue Temp: 37.2°C ✅ | Plasticity: 1.0004 | Battery: 84.2%

MODE: SPEECH DECODING
Output: "I WOULD LIKE SOME WATER PLEASE"
Confidence: 94.2% | Latency: 0.42 ms

10-FOLD CROSS-VALIDATION:
Mean Acc: 88.5% | Std: 2.1%

t-test: t=4.82 | p=0.0003 ✅ | d=1.24

🔧 Advanced Configuration

Customizing Parameters

// Kalman Filter Parameters (main.cpp)
float dt = 0.016f;  // Time step (16ms for 60Hz)
// State transition matrix automatically configured

// CSP Parameters
CommonSpatialPattern csp(4);  // 4 spatial filters

// EEG Generation Parameters
alphaAmp = 15.0f;  // 8-13 Hz
betaAmp = 8.0f;    // 13-30 Hz
gammaAmp = 5.0f;   // 30-80 Hz
thetaAmp = 12.0f;  // 4-8 Hz
deltaAmp = 20.0f;  // 0.5-4 Hz

CSV Data Format

Timestamp,Mode,EEG_uV,fMRI_BOLD,NPU_Load,Tissue_Temp,Plasticity,Seizure,Battery,RSSI,Kalman_Acc,CSP_Acc
2024-01-15 10:30:45.123,2,12.34,0.023,42.5,37.1,1.000,0,87.0,-42.0,94.2,88.5

📁 Repository Structure

bci-cpp-framework/
├── main.cpp                    # Core C++ application
├── graphs.py                   # Python graph generator
├── App.exe                     # Pre-compiled executable (Windows)
├── raylib/                     # Raylib library
│   ├── include/               # Header files
│   └── lib/                   # Library files
├── graph_figures/             # Generated figures
│   ├── Figure1_EEG_Waveform_Enhanced.png
│   ├── Figure2_Confusion_Matrix.png
│   ├── Figure3_ROC_Curve.png
│   ├── Figure4_Feature_Importance.png
│   ├── Figure5_Spectrogram.png
│   ├── Figure6_EEG_Topomap.png
│   ├── Figure7_Performance_Trends.png
│   ├── Figure8_Correlation_Heatmap.png
│   ├── Figure9_Ablation_Study.png
│   └── Table1_Performance_Summary.png
├── research_data_*.csv        # Generated data logs
├── video/                     # Project demonstration video
│   └── demo.mp4
├── Icon/                      # Banner and icons
│   └── Banner.png
└── README.md                  # This file

📊 Detection Capabilities

Algorithms Implemented

  • Kalman Filter: 9D state estimation (position, velocity, acceleration)
  • Common Spatial Pattern (CSP): Multi-class feature extraction
  • Statistical Analysis: t-test, p-values, effect size
  • Cross-Validation: 10-fold robust validation
  • Ablation Studies: Component importance analysis

Visualization Capabilities

  • 3D Neural Mesh: 128-node Fibonacci lattice
  • Synaptic Connections: Distance-based interconnection
  • Real-time Waveforms: EEG, fMRI, power spectrum
  • Publication Figures: 10 high-quality research plots
  • Interactive Camera: 360-degree orbit control

🤝 Contributing

We welcome contributions! Please feel free to submit pull requests, report bugs, or suggest new features.

Areas for Contribution

  • New Algorithms: Add more neural decoding algorithms
  • Visualization Enhancements: Improve 3D rendering
  • Performance Optimization: Optimize signal processing
  • Documentation: Improve user guides and API docs
  • Testing: Add unit tests and validation

🐛 Troubleshooting

Common Issues

Compilation Error:

# Ensure Raylib is properly installed
# Check include and lib paths in the compile command
# Use the exact command from the Installation section

Raylib Not Found:

# Download Raylib from https://www.raylib.com/
# Extract to the raylib/ folder in the project root
# Structure should be: raylib/include/ and raylib/lib/

Python Dependencies:

# Install required packages
pip install pandas numpy matplotlib seaborn scipy

CSV Not Generating:

# Press 'L' key in the application to start logging
# CSV will be saved as research_data_[timestamp].csv

📄 License

This project is licensed under the PROPRIETARY LICENSE - STRICT PROTECTION - see the LICENSE file for details.


🙏 Acknowledgements

  • Raylib - For 3D visualization and graphics
  • Raylib Team - For the excellent game development library
  • Matplotlib - For publication-quality plotting
  • SciPy - For scientific computing
  • IEEE EMBS - For the research platform inspiration

📞 Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed description
  3. Provide error messages and system information
  4. Watch the demonstration video in the video/ folder


MADE WITH ❤️ BY AUTHOR ALI HUSNAIN

Advancing Brain-Computer Interface Research - From Signal to Insight

About

​Real-time C++17 Brain-Computer Interface (BCI) Engine featuring 3D Raylib Neural Mesh, 9-State Kalman Filtering, CSP Signal Processing, Post-Quantum Security (KYBER1024 over NDN), IEC 60601-1 Safety Constraints, and an Automated Python Analytics Pipeline for Publication-Grade IEEE Figures.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages