Polysomnography (PSG) measures brain activity during sleep via electroencephalography (EEG) using six leads. Artifacts caused by movement or loose leads distort EEG measurements. We developed a method to automatically identify such artifacts in a PSG EEG trace. After preprocessing, we extracted power levels at frequencies of 0.5–32.5 Hz with multitaper spectral analysis using 4 s windows with 3 s overlap. For each resulting 1 s segment, we computed segment-specific correlations between power levels for all pairs of leads. We then averaged all pairwise correlation coefficients involving each lead, creating a time series of segment-specific average correlations for each lead. Our algorithm scans each averaged time series separately for “bad” segments using a local moving window. In a second pass, any segment whose averaged correlation is less than a global threshold among all remaining good segments is declared an outlier. We mark all segments between two outlier segments fewer than 300 s apart as artifact regions. This process is repeated, removing a channel with excessive outliers in each iteration. We compared artifact regions discovered by our algorithm to expert-assessed ground truth, achieving sensitivity and specificity of 80% and 91%, respectively. Our algorithm is an open-source tool, either as a Python package or a Docker.
Read full abstract