Inspiration

Mental health care has a data problem. Clinicians rely almost entirely on
self-reported symptoms - but by the time a patient articulates that they're
overwhelmed, burned out, or unable to focus, they've often been struggling for
months. We asked: what if a 2-second brainwave snapshot could quantify what a person can't put into words?

STRAIN (Stress and Affect Recognition via Neural Inference) was built to answer
that question.

What it does

STRAIN is a real-time EEG analysis platform that processes brainwave signals from a 14-channel EMOTIV EPOC+ headset to generate:

  • Affective state predictions - Valence, Arousal, and Dominance scores (1–5) load (β/α ratio), mapped to a 0–100 clinical scale
  • Explainability - top EEG signal contributions (band power, channel variance) driving each prediction
  • FHIR R4 export - structured clinical data bundles ready for EHR integration

The platform includes a full-stack web dashboard (React + Three.js 3D brain visualization), a FastAPI backend, and an MCP-connected AI agent on Prompt Opinion that can converse with patients, triage their symptoms, redirect them to a scan, and generate a full clinical report - complete with a downloadable Markdown file formatted for doctor consultation.

The demo narrative

Sam Rivera is a 26-year-old PhD student. She opens the STRAIN agent on Prompt Opinion and says she's overwhelmed - racing thoughts, can't focus, three deadlines she can't face. The agent empathises, explains that STRAIN can measure cognitive load directly from her brainwaves, and drops a link to the dashboard.

Sam runs a scan. Her results: Valence 1.0 / 5, Arousal 4.0 / 5, β/α ratio 57.6 (normal range: 1–3), cognitive load 100% - an extreme ADHD-stress overlap signature identified in the DREAMER dataset. She returns to the agent, asks for her analysis, and receives a full neural screening report with EEG electrode topography, VAD charts, risk indicators, and personalised next steps - including a recommendation for formal ADHD screening (Conners ACRS).

How we built it

Data pipeline: DREAMER.mat (Zenodo) → sliding-window export (256 samples, 50%
overlap, 128 Hz) → (14, 256) epoch tensors → Welch PSD feature extraction → subject-holdout Ridge regression (VAD).

Backend: FastAPI orchestrator with agent pipeline (DataCurator → AnalysisEngine → Explainer), FHIR R4 bundle generator, and a matplotlib EEG electrode topography renderer.

Frontend: React 19 + TypeScript, Three.js/react-three-fiber 3D brain with
animated dendrite lines and electrode markers, 9-second animated scan sequence.

AI integration: FastMCP server exposing strain-tools over SSE/Streamable
HTTP. Connected to Prompt Opinion BYO agent - the agent calls analyze_named_patient_tool, which runs the full pipeline and returns a rich
Markdown report with inline charts (QuickChart.io), brain scan image, and a downloadable report URL.

Interoperability: FHIR R4 Observation bundles for all screening outputs -
designed for real EHR integration.

## Challenges

  • EEG feature leakage: Getting subject-holdout cross-validation right so the
    model generalises across people, not just memorises one subject's baseline.
  • MCP + LLM hallucination: The Po agent repeatedly fabricated URLs and patient names until we locked the tool docstrings, removed example URLs, and added hard
    REQUIRED: directives in the system prompt.
  • Real-time feel from batch data: The 9-second scan animation needed to feel
    live while actually processing a pre-recorded DREAMER epoch - deterministic channel power seeding made it reproducible and convincing.
  • Clinical framing without overclaiming: Every output carries a disclaimer. The language is clinical but the system is explicitly not a medical device - threading that needle in the UI and agent responses took deliberate iteration.

What we learned

Brain-computer interfaces don't need to be invasive or expensive to be clinically
informative. A consumer-grade 14-channel headset, open research data, and a well-structured ML pipeline can produce explainable, FHIR-ready outputs that a
clinician could actually use as a conversation starter - not a diagnosis, but a signal worth discussing.

What's next

  • Swap Ridge regression for a subject-adaptive 4D-CRNN on the raw epoch tensors
  • Live EMOTIV SDK integration (replace DREAMER replay with real-time streaming)
  • Longitudinal tracking - compare scans over time to detect trend changes
  • Expand to DEAP and SEED-IV datasets for cross-dataset validation

Built With

Share this project:

Updates