Abstract Introduction Closed-loop neuromodulation based on streaming EEG requires real-time algorithms to continuously run as new data samples are collected, and the system must react with millisecond precision to time stimulation with detected features. To address this, we developed a comprehensive real-time EEG signal processing pipeline consisting of automated on-line artifact rejection, sleep staging, and slow-wave and spindle detection, along with control logic for triggering external neuromodulation systems. Methods We used the STAGES dataset (1,687 polysomnograms) to develop our algorithms. We manually labeled artifact containing sleep epochs to develop a threshold-based approach to rejection. We then defined a set of parameters to identify slow waves and spindles as they occur in real-time, along with opportunities for personalized models. An XGBoost machine learning (ML) model was used to implement automated sleep staging capable of running in a real-time manner. Lastly, we developed a predictive model of the upcoming (future) sleep stage of the next epoch of EEG data. Results The artifact rejection threshold value can be adjusted to be less or more restrictive on data quality used for analysis. For example, one can reject more data by reducing the threshold to lower values, which flags more epochs as contaminated by noise and provides a cleaner (but reduced) dataset. The sleep stage model analyzes 10 seconds of EEG data then predicts the future 10 second epoch and runs again 10 seconds later. EEG feature calculations take 5 ms to run. Our algorithms can detect 81.4 % of slow waves prior to the negative peak (270-degress, mean = 246.2 degrees). A second real-time slow wave and spindle detection model relies on obtaining a minimum of 1-night’s sleep recording for individualized neuromodulation. Conclusion We combined these algorithms (artifact rejection, sleep staging, and slow-wave and spindle detection) into a closed-loop workflow that allows one to time neurostimulation at any point and define timeout periods for safety. The approach was validated using a separately developed custom software application to visualize pre-recorded EEG data as if it were being actively recorded. All code is written in Python to accommodate further modification and enhancements. Support (if any)
Good et al. (Fri,) studied this question.