Case file
Automatic detection of sleep spindles on a single EEG channel, scored event by event against two human experts. It began as a team project in my M.Sc. and I reopened it in 2026. The detector turned out to be better than our report said. The evaluation code was wrong, not the detector.
Thesis
Sleep spindles are short bursts of 11 to 16 Hz activity in light sleep. They track memory consolidation and change with age, medication and several neurological conditions. Scoring them by hand is slow, and two trained experts disagree on a large share of events. An automatic detector is only useful if it is measured honestly against that disagreement. The two experts in this dataset agree at an event-level F1 of 0.65, so that is the ceiling, and 1.0 is not.
What we found
In 2023 the team built a Morlet wavelet detector and reported an F1 of 0.25. Rerunning the original code unchanged reproduces that number. The detector was not the problem. The evaluation had three faults. When counting missed spindles, it compared detection times in samples against expert times in seconds, so real hits counted as misses. Expert 1 only annotated the first 1000 of each 1800 seconds, but every detection after that counted as a false positive. And a train and test split was applied to a detector with no parameters to fit. Scored correctly, the same 2023 detector reaches 0.49.
Architecture
A single pipeline in four stages. A zero-phase 0.5 to 30 Hz band-pass. A complex Morlet wavelet at 13.5 Hz with 7 cycles, which gives a smoothed sigma envelope. A dual threshold: a core above a high threshold, extended while the envelope stays above a lower one. Finally, a relative sigma power gate, then merging and duration limits of 0.5 to 3 seconds. The metric matches detections to expert events one to one and only scores inside the window each expert actually annotated.
Engineering decisions
Median normalisation rather than min-max. Min-max scaling lets one movement artefact rescale an entire recording, and every threshold downstream moves with it. Dividing by the median makes the threshold mean "this many times the typical sigma power for this person", which holds across recordings.
7 cycles rather than 20. At 13 Hz, a 20-cycle wavelet smears energy over about 1.5 seconds, longer than most spindles. Shorter wavelets trade some frequency resolution for the time resolution the task needs.
Leave-one-recording-out rather than a random split. There are only eight recordings. Every tuned value is chosen on seven and scored on the eighth, so no recording is ever judged by parameters that saw it. The same thresholds won in six of eight folds, which shows the choice is stable rather than fitted to noise.
A learned stage that lost. I added a gradient-boosted classifier to re-score candidate events. It reached 0.63, below the 0.64 of two well-chosen thresholds. With eight recordings and about 350 labelled spindles, there is not enough data for a model to learn more than that. It stays in the repository as a negative result.
The chart
The results chart puts four numbers against one dashed line. The 2023 detector as reported (0.25). The same detector scored correctly (0.49). The reworked detector (0.64). The learned variant (0.63). The dashed line is expert 2 against expert 1 (0.65). Everything the project claims is in the distance between the bars and that line.
Data and licence
The DREAMS Sleep Spindles database: eight 30-minute excerpts of channel C3-A2, with expert annotations. It is licensed CC BY-NC-ND 3.0, so the EEG is not in the repository. The code, tests and results are, and the README explains where to get the data.
Build status
Done. The corrected event metric, with unit tests pinning each of the three 2023 faults. The original detector kept verbatim for comparison. The reworked detector. The leave-one-recording-out evaluation, which reproduces every number in the README from a clean checkout.
Limits. Eight recordings, about four hours of EEG, one channel, one database. Expert 1's labels cover only the first 1000 seconds of each recording, and expert 2 marked fixed one-second windows, so boundary precision cannot be evaluated. These results say nothing about other montages, patient groups or sleep disorders.
Credit
2023 team: Jeremia Kerstner (project owner), Samuel Henry Mba (scientific lead), Manuel Kalus (marketing lead), Robert Aigner (development lead), FH Technikum Wien. The 2023 detector and literature review were joint work. The 2026 evaluation fixes, reworked detector and validation are mine.