← Writeups

Writeup

Biosignal Recording Rig

The design for one home rig that records brain, eye and muscle signals: overnight recordings to stage my own sleep, and surface EMG to compare how hard muscles work across lifting variations. One amplifier, one housing, one archive.

openbci cytonads1299touch-proof electrodesmqtt3d printing

The body produces small electrical signals that can be recorded from the skin. The brain's show up as EEG, the eyes' as EOG and the muscles' as EMG. This rig records all three at home, for two uses:

  • Sleep. Overnight recordings good enough to stage my own sleep the way a sleep lab does.
  • Lifting. Surface EMG on the working muscles, to compare how hard each one works across exercises and across variations of the same exercise.

The amplifier is an OpenBCI Cyton, an 8-channel board, from a headset kit I already own. The design puts it in a housing made for medical electrode leads, so one board serves both uses.

One rig, several signals

EEG, EOG and EMG differ in size and frequency. EEG is tens of microvolts; surface EMG can reach a few millivolts. All three are still voltages between electrodes on the skin, and the chip on the Cyton, TI's ADS1299, is built to measure that whole range. What changes from one use to the next is where the electrodes go and how each channel is referenced.

SignalElectrodesUsed forReferencing
EEGScalp: frontal, central and occipitalSleep stagingEach against a reference behind the opposite ear
EOGBeside each eyeThe eye movements of REM sleepAgainst a reference
Chin EMGA pair under the chinThe muscle relaxation of REM sleepBipolar: one pair per channel
Limb EMGA pair over each muscleLiftingBipolar: one pair per channel

So the hardware, the capture software and the storage get built once and reused. A sleep night and a lifting session differ only in which leads are plugged in and how the channels are configured.

What sleep staging needs

The American Academy of Sleep Medicine's recommended signals for staging sleep come to six channels:

  • three EEG channels (frontal, central, occipital);
  • two EOG channels, one beside each eye;
  • one chin EMG channel.

A scorer splits the night into 30-second epochs and labels each one wake, N1, N2, N3 or REM. The Cyton's eight channels cover that montage with two to spare.

The housing

The rig is built around a design by Robert Oostenveld, published on the EEGsynth blog in 2019: a touch-proof enclosure for OpenBCI. It's a 3D-printed box, 100 × 100 × 30 mm, holding:

  • the board;
  • a LiPo battery with its own USB charger and protection board;
  • a latching power switch and a status LED;
  • a panel of touch-proof sockets (DIN 42802), the shrouded connector medical electrodes use.

He built it to record EEG, EMG and ECG with one rig, which is this project's problem with EOG in place of ECG. Three things make it the right starting point:

  • Leads, not rewiring. Switching from a sleep montage to lifting means swapping leads. Cup electrodes for EEG and snap electrodes for EMG both come with touch-proof plugs, so the box takes off-the-shelf leads.
  • The battery stays inside. It charges over USB rather than through the board's battery connector, which he found wears out from repeated plugging.
  • Paste electrodes, not dry ones. Cup electrodes with conductive paste give a better signal than the dry electrodes on OpenBCI's headset, which matters over an eight-hour recording.

The build changes three things:

  1. Bipolar sockets. His panel shares one reference across every channel, which suits EEG but not EMG. The remix exposes each channel's own negative input on at least two channels, for chin EMG and lifting, which takes 12 sockets instead of 10.
  2. A battery sized for a full night. The article gives no runtime, so the cell is sized from the board's measured current draw: the original 850 mAh if it lasts nine hours, a larger cell if it doesn't.
  3. USB-C charging, in place of the 2019 micro-USB charger board.

Safety: nothing is wired to the board

warn

Running on battery is what keeps the person wearing the electrodes isolated from mains power. While leads are on, the board has no wired connection to anything: data leaves it by radio or on its memory card, and it charges only with every lead unplugged.

The charging rule comes from Oostenveld's reply to a reader who asked whether the board could charge while recording. He advised against it: a faulty charger could put mains voltage onto the board and onto the person. The same reasoning rules out a USB cable from the board to any powered device while it's worn, and that shapes how data gets off it.

This is a measurement project for my own curiosity, not a medical device, and nothing it records is a diagnosis.

Getting data off the board

There are two routes, and neither puts a wire on the board.

  • Live, over MQTT. The Cyton's radio sends samples to OpenBCI's USB receiver, plugged into a small always-on computer nearby. That computer publishes them to the MQTT broker that the homelab's microcontrollers already report to, and a subscriber there writes each recording to the archive. The only USB cable runs between the receiver and that computer.
  • On the card. The Cyton can also log to its own microSD card, at about a megabyte a minute for eight channels at the default 250 samples a second, or roughly half a gigabyte a night. The card is copied off and uploaded in bulk afterwards. It has the fewest moving parts, and a dropped radio link can't cost a night.

A phone over Bluetooth is deliberately not one of them. It adds pairing, an app the phone's operating system can suspend overnight, and another battery to the things that can end a recording early, and it offers nothing the other two don't.

Once a recording reaches the homelab, three rules apply:

  • Raw recordings never go into git, and don't stay on a laptop.
  • Raw streams stay as files. Only derived summaries, such as a hypnogram for each night or activation per set, become rows in a database.
  • Other projects read summaries, never raw samples. The sleep and training projects that use the results get the summary they need, not the recording.

The plan

  1. Housing. Remix the socket panel, print the box, and fit the board, battery, charger, switch, LED and sockets. Electrodes are cup electrodes with paste for EEG and EOG, and snap electrodes with pads for EMG. Done when the box is assembled with its panel wired to the board.

  2. Bench tests, a few minutes each:

    • inputs shorted together, to measure the noise floor;
    • eyes-closed alpha rhythm over the back of the head;
    • eye movements on the EOG channels;
    • a jaw clench on the chin EMG pair.

    Done when each signal is visible where it should be.

  3. The data path. The MQTT stream and the card, each tried on a bench recording. Done when a recording reaches the archive by both routes.

  4. A nap, then a night. One nap with the full montage, then the first overnight recording. Done when a full night is archived and opens cleanly.

  5. Score the sleep. Run an open-source automatic sleep stager on the recordings, and check it against my own scoring of a few nights. Done when each night has a hypnogram I trust.

  6. Lifting sessions. Bipolar pairs on the working muscles, recorded per set. Done when two variations of one lift can be compared side by side.