Bench modeSteps, parts, and safety only. Big type for a phone at the bench.
Phase 3: Read intentProjectA month of evenings and a few nightsAbout $30 beyond the amplifierTier 2

Project E: The sleep band

Two forehead electrodes, an automatic sleep stager trained on public data, and then pink-noise pulses timed to slow waves, which has published effects on memory. A freshman who builds a closed-loop sleep device has a story no one else has.

AssumesProject A: The ADS1299 boardClassification done honestlySpineAnalog / mixed-signal hardwareDecoding / signal processing / ML

You are skimming: the title, the first figure, and the short version. Switch to Read in the header for the full page, or Deep to open every deep dive.

Sleep is the one time your brain produces enormous, unmistakable EEG: of a hundred microvolts in deep sleep, in light sleep, alpha as you drift off, rapid eye movements you can see from the forehead. A two-electrode band on the forehead records all of it. Train a stager on the public dataset, and it will draw your each morning. Then close the loop: detect slow waves as they happen and play a soft click on their rising phase, which in published studies makes them larger and improves next-day memory. Everything about this project is unusual for an undergraduate, and every piece of it is within reach.

Predict before you look

Which EEG feature most reliably separates deep sleep (N3) from everything else?

Delta power. Deep sleep is defined by slow waves of at least 75 µV occupying more than a fifth of each thirty-second epoch. It is the easiest stage to detect and the one the closed-loop stimulation targets. Spindles mark stage N2, alpha marks wake, and REM is recognized by eye movements with a low-amplitude EEG that looks like wake.

Beyond the amplifier

PartWhereQtyApprox.
9 V batteries and snap connectors, ×4
Two batteries give you a ±9 V split supply. Never power anything touching skin from the wall or from a laptop USB port.
Any store1$10
Disposable snap ECG electrodes, pack of 50, and snap leads
For EMG and as a quick ground/reference. Snap leads with alligator or 3.5 mm ends.
Amazon1$12
ESP32 DevKit (or Raspberry Pi Pico)
For streaming from the ADS1299 board over USB later. Either board works; pick one ecosystem and learn it.
Adafruit, SparkFun, Amazon1$8
Total (prices drift; treat as a ceiling)$30

The band

Two channels. Electrode at Fp1 or Fp2 referenced to an electrode behind the ear (the mastoid), plus the bias electrode on the forehead. Snap electrodes with a little gel hold overnight better than cups. A soft fabric headband holds the board (or just the electrodes, with a cable to a board on the nightstand running on a battery). Sample at 250 Hz. Sleep-EDF’s channels are Fpz-Cz and Pz-Oz; forehead-to-mastoid is close enough to Fpz-Cz that a model trained on one transfers reasonably to the other, and you will measure how well.

The stager

Two routes. Features and a classifier. For each 30-second epoch compute band powers (delta, theta, alpha, sigma for spindles, beta), the ratio of slow to fast, an EOG-like slow-movement measure from the same frontal channel, and a few others. Train a random forest on Sleep-EDF epochs against the expert labels. Expect around 75 to 80 percent agreement with the expert on held-out recordings, which is close to what two experts achieve with each other. A small convolutional network on the raw epoch (the Braindecode or YASA route) reaches the mid-80s. Start with features so you can see what matters.

Evaluate by held-out recording, never by held-out epoch, since epochs within a night are correlated. Report the confusion matrix; N1 will be terrible for you as it is for everyone.

Your own nights

Record five nights. Run the stager each morning. Plot the hypnogram, the spectrogram, and the delta power over the night. You will see your own sleep cycles, about ninety minutes each, with deep sleep front-loaded into the first half of the night and REM growing toward morning. Compare to what a phone app says and notice how different they are.

Closing the loop

The published protocol (Ngo et al. 2013) detects slow waves in real time and plays two 50-millisecond pink-noise clicks timed to the up-state of the wave. Detection: band-pass 0.5 to 4 Hz, wait for a negative peak below a threshold (say −80 µV), predict the next up-state from the wave’s period (about half a second later), play the click, and pause for a couple of seconds. Randomize which nights stimulate and which merely mark where they would have stimulated (a sham), so you can compare slow-wave amplitude after real versus sham clicks. Keep a simple memory test (word pairs before bed, recall in the morning) if you want to see whether the effect reaches behaviour in one person, with the caveat that one person is an anecdote.

  1. Download two Sleep-EDF recordings, load with MNE, plot the hypnogram against the Fpz-Cz spectrogram. Look at what each stage looks like.
  2. Build the feature-based stager. Cross-validate by recording. Report the confusion matrix.
  3. Build the band. Record one night with the stager off, just to see the raw data and check nothing fell off.
  4. Run the stager on your night. Compare the hypnogram to your own sense of the night.
  5. Implement slow-wave detection offline on your recording. Tune the threshold so it fires on real slow waves and not on movement.
  6. Run it live with sham nights interleaved. Compare slow-wave amplitude in the second after real versus sham clicks. Plot it.
Recall
Why must a sleep stager be validated by held-out recording rather than held-out epoch?
Epochs within one night are strongly correlated; holding out random epochs leaks the night's characteristics into training and inflates accuracy. Held-out recordings test generalization to a new night or person.
Recall
What does closed-loop slow-wave stimulation do, and what makes the test of it honest?
It plays brief soft clicks timed to the up-phase of detected slow waves, which published work shows enlarges them and aids memory. Honest testing interleaves sham nights where detections are logged but no sound is played, and compares subsequent waves.