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.
On this pageA month of evenings and a few nights
Sleep is the one time your brain produces enormous, unmistakable EEGElectroencephalography (EEG) Recording the brain's electrical activity from electrodes on the scalp, a few tens of microvolts of blurred, summed cortical activity. Related: Electrocorticography (ECoG)Electrocorticography (ECoG) Recording from electrodes placed on the surface of the brain under the skull, usually during epilepsy surgery evaluation; cleaner and sharper than EEG. , Magnetoencephalography (MEG)Magnetoencephalography (MEG) Recording the tiny magnetic fields produced by cortical currents with superconducting sensors in a shielded room; less blurred by the skull than EEG, and far more expensive. , Volume conductionVolume conduction The spreading of currents from a source through the conductive tissues of the head, which is why one source shows up on many electrodes and why scalp EEG is blurry. , Microvolt (µV)Microvolt (µV) One millionth of a volt. Scalp EEG is tens of microvolts; a AA battery is 1.5 million of them. . Glossary entry: slow wavesSlow wave A large, slow (under 1 Hz) oscillation of deep sleep during which most cortical neurons fall silent and then fire together. Related: Delta wavesDelta waves Slow, large waves below about 4 Hz that dominate deep sleep., HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG.. Glossary entry of a hundred microvolts in deep sleep, spindlesSleep spindle A half-second burst of 11 to 16 Hz activity in light sleep, generated in the thalamus. Related: HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG., Thalamocortical loopThalamocortical loop The two-way circuit between the thalamus and the cortex whose rhythmic activity produces alpha, sleep spindles, and other EEG rhythms.. Glossary entry in light sleep, alpha as you drift off, rapid eye movements you can see from the forehead. A two-electrodeElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry band on the forehead records all of it. Train a stager on the public Sleep-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging. Related: HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG., PhysioNetPhysioNet A free archive of physiological recordings including EEG, ECG, and sleep data, run out of MIT.. Glossary entry dataset, and it will draw your hypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. Related: Polysomnography (PSG)Polysomnography (PSG) The overnight sleep study: EEG, EOG, chin EMG, breathing, oxygen, and heart rate recorded together and scored in 30-second epochs., Sleep-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging.. Glossary entry each morning. Then close the loop: detect slow wavesSlow wave A large, slow (under 1 Hz) oscillation of deep sleep during which most cortical neurons fall silent and then fire together. Related: Delta wavesDelta waves Slow, large waves below about 4 Hz that dominate deep sleep. , HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. . Glossary entry 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.
Which EEG feature most reliably separates deep sleep (N3) from everything else?
Delta power. Deep sleep is defined by slow wavesSlow wave A large, slow (under 1 Hz) oscillation of deep sleep during which most cortical neurons fall silent and then fire together. Related: Delta wavesDelta waves Slow, large waves below about 4 Hz that dominate deep sleep. , HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. . Glossary entry of at least 75 µV occupying more than a fifth of each thirty-second epochEpoch A fixed-length slice of the recording locked to an event, such as one second starting 200 milliseconds before each stimulus. Related: Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. , Baseline correctionBaseline correction Subtracting the mean of the pre-stimulus interval from each epoch so trials line up. . Glossary entry. 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 EEGElectroencephalography (EEG) Recording the brain's electrical activity from electrodes on the scalp, a few tens of microvolts of blurred, summed cortical activity. Related: Electrocorticography (ECoG)Electrocorticography (ECoG) Recording from electrodes placed on the surface of the brain under the skull, usually during epilepsy surgery evaluation; cleaner and sharper than EEG. , Magnetoencephalography (MEG)Magnetoencephalography (MEG) Recording the tiny magnetic fields produced by cortical currents with superconducting sensors in a shielded room; less blurred by the skull than EEG, and far more expensive. , Volume conductionVolume conduction The spreading of currents from a source through the conductive tissues of the head, which is why one source shows up on many electrodes and why scalp EEG is blurry. , Microvolt (µV)Microvolt (µV) One millionth of a volt. Scalp EEG is tens of microvolts; a AA battery is 1.5 million of them. . Glossary entry that looks like wake.
Beyond the amplifier
| Part | Where | Qty | Approx. |
|---|---|---|---|
| 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 store | 1 | $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. | Amazon | 1 | $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, SparkFun | 1 | $9 |
| Total (prices drift; treat as a ceiling) | $34 | ||
The band
Two channels. ElectrodeElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry at Fp1 or Fp2 referenced to an electrodeElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry behind the ear (the mastoid), plus the bias electrodeElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry on the forehead. Snap electrodesElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry with a little gel hold overnight better than cups. A soft fabric headband holds the board (or just the electrodesElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry, with a cable to a board on the nightstand running on a battery). Sample at 250 Hz. Sleep-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging. Related: HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. , PhysioNetPhysioNet A free archive of physiological recordings including EEG, ECG, and sleep data, run out of MIT. . Glossary entry’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 classifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. Related: Linear discriminant analysis (LDA)Linear discriminant analysis (LDA) A simple, robust classifier that draws a straight boundary between classes; the workhorse of EEG decoding for two decades. , Support vector machine (SVM)Support vector machine (SVM) A classifier that finds the boundary with the widest margin between classes; strong on small datasets. , Cross-validationCross-validation Testing a model on data it never saw during training, repeatedly, so the reported accuracy means something. . Glossary entry. For each 30-second epochEpoch A fixed-length slice of the recording locked to an event, such as one second starting 200 milliseconds before each stimulus. Related: Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. , Baseline correctionBaseline correction Subtracting the mean of the pre-stimulus interval from each epoch so trials line up. . Glossary entry 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-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging. Related: HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. , PhysioNetPhysioNet A free archive of physiological recordings including EEG, ECG, and sleep data, run out of MIT. . Glossary entry epochsEpoch A fixed-length slice of the recording locked to an event, such as one second starting 200 milliseconds before each stimulus. Related: Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. , Baseline correctionBaseline correction Subtracting the mean of the pre-stimulus interval from each epoch so trials line up. . Glossary entry 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 epochEpoch A fixed-length slice of the recording locked to an event, such as one second starting 200 milliseconds before each stimulus. Related: Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. , Baseline correctionBaseline correction Subtracting the mean of the pre-stimulus interval from each epoch so trials line up. . Glossary entry (the BraindecodeBraindecode A PyTorch library of deep-learning models for EEG, including EEGNet and ShallowConvNet, with dataset loaders. Related: EEGNetEEGNet A compact convolutional neural network for EEG, published in 2018, that became the standard deep-learning baseline because it is small enough to train on a laptop. , MOABBMOABB Mother of All BCI Benchmarks: a library that runs classifiers across many public EEG datasets the same way so results are comparable. . Glossary entry 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 epochEpoch A fixed-length slice of the recording locked to an event, such as one second starting 200 milliseconds before each stimulus. Related: Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. , Baseline correctionBaseline correction Subtracting the mean of the pre-stimulus interval from each epoch so trials line up. . Glossary entry, since epochsEpoch A fixed-length slice of the recording locked to an event, such as one second starting 200 milliseconds before each stimulus. Related: Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. , Baseline correctionBaseline correction Subtracting the mean of the pre-stimulus interval from each epoch so trials line up. . Glossary entry 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 hypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. Related: Polysomnography (PSG)Polysomnography (PSG) The overnight sleep study: EEG, EOG, chin EMG, breathing, oxygen, and heart rate recorded together and scored in 30-second epochs. , Sleep-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging. . Glossary entry, the spectrogramSpectrogram A spectrum computed over sliding windows and plotted against time, showing how frequency content changes. Related: Wavelet transformWavelet transform A time-frequency analysis that uses short wiggles at high frequencies and long ones at low, matching the trade-off to the frequency. , SpectrumSpectrum A plot of how much of a signal lives at each frequency. . Glossary entry, 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 memoryThe exact closed-loop click protocol the sleep band project reimplements, with effect sizes to compare against.) detects slow wavesSlow wave A large, slow (under 1 Hz) oscillation of deep sleep during which most cortical neurons fall silent and then fire together. Related: Delta wavesDelta waves Slow, large waves below about 4 Hz that dominate deep sleep. , HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. . Glossary entry 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, recallRecall A correction or removal of a marketed device; FDA's public database of them is a catalogue of how designs fail people. Glossary entry 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.
- Download two Sleep-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging. Related: HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. , PhysioNetPhysioNet A free archive of physiological recordings including EEG, ECG, and sleep data, run out of MIT. . Glossary entry recordings, load with MNEMNE-Python The standard open-source Python library for EEG and MEG analysis: filtering, epoching, ICA, topographies, source localization. Related: Independent component analysis (ICA)Independent component analysis (ICA) A method that unmixes multichannel data into statistically independent sources, so blinks and heartbeat can be identified and removed. . Glossary entry, plot the hypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. Related: Polysomnography (PSG)Polysomnography (PSG) The overnight sleep study: EEG, EOG, chin EMG, breathing, oxygen, and heart rate recorded together and scored in 30-second epochs. , Sleep-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging. . Glossary entry against the Fpz-Cz spectrogramSpectrogram A spectrum computed over sliding windows and plotted against time, showing how frequency content changes. Related: Wavelet transformWavelet transform A time-frequency analysis that uses short wiggles at high frequencies and long ones at low, matching the trade-off to the frequency. , SpectrumSpectrum A plot of how much of a signal lives at each frequency. . Glossary entry. Look at what each stage looks like.
- Build the feature-based stager. Cross-validate by recording. Report the confusion matrix.
- Build the band. Record one night with the stager off, just to see the raw data and check nothing fell off.
- Run the stager on your night. Compare the hypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. Related: Polysomnography (PSG)Polysomnography (PSG) The overnight sleep study: EEG, EOG, chin EMG, breathing, oxygen, and heart rate recorded together and scored in 30-second epochs. , Sleep-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging. . Glossary entry to your own sense of the night.
- Implement slow-wave detection offline on your recording. Tune the threshold so it fires on real slow wavesSlow wave A large, slow (under 1 Hz) oscillation of deep sleep during which most cortical neurons fall silent and then fire together. Related: Delta wavesDelta waves Slow, large waves below about 4 Hz that dominate deep sleep. , HypnogramHypnogram The staircase plot of sleep stage against time across a night, scored in 30-second epochs from EEG, EOG, and EMG. . Glossary entry and not on movement.
- Run it live with sham nights interleaved. Compare slow-wave amplitude in the second after real versus sham clicks. Plot it.