↑↓ move↵ open[] previous / next lesson? all shortcuts
Appearance
Theme
Type size
Reading

Focus mode hides the sidebars. Press f to toggle it anywhere.

Keyboard shortcuts
/
Search
[ ]
Previous / next lesson
t
Jump to the table of contents
r
Review queue
f
Focus mode
?
This panel
ProjectA month of evenings and a few nightsAbout $35 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
On this pageA month of evenings and a few nights
  1. The band
  2. The stager
  3. Your own nights
  4. Closing the loop

Sleep is the one time your brain produces enormous, unmistakable : 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- 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 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 of at least 75 µV occupying more than a fifth of each thirty-second . 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 that looks like wake.

Beyond the amplifier

PartWhereQtyApprox.
9 V batteries, ×4, and snap connectors
$9.69 for four Energizer cells plus $3.59 for three snap connectors (Amazon B0CR8RKQ5Q). Two batteries give you a ±9 V split supply. Never power anything touching skin from the wall or from a laptop USB port.
Amazon, any store1$13
Disposable snap ECG electrodes, bag of 50
3M Red Dot, $11.40 for fifty. Clip the alligator leads onto the snap studs rather than buying leads; a set of four 3.5 mm snap leads is $9.99 if you want them tidy.
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.
Amazon, Adafruit, SparkFun1$9
Total (prices drift; treat as a ceiling)$34

The band

Two channels. at Fp1 or Fp2 referenced to an behind the ear (the mastoid), plus the bias on the forehead. Snap with a little gel hold overnight better than cups. A soft fabric headband holds the board (or just the , with a cable to a board on the nightstand running on a battery). Sample at 250 Hz. ’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

A real night, scored by hand
This interactive needs JavaScript. If you are reading a printout, the caption describes what it shows.
Figure 1. What a night looks like when a human scores it: one full night from the Sleep-EDF database, 30 s epochs, awake at the top and deep sleep at the bottom, REM shaded. Your stager is trying to reproduce this staircase from one or two channels.

Two routes. Features and a . For each 30-second 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 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 (the 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 , since 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 , the , 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. 2013Auditory closed-loop stimulation of the sleep slow oscillation enhances memoryNgo, Martinetz, Born, et al. · Neuron · 2013The exact closed-loop click protocol the sleep band project reimplements, with effect sizes to compare against.) detects 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, 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 recordings, load with , plot the against the Fpz-Cz . 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 to your own sense of the night.
  5. Implement slow-wave detection offline on your recording. Tune the threshold so it fires on real 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.