Sleep is far more than a passive state of rest. Every night, the brain and the cardiovascular system engage in a tightly choreographed dialogue, with cortical rhythms rising and falling in step with the beat of the heart. Researchers have long known that disruptions to this brain–heart conversation are hallmarks of conditions such as obstructive sleep apnea and depression, but studying the two systems together has remained surprisingly cumbersome. Now, a team of biomedical engineers has built an open-source software framework that, for the first time in a single automated workflow, aligns the brain’s micro-arousal patterns with the heart’s autonomic fingerprints, potentially accelerating the search for biomarkers of disordered sleep.
The new framework, described in Frontiers in Physiology by Shaween Shukir, Mostafa Moussa, Yahya AlZaabi, Ahsan Khandoker, and Zbigniew R. Struzik of Khalifa University in Abu Dhabi and the University of Tokyo, tackles a stubborn technical bottleneck. Sleep scientists routinely score the cyclic alternating pattern, or CAP, a well-established electroencephalographic marker of arousal instability in non-REM sleep, using one set of tools. Meanwhile, heart rate variability, or HRV, a non-invasive window into the balance between the sympathetic and parasympathetic nervous systems, is typically quantified in entirely different software. Because the two analyses rarely share a common time base, researchers who want to ask how a burst of cortical activity shapes cardiac regulation within the same seconds of the night must stitch results together by hand, a process that is slow, error-prone, and difficult to reproduce across laboratories.
The pipeline, written in MATLAB, is organized as five sequential modules: data ingestion, signal preprocessing, CAP event detection, HRV feature extraction, and multimodal synchronization. On the electroencephalography side, the framework applies a 50-hertz notch filter to remove power-line interference, followed by a fourth-order Butterworth bandpass filter spanning the delta, theta, alpha, and beta bands, and then a narrow delta-band filter to isolate the slow-wave activity characteristic of stage III sleep. The CAP detection module implements the published Terzano scoring criteria as explicit rules: candidate A1 events, the high-amplitude delta bursts that mark the activation phases of the cyclic alternating pattern, must last between one and sixty seconds, and their peak delta-band envelope must exceed the mean background delta amplitude of the surrounding epoch by at least a factor of 1.33. Only events occurring within polysomnographically confirmed slow-wave sleep are accepted.
On the cardiac side, the framework processes the electrocardiogram with the classic Pan–Tompkins algorithm, a deterministic threshold-based method for detecting the R-peaks that mark each heartbeat. From the intervals between consecutive R-peaks, the pipeline computes twenty-two HRV features spanning time-domain measures such as SDNN and RMSSD, frequency-domain indices derived by Lomb–Scargle spectral analysis including LF, HF, and the LF/HF ratio, and nonlinear metrics such as Poincaré plot descriptors, detrended fluctuation analysis exponents, and sample entropy. Crucially, the authors did not reimplement any of these calculations. Instead, the pipeline calls the open-source PhysioZoo/mhrv toolbox directly, so every extracted feature inherits that toolbox’s validated definitions, a design choice that sidesteps a common source of discrepancy between studies.
The synchronization logic is the heart of the contribution. Because sleep staging is conventionally performed on thirty-second epochs while stable HRV estimation requires windows of at least five minutes, the framework divides NREM sleep into consecutive five-minute segments, each spanning ten staged epochs, and admits an epoch only if it lies within a contiguous NREM segment. A five-minute epoch is labeled as CAP if it contains at least one qualifying A1 event, and the corresponding ECG segment, downsampled to share a common 100-hertz time base with the EEG, is then processed to yield one complete HRV feature vector per epoch. The output is a single synchronized table in which every row pairs a CAP label with a full autonomic profile, ready for downstream analysis.
The authors are candid about what this epoch-level labeling does and does not capture. A CAP A1 event lasts between one and sixty seconds, so a single event may occupy as little as a fraction of one percent of a five-minute window. The measured HRV therefore reflects the entire epoch, both the arousal-associated and the inter-arousal intervals, rather than the instantaneous autonomic response to an individual A-phase. The synchronization module exposes event-level timing hooks so that future users can perform event-locked analyses at finer temporal resolution, an approach pioneered by Ferri and colleagues, who characterized autonomic activation during CAP A-phases at second-level precision. Quantifying per-epoch A1 occupancy and testing whether autonomic differences scale with within-epoch CAP density are identified as the natural first analyses on that path.
Speed is another selling point. On a standard Windows workstation with an Intel Core i7 processor and 16 gigabytes of RAM, the pipeline processes one five-minute epoch in roughly twelve seconds, corresponding to eight to ten minutes for a full overnight recording. Manual CAP scoring combined with separate HRV extraction typically demands twenty to thirty minutes per subject. The pipeline is also deterministic by construction: the filters are linear time-invariant operations, the R-peak detector is threshold-based, and the spectral and nonlinear routines involve no random initialization, so repeated runs on identical inputs produce numerically identical outputs at floating-point precision.
To demonstrate the framework, the team applied it to polysomnographic recordings from forty-four patients recruited at the American Center for Psychiatry and Neurology in Abu Dhabi under institutional review board approval. Twenty-six patients had confirmed obstructive sleep apnea without comorbid depression, while eighteen patients, the OSAD+ subgroup, had OSA with clinically significant depressive symptoms defined by a PHQ-9 score of at least ten, a screening-level threshold rather than a structured-interview diagnosis. The worked example on the OSAD+ subgroup produced complete, well-structured feature vectors for every retained epoch, with values falling in physiologically plausible ranges. The authors deliberately refrain from interpreting the descriptive differences between CAP and non-CAP epochs in this subgroup as physiological findings, since no inferential statistics were applied and the epoch-level labeling means any difference reflects epoch context rather than event-locked autonomic response.
As a healthy reference point, the pipeline was also run on the publicly available CAP Sleep Database from the Sleep Disorders Center of the Ospedale Maggiore in Parma, Italy. Fifteen healthy controls with ECG recordings yielded 785 of 810 expert-annotated A1 epochs passing quality control, a retention rate of 96.9 percent that substantially exceeds the roughly 50 percent epoch retention observed in the patient recordings, consistent with the cleaner signals of healthy volunteers. The control values, including a mean heart rate of about 65 to 67 beats per minute, high vagally mediated variability, and a sympathovagal balance below unity, are offered strictly as a descriptive cross-database reference. Because the control cohort differs from the patients in database, site, acquisition system, and age, no statistical comparison between the groups is performed, and the authors emphasize that a matched, single-site control arm remains necessary before any control-referenced claim can be made.
The framework’s limitations are stated with unusual transparency. The CAP detection module is a rule-based implementation of published criteria that has not yet been benchmarked against expert manual scoring, since no manually scored CAP labels were available in the patient dataset; reporting sensitivity, specificity, F1, and Cohen’s kappa against the expert annotations of the CAP Sleep Database on PhysioNet is identified as the immediate next step. The current implementation detects only A1 subtypes during slow-wave sleep, omitting the A2 and A3 subtypes and stage 2 CAP that are clinically relevant, particularly in OSA where A3 events predominate. The MATLAB dependency limits accessibility, all patients come from a single institution, and the pipeline operates offline only. Planned extensions include a Python port to remove the licensing barrier, cloud-based deployment, an event-locked synchronization mode, and robustness testing across operating systems and MATLAB versions. For now, the complete code is released under a CC-BY 4.0 license on GitHub with a versioned archive on Zenodo, lowering the engineering barrier for laboratories worldwide to probe how the sleeping brain and the beating heart speak to each other, and what falls silent when sleep goes wrong.
Subject of Research: An open-source EEG–ECG software framework for synchronized CAP and heart rate variability analysis in sleep research
Article Title: An automated EEG–ECG framework for CAP–HRV analysis: enabling brain–heart coupling studies in sleep disorders
Article References: Shukir, S., Moussa, M., AlZaabi, Y., Khandoker, A., & Struzik, Z. R. (2026). An automated EEG–ECG framework for CAP–HRV analysis: enabling brain–heart coupling studies in sleep disorders. Frontiers in Physiology, 17, Article 1864664. https://doi.org/10.3389/fphys.2026.1864664
Image Credits: AI Generated
DOI: 10.3389/fphys.2026.1864664
Keywords: cyclic alternating pattern, heart rate variability, electroencephalography, electrocardiography, obstructive sleep apnea, depression, sleep microstructure, autonomic nervous system, slow-wave sleep, open-source software, brain–heart coupling, polysomnography
Cite Scienmag News
Cassandra Pierce. (October 16, 2026). New Open-Source Tool Synchronizes Brain and Heart Signals to Decode Sleep Disorders. Scienmag. https://scienmag.com/new-open-source-tool-synchronizes-brain-and-heart-signals-to-decode-sleep-disorders/
Cassandra Pierce. "New Open-Source Tool Synchronizes Brain and Heart Signals to Decode Sleep Disorders." Scienmag, 16 October 2026, https://scienmag.com/new-open-source-tool-synchronizes-brain-and-heart-signals-to-decode-sleep-disorders/. Accessed 16 October 2026.
Cassandra Pierce. "New Open-Source Tool Synchronizes Brain and Heart Signals to Decode Sleep Disorders." Scienmag. October 16, 2026. https://scienmag.com/new-open-source-tool-synchronizes-brain-and-heart-signals-to-decode-sleep-disorders/

