BioSync AI is a real-time system designed to combat the "Fragmented Attention" and "Dopamine Disparity" caused by modern social media algorithms. By utilizing heart rate variability (HRV) as a proxy for the Central Autonomic Network (CAN), the system detects cognitive states and uses generative music as a regulatory tool to guide users into an optimal "Flow State".
The core objective of this project is to answer: Can a real-time AI system use physiological biomarkers to detect and regulate a user's cognitive state?. Rather than treating music as static background noise, this system treats it as a dynamic, closed-loop biofeedback signal.
- Flow Theory: Based on Csikszentmihalyi’s definition of flow as a state of complete absorption in the present moment.
- Neurovisceral Integration: Based on Thayer and Lane’s model, where heart rate variability (HRV) reflects the functional integrity of the Central Autonomic Network (CAN).
- The Nine-Quadrant Model: The system classifies user states into categories such as Anxiety, Arousal, Flow, Control, Relaxation, Boredom, Apathy, and Worry.
The system extracts real-time physiological data through a wearable HRV sensor. Key features include:
- BPM (Beats Per Minute).
- RMSSD (Root Mean Square of Successive Differences).
- HR Delta (Heart Rate variability trends).
The system utilizes a Multidimensional Multiclass Support Vector Machine (SVM) to predict cognitive states.
- Kernel Trick: Projects biomarkers into higher-dimensional space to handle non-linear physiological data.
- Feature Scaling: Standardizes data to ensure the hyperplane is not biased toward dimensions with larger numerical ranges.
- Pre-training: The model is pre-trained on the WESAD dataset to establish baseline stress vs. relaxation boundaries.
- Personalization: Conducts fine-tuning by collecting user-specific data during tasks and labeling them via a Flow State Scale assessment.
Rather than simple rule-based mapping, the system uses a Reinforcement Learning (RL) framework.
- Modulation: Adjusts parameters such as tempo, rhythmic density, harmonic complexity, and spectral brightness.
- Reward Signal: The stabilization of HRV balance serves as the intrinsic reward, ensuring the user moves toward the Flow quadrant.
- Arduino Uno R3 (for real sensor input)
- Pulse Sensor (Analog, e.g., PulseSensor.com heartbeat sensor)
- USB cable for Arduino connection
- Python 3.10+
-
Wire the pulse sensor to Arduino:
SIGNALpin →A0(Analog pin 0)VCCpin →5VGNDpin →GND
-
Upload the Arduino sketch (save as
pulse_sensor.ino):const int PULSE_PIN = A0; void setup() { Serial.begin(9600); } void loop() { int val = analogRead(PULSE_PIN); Serial.println(val); // outputs 0-1023 delay(10); // ~100 Hz sampling }
-
Find the Arduino serial port:
- macOS:
/dev/cu.usbmodem1411(or similar in/dev/cu.*) - Linux:
/dev/ttyUSB0 - Windows:
COM3
- macOS:
This project requires Python 3.10 or 3.11 (recommended).
If you need to install or manage multiple Python versions:
# Install pyenv (macOS)
brew install pyenv
# Add to shell config (~/.zshrc or ~/.bashrc)
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
# Install Python 3.11
pyenv install 3.11.0
# Set local Python version for this project
pyenv local 3.11.0
# Verify
python --version-
Create and activate virtual environment:
# Create venv python -m venv venv # Activate (macOS/Linux) source venv/bin/activate # Activate (Windows) # venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt pip install pyserial # Required for Arduino communication
# Activate venv first (if not already activated)
source venv/bin/activate
# Simulated sensor mode (default - no hardware needed)
python biofeedback_system.py
# Arduino sensor mode (real hardware)
python biofeedback_system.py --sensor arduino
python biofeedback_system.py --sensor arduino --port /dev/cu.usbmodem1411Wire the pulse sensor to Arduino as described above. The system communicates directly with the Arduino over USB serial — no external ADC needed.
BioSyncAI/
├── biofeedback_system.py # Main system (supports simulated or Arduino sensor)
├── requirements.txt # Python dependencies
├── README.md # This file
├── .gitignore # Git ignore rules
└── pulse_sensor.ino # Arduino sketch for pulse sensor
numpy- Numerical computingscikit-learn- SVM implementationscipy- Signal processingpyserial- Arduino USB serial communication
- Edge Cases: The system includes personalized calibration to handle baseline distributions and avoid misclassifying pathological irregularities like arrhythmia.
- Deployment: The user's normalized physiological input is fed into the real-time trained SVM classifier to predict current cognitive states.
- Csikszentmihalyi, M. (1997). Finding flow: The psychology of engagement with everyday life.
- Thayer, J. F., & Lane, R. D. (2000). A model of neurovisceral integration in emotion regulation and dysregulation.
- Satani, A., et al. (2025). Modern day high: The neurocognitive impact of social media usage.