-
-
strokesignal: a stroke patient's attempt to move a hand, answered by a simulated arm rigged from 33 bones and muscles of real anatomy.
-
Inside the signal: electrodes sit over the motor areas, C3 and C4, and listen. The brain and headset are simulated.
-
The model reads real recorded C3 and C4 EEG from a stroke patient, picks the hand (here LEFT, over 99% sure), and the arm answers.
Inspiration
Every 40 seconds, someone in the US has a stroke, and almost 12 million new strokes happen worldwide every year. Many of those people end up in the same spot: they try to move a hand, the hand doesn't answer, and the brain never finds out that trying counted for anything. That silence is the hardest part of stroke rehab, so it's the part I decided to build against.
Brain-computer interface rehab improves recovery by answering every attempt. The problem is that almost nobody outside a clinic ever sees what that answer looks like, because it needs a headset, a trainer and a lot of money. I wanted anyone to see the whole loop in under a minute, in a browser, with nothing to install. That's why I built strokesignal, the first simulated BCI stroke rehab.
What it does
strokesignal reads a stroke patient's attempt to move a hand from their EEG, decides which hand they meant, and answers with an anatomically rigged arm. The tendons draw, the fingers close, and a stimulation pulse runs along the tendons.
The EEG is real. It's recorded data from three stroke patients (g.tec's stroke-rehab dataset), replayed trial by trial. The brain, the headset, the arm and the stimulation are simulated, so nothing on the page is live.
You can scroll through the idea or drive it yourself. First, pick any of six sessions from the three patients. Next, play the real recorded trials. Then flip between two rules: the therapy rule, where the arm answers only when the reading matches the cue, and real use, where the arm moves for whatever the model reads, so a wrong guess moves the wrong hand. A Voice cues switch speaks every cue out loud, which helps when someone can't watch the screen while they imagine a movement.
When the model is at least 90 percent sure, it's right 94 percent of the time (367 of 390 trials), on brain signals it never saw during training.
Live: https://strokesignal.health (judge version: https://strokesignal.health/judge.html) Code: https://github.com/CoderJT-Elite/strokesignal
How I built it
- Decoder. I band-pass the EEG from 8 to 30 Hz and keep the 3 to 6 second imagery window. Then I use common spatial patterns (CSP), 3 pairs of filters, and linear discriminant analysis. CSP finds the spatial filters (the vector w below) that make the variance of one hand's trials as large as possible while the other hand's stays small:
$$\mathbf{w}^* = \arg\max_{\mathbf{w}} \frac{\mathbf{w}^\top \Sigma_{L}\, \mathbf{w}}{\mathbf{w}^\top (\Sigma_{L} + \Sigma_{R})\, \mathbf{w}}$$
I solve it with an eigen decomposition of the covariance matrices, take the log-variance of each filtered trial as the features, and fit the classifier on each session's training run. Every score comes from that session's test run, which the model never saw.
- Evidence. A bare accuracy number hides how small the test sets are, so each session gets a 95 percent Wilson interval:
$$\frac{\hat{p} + \frac{z^2}{2n} \pm z\sqrt{\frac{\hat{p}(1-\hat{p})}{n} + \frac{z^2}{4n^2}}}{1 + \frac{z^2}{n}}$$
On top of that I run a 5,000-shuffle label permutation test, a calibration check (when the model is at least 90 percent sure, how often is it right), and a learning curve (accuracy against the number of calibration trials). Eight pytest checks fail if the page's trial data ever disagrees with the reported accuracies, the intervals, or the changes quoted on the page.
- Arm. I loaded 33 BodyParts3D meshes (radius, ulna, carpals, metacarpals, phalanges, flexor and extensor muscles) into three.js. The meshes come as loose parts with no joints, so I found each joint's pivot from the mesh ends, built a bone chain for every finger and the thumb, drew the tendons as tubes that follow the chain, and swelled the flexor muscle bellies in a vertex shader when they activate.
- Page. Plain HTML, CSS and JavaScript with no framework: chart paper for the EEG strip, one sticky arm, and one scripted moment where the arm answers.
- Services. The site and a small read-only API run on a Vultr server behind nginx with HTTPS. The evidence and session notes live in MongoDB Atlas and reach the page through that API, and the page shows which source the figures came from. Gemini wrote a two-sentence plain-language note per session, and a script rejects any note that contains a number that isn't in that session's figures. ElevenLabs generated the six spoken cues once, and they're served as static audio, so no key ever reaches the browser.
AI tools I used, and how
Claude Code (Anthropic) wrote most of the code under my direction: the decoder export, the evidence script, the rigged arm, the page, the server setup and the tests. I chose the project, set the direction and reviewed every result. Gemini wrote the session notes, and a script checked every one. ElevenLabs made the voice clips. The decoder's numbers come from the evidence script running on g.tec's recordings, not from any AI tool.
Results
Left versus right accuracy on test runs the model never saw (chance is 50 percent): P1 92.5 then 86.3, P2 81.2 then 98.8, P3 80.0 then 82.5. Every one of the six sessions is above chance with a label-shuffle p below 0.001. At 90 percent confidence or more, 367 of 390 trials were correct (94 percent).
Challenges
The first one was making an arm that looks like an arm. My first attempt, drawn from code, looked wrong, so I switched to scanned anatomy. That fixed how it looked and created a new problem: the meshes arrive as separate parts with no joints, so I had to find the pivots from the geometry and check each finger's curl against the real bone shapes.
The second was making a brain signal feel like something a person can see and understand in under a minute. A line chart of EEG means nothing to most people, which is why the arm is the interface and the chart only backs it up.
The third was plumbing. MongoDB Atlas only accepts connections from allow-listed IPs, and a blocked server shows a vague TLS "internal error" instead of saying the IP is the problem. It took a while to see that, because the message points at the wrong thing.
Accomplishments that I'm proud of
I built an end-to-end loop from a stroke patient's EEG to a moving, anatomical arm, with intervals, a permutation test and calibration behind it. The tests fail if the page and the pipeline disagree, so every number a judge reads on the page traces back to the evidence script. And the page works the way I wanted: the arm is the interface, and someone with no neuroscience background gets it in seconds.
What I learned
I learned how CSP features turn two channels' band power into a decision, and how to read a Wilson interval for an 80-trial test run, which is wide enough that a single accuracy number would have oversold it. I also learned how to rig loose anatomical meshes into a hand that closes believably, and that a vague error message (the Atlas TLS one) can send you debugging the wrong layer.
What's next for strokesignal
First, I want to put it in front of someone who does stroke rehab every day and ask whether the answer should be feedback on screen, stimulation, or both. After that, the plan is more patients and sessions, a live decode on a full cap, and a real stimulation or exoskeleton output under clinical supervision.
Anatomy: BodyParts3D, (c) The Database Center for Life Science, licensed under CC Attribution-Share Alike 2.1 Japan (Mitsuhashi et al., Nucleic Acids Research, 2009).
Built With
- css
- elevenlabs
- gemini
- html
- javascript
- mongodb-atlas
- nginx
- numpy
- pytest
- python
- scikit-learn
- scipy
- three.js
- vultr