An automated EEG–ECG framework for CAP–HRV analysis: enabling brain–heart coupling studies in sleep disorders
The 8 matches · 2 of them tie a paragraph to a whole file without given lines: weak matches, whose lines are not tinted
- [1] § Materials and methods › ECG preprocessing and HRV feature extraction ↔ worked_example.m, lines 1 to 72 · score 0.81 · SampEn, mhrv toolbox directly, PhysioZoo, RMSSD, AVNN, HF · Report a mismatch
- [2] § Materials and methods › Control reference cohort and A1-event HRV ↔ validate_CAP_A1.m, lines 1 to 100 · score 0.78 · CAP Sleep Database, expert annotated, CAP A1 events, n16, capslpdb, channel · Report a mismatch
- [3] § Materials and methods › Control reference cohort and A1-event HRV ↔ Shaween_HRV_Features_w_CAP.m, lines 1 to 35 · score 0.76 · n1 n16, CAP Sleep Database, Pan Tompkins, HRV feature, CAP A1, healthy · Report a mismatch
- [4] § Materials and methods › CAP A1 detection (rule-based implementation) ↔ validate_CAP_A1.m, lines 1 to 100 · score 0.72 · expert annotated, CAP A1 events, validated, Cohen, sensitivity, module · Report a mismatch
- [5] § Materials and methods › EEG preprocessing ↔ validate_CAP_A1.m, lines 113 to 127 · score 0.71 · 0.5–4 Hz, delta band, morphology, CAP A1, channel, bandpass · Report a mismatch
- [6] § Materials and methods › ECG preprocessing and HRV feature extraction ↔ worked_example.m, lines 1 to 72 · score 0.66 · Pan Tompkins, peak detection, ECG epochs, fallback, SDNN, bpm · Report a mismatch
- [7] § Materials and methods › ECG preprocessing and HRV feature extraction ↔ ShaweenHRV_mhrv.m, the whole file · a weak match · score 0.65 · Pan Tompkins, peak detection, ECG epochs, fallback, intervals, nonlinear · Report a mismatch
- [8] § Materials and methods › ECG preprocessing and HRV feature extraction ↔ ShaweenHRV_mhrv.m, the whole file · a weak match · score 0.61 · mhrv toolbox directly, PhysioZoo, power, DFA, HRV features, Lomb · Report a mismatch
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
MATLAB · 186 lines · 7.6 KB · CC-BY-4.0 · 3 matches
- function results = validate_CAP_A1(dbDir, records, outCsv)
- % VALIDATE_CAP_A1 Benchmark YOUR rule-based CAP A1 detector against the
- % expert annotations of the PhysioNet CAP Sleep Database (capslpdb v1.0.0).
- %
- % Addresses Reviewer 1, Comment 1 (and the Editor note): reports sensitivity,
- % specificity, PPV, F1, and Cohen's kappa for CAP A1 detection vs. expert
- % scoring, at both 1-second and event levels, restricted to SWS (S3/S4).
- %
- % This version uses PhysioNet's own ScoringReader.m (shipped with the
- % database), so you do NOT parse the .txt files yourself.
- %
- % USAGE
- % r = validate_CAP_A1('capslpdb/', {'n1','n2','sdb1','sdb2'}, 'cap_a1_val.csv')
- % r = validate_CAP_A1('capslpdb/', [], 'cap_a1_val.csv') % uses RECORDS file
- %
- % INPUTS
- % dbDir folder holding the downloaded capslpdb files (*.edf, *.txt,
- % ScoringReader.m, RECORDS). Put this .m file there or add to path.
- % records cell array of record names WITHOUT extension, e.g. {'n1','sdb1'}.
- % If empty, all names in the RECORDS file are used.
- % RECOMMENDED for a CAP-A1/SWS benchmark: the 16 controls
- % {'n1'..'n16'} (clean SWS) plus the 4 SDB records {'sdb1'..'sdb4'}.
- % outCsv path for the per-record results table.
- %
- % >>> THE ONLY LINE YOU MUST EDIT is marked "WIRE HERE": call your detector. <<<
- % Your detector must return Nx2 [onset_sec offset_sec] of detected A1 events.
- %
- % REQUIREMENTS
- % - MATLAB R2023b+ (edfread/edfinfo), or replace local_load_eeg with your reader
- % - ScoringReader.m from the database (on the MATLAB path)
- % - Your CAP A1 module
- %
- % Author: prepared for the Frontiers in Physiology revision. CC-BY 4.0.
- if nargin < 3 || isempty(outCsv), outCsv = 'cap_a1_validation.csv'; end
- if nargin < 2 || isempty(records)
- records = local_read_records(fullfile(dbDir,'RECORDS'));
- end
- assert(exist('ScoringReader','file')==2, ...
- 'ScoringReader.m not found on path. Add the capslpdb folder to the MATLAB path.');
- rows = {}; allTP=0; allFP=0; allTN=0; allFN=0;
- for i = 1:numel(records)
- rec = records{i};
- txt = fullfile(dbDir,[rec '.txt']);
- edf = fullfile(dbDir,[rec '.edf']);
- if ~isfile(txt) || ~isfile(edf)
- warning('Missing files for %s, skipping.', rec); continue;
- end
- % ---- 1. Expert annotations via PhysioNet's ScoringReader.m -----------
- % ScoringReader returns the macrostructure hypnogram (0=W,1..4=S1..S4,5=REM)
- % and three arrays for the CAP A phases: start time (s), duration (s),
- % subtype (1=A1, 2=A2, 3=A3). Adjust the output order if your copy differs.
- [hypno, capStart, capDur, capType] = ScoringReader(txt); % see note above
- hypno = hypno(:);
- isA1 = (capType(:) == 1);
- a1_exp = [capStart(isA1), capStart(isA1)+capDur(isA1)]; % Nx2 sec
- % ---- 2. Load the central EEG derivation -----------------------------
- [eeg, fs, chan] = local_load_eeg(edf);
- % ---- 3. Run YOUR detector (WIRE HERE) -------------------------------
- caps_det = detect_cap_a1(eeg, fs, hypno); % <<< WIRE HERE: your A1 module
- % ---- 4. Build 1-second SWS masks (gold vs detected) -----------------
- T = max([numel(hypno)*30, ceil(max([a1_exp(:);0])), ...
- ceil(max([caps_det(:);0]))]);
- sws = local_stage_mask(hypno, T, [3 4]); % S3/S4 only
- gold = local_events_to_mask(a1_exp, T) & sws;
- pred = local_events_to_mask(caps_det,T) & sws;
- TP=sum(pred&gold); FP=sum(pred&~gold); FN=sum(~pred&gold); TN=sum(~pred&~gold);
- [se,sp,f1,kap,ppv] = local_metrics(TP,FP,TN,FN);
- [evSe,evPpv,evF1] = local_event_match(caps_det, a1_exp, sws, T, 0.5);
- rows(end+1,:) = {rec, char(chan), sum(isA1 & local_onset_in_sws(capStart,hypno,[3 4])),...
- size(caps_det,1), se, sp, ppv, f1, kap, evSe, evPpv, evF1}; %#ok<AGROW>
- allTP=allTP+TP; allFP=allFP+FP; allTN=allTN+TN; allFN=allFN+FN;
- fprintf('%-8s [%s] Se=%.3f Sp=%.3f F1=%.3f kappa=%.3f (eventF1=%.3f)\n',...
- rec, chan, se, sp, f1, kap, evF1);
- end
- [se,sp,f1,kap,ppv] = local_metrics(allTP,allFP,allTN,allFN);
- fprintf('\nPOOLED (1-s, SWS): Se=%.3f Sp=%.3f PPV=%.3f F1=%.3f Cohen kappa=%.3f\n',...
- se,sp,ppv,f1,kap);
- V = cell2table(rows,'VariableNames',{'record','channel','n_expert_A1_SWS',...
- 'n_detected','sensitivity','specificity','PPV','F1','kappa',...
- 'event_sensitivity','event_PPV','event_F1'});
- writetable(V,outCsv);
- results = struct('perRecord',V,'pooled',...
- struct('Se',se,'Sp',sp,'PPV',ppv,'F1',f1,'kappa',kap));
- fprintf('Per-record results written to %s\n', outCsv);
- fprintf(['\nReport in the manuscript (Section 2.4 / 3): pooled Se, Sp, F1 and ' ...
- 'Cohen''s kappa above, plus the per-record table as supplementary.\n']);
- end
- % ============================ helpers ===================================
- function recs = local_read_records(f)
- recs = {};
- if isfile(f)
- fid=fopen(f); c=textscan(fid,'%s'); fclose(fid); recs=c{1};
- else
- % default: controls + SDB
- recs = [arrayfun(@(k)sprintf('n%d',k),1:16,'uni',0), ...
- arrayfun(@(k)sprintf('sdb%d',k),1:4,'uni',0)];
- warning('RECORDS file not found; defaulting to controls n1-n16 + sdb1-4.');
- end
- end
- function [eeg, fs, chan] = local_load_eeg(edfPath)
- info = edfinfo(edfPath);
- labels = string(info.SignalLabels);
- pick = find(contains(labels,["C4-A1","C3-A2","C4A1","C3A2"],'IgnoreCase',true),1);
- if isempty(pick), pick = find(contains(labels,["C4","C3"],'IgnoreCase',true),1); end
- if isempty(pick), pick = find(contains(labels,"EEG",'IgnoreCase',true),1); end
- if isempty(pick), pick = 1; end
- chan = labels(pick);
- fs = double(info.NumSamples(pick))/seconds(info.DataRecordDuration);
- tt = edfread(edfPath,'SelectedSignals',cellstr(chan));
- eeg = cell2mat(tt.(matlab.lang.makeValidName(chan)));
- eeg = double(eeg(:));
- [b,a]= butter(4,[0.5 4]/(fs/2),'bandpass'); % delta band, matches A1 morphology
- eeg = filtfilt(b,a,eeg);
- end
- function m = local_events_to_mask(ev, T)
- m = false(1,T);
- for k=1:size(ev,1)
- a=max(1,floor(ev(k,1))+1); b=min(T,ceil(ev(k,2)));
- if b>=a, m(a:b)=true; end
- end
- end
- function msk = local_stage_mask(hypno, T, stages)
- msk = false(1,T);
- for e=1:numel(hypno)
- if any(hypno(e)==stages)
- a=(e-1)*30+1; b=min(T,e*30); msk(a:b)=true;
- end
- end
- if ~any(msk), msk=true(1,T); end % if hypnogram empty, do not gate
- end
- function tf = local_onset_in_sws(starts, hypno, stages)
- tf = false(numel(starts),1);
- for k=1:numel(starts)
- e=floor(starts(k)/30)+1;
- if e>=1 && e<=numel(hypno) && any(hypno(e)==stages), tf(k)=true; end
- end
- end
- function [se,sp,f1,kap,ppv] = local_metrics(TP,FP,TN,FN)
- se =TP/max(TP+FN,1); sp =TN/max(TN+FP,1); ppv=TP/max(TP+FP,1);
- f1 =2*ppv*se/max(ppv+se,eps);
- N=TP+FP+TN+FN; po=(TP+TN)/max(N,1);
- pe=((TP+FP)*(TP+FN)+(TN+FN)*(TN+FP))/max(N^2,1);
- kap=(po-pe)/max(1-pe,eps);
- end
- function [se,ppv,f1] = local_event_match(det, exp, sws, T, ovl)
- det=local_restrict(det,sws,T); exp=local_restrict(exp,sws,T);
- mE=false(size(exp,1),1);
- for i=1:size(det,1)
- for j=1:size(exp,1)
- if mE(j), continue; end
- o=min(det(i,2),exp(j,2))-max(det(i,1),exp(j,1));
- if o<=0, continue; end
- shorter=min(diff(det(i,:)),diff(exp(j,:)));
- if o/max(shorter,eps)>=ovl, mE(j)=true; break; end
- end
- end
- TP=sum(mE); se=TP/max(size(exp,1),1); ppv=TP/max(size(det,1),1);
- f1=2*ppv*se/max(ppv+se,eps);
- end
- function ev = local_restrict(ev, sws, T)
- keep=false(size(ev,1),1);
- for k=1:size(ev,1)
- a=max(1,floor(ev(k,1))+1); b=min(T,ceil(ev(k,2)));
- if b>=a && any(sws(a:b)), keep(k)=true; end
- end
- ev=ev(keep,:);
- end
validate_CAP_A1.m at commit 49885ef, under CC-BY-4.0 · at the source
Overview
- Healthcare Engineering Innovation Group (HEIG), Department of Biomedical Engineering and Biotechnology, Khalifa University, Abu Dhabi, United Arab Emirates
- Graduate School of Education, University of Tokyo, Bunkyo-ku, Tokyo, Japan
Abstract
Background: Multimodal sleep analysis typically requires separate processing pipelines for electroencephalography (EEG) and electrocardiography (ECG), which complicates joint investigation of sleep microstructure and autonomic regulation. Cyclic alternating pattern (CAP) scoring and heart rate variability (HRV) analysis are routinely performed in different software environments, limiting temporal alignment, reproducibility, and scalability.
Methods: We present an open-source MATLAB framework that integrates rule-based CAP A1 detection and HRV feature extraction within a single, time-synchronized workflow. The pipeline performs standardized EEG and ECG preprocessing, rule-based CAP A1 detection during slow-wave sleep (SWS) implementing the Terzano scoring criteria, R-peak detection via the Pan–Tompkins algorithm, and computation of time-domain, frequency-domain, and nonlinear HRV features by calling the open-source PhysioZoo/
Results: Because HRV features are computed by calling the PhysioZoo/
Conclusion: The framework provides a reproducible, rule-based, and modular tool for integrated EEG–ECG analysis of sleep microstructure and autonomic dynamics. By enabling synchronized CAP–HRV feature extraction in a single environment, it lowers the engineering barrier to brain–heart coupling research during sleep and provides a foundation for future extensions, including validated CAP detection, a matched-control study, a Python port, and cloud-based deployment.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 8 matches between paragraphs and lines of code.
ahsankhandoker/CAP-HRV
49885ef1f0ea7ca741dc6bc76c247c839cd46730, 16 October 2026Availability: 1 check, the latest on 31 October 2026: the link answers
- 31 October 2026: the link answers
7 files
- ShaweenHRV_mhrv.m, MATLAB, 58 lines, 2 matches
- Shaween_HRV_Features_w_C
AP.m , MATLAB, 193 lines, 1 match - pan_tompkin.m, MATLAB, 404 lines
- validate_CAP_A1.m, MATLAB, 186 lines, 3 matches
- worked_example.m, MATLAB, 84 lines, 2 matches
- LICENSE, License, 402 lines
- README.md, Text, 75 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 5 scripts, each with its path and the digest of its content;
- 8 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data availability statement
The original contributions presented in the study are included in the article/
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 31 October 2026: the first record
Recorded: type, language, journal, volume, pages, dates, 5 authors, 6 keywords, 28 references.
Cite
This paper
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, 1864664.
BibTeX
@article{shukir2026autom
author = {Shukir, Shaween and Moussa, Mostafa and AlZaabi, Yahya and Khandoker, Ahsan and Struzik, Zbigniew R},
title = {{An automated EEG–ECG framework for CAP–HRV analysis: enabling brain–heart coupling studies in sleep disorders}},
journal = {Frontiers in physiology},
year = {2026},
month = oct,
volume = {17},
pages = {1864664},
publisher = {Frontiers Media SA},
issn = {1664-042X},
pmcid = {PMC13719611}
}
RIS
TY - JOUR
AU - Shukir, Shaween
AU - Moussa, Mostafa
AU - AlZaabi, Yahya
AU - Khandoker, Ahsan
AU - Struzik, Zbigniew R
TI - An automated EEG–ECG framework for CAP–HRV analysis: enabling brain–heart coupling studies in sleep disorders
T2 - Frontiers in physiology
J2 - Front Physiol
PY - 2026
DA - 2026/
VL - 17
SP - 1864664
SN - 1664-042X
PB - Frontiers Media SA
LA - en
ER -
CSL-JSON
{
"id": "pmcid:PMC13719611",
"type": "article-journal",
"title": "An automated EEG–ECG framework for CAP–HRV analysis: enabling brain–heart coupling studies in sleep disorders",
"container-title": "Frontiers in physiology",
"author": [
{
"family": "Shukir",
"given": "Shaween"
},
{
"family": "Moussa",
"given": "Mostafa"
},
{
"family": "AlZaabi",
"given": "Yahya"
},
{
"family": "Khandoker",
"given": "Ahsan"
},
{
"family": "Struzik",
"given": "Zbigniew R"
}
],
"container-title-short":
"volume": "17",
"page": "1864664",
"PMCID": "PMC13719611",
"ISSN": "1664-042X",
"publisher": "Frontiers Media SA",
"language": "en",
"issued": {
"date-parts": [
[
2026,
10,
31
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1038/s42003-026-10156-5 [code]
- Brain-heart interactions in late-onset major depressive disorder revealed by multimodal HRV-driven fMRI.Journal: Communications biologyIn common: depression, other, 4 references
- [2] doi:10.3390/diagnostics12102510
- L-Tetrolet Pattern-Based Sleep Stage Classification Model Using Balanced EEG Datasets.Journal: Diagnostics (Basel, Switzerland)In common: sleep disorders, methods / tools, EEG, 3 references
- [3] doi:10.1186/s12911-024-02522-2
- Machine learning-empowered sleep staging classification using multi-modality signals.Journal: BMC medical informatics and decision makingIn common: other, methods / tools, EEG, 3 references
- [4] doi:10.3390/bios16010056 [code]
- Modulation-Based Feature Extraction for Robust Sleep Stage Classification Across Apnea-Based Cohorts.Journal: BiosensorsIn common: Signal Processing Toolbox, sleep disorders, methods / tools, EEG, 2 references
- [5] doi:10.3390/diagnostics16152317
- MAF-SleepNet: A Multimodal Attention-Enhanced Fusion Network for Automatic Multi-Class Sleep Disorder Classification from Polysomnography.Journal: Diagnostics (Basel, Switzerland)In common: sleep disorders, EEG, 3 references
- [6] doi:10.1038/s42003-025-08685-6 [code]
- Dynamic brain-heart interaction in sleep characterized by variational phase-amplitude coupling framework.Journal: Communications biologyIn common: Signal Processing Toolbox, sleep disorders, EEG, 2 references
- [7] doi:10.1038/s42003-025-09026-3 [code]
- When your heart isn't in it anymore: cardiac correlates of task disengagement.Journal: Communications biologyIn common: Signal Processing Toolbox, other, EEG, 2 references
- [8] doi:10.3389/fnagi.2024.1498687
- Diagnostic accuracy of heart rate variability as a screening tool for mild neurocognitive disorder.Journal: Frontiers in aging neuroscienceIn common: depression, other, 3 references
- [9] doi:10.1038/s41746-026-03406-7 [code]
- AnySleep: a channel-agnostic deep learning system for high-resolution sleep staging in multi-center cohorts.Journal: NPJ digital medicineIn common: sleep disorders, EEG, 3 references
- [10] doi:10.3390/diagnostics16162609
- Automated Multimodal Sleep Staging Using DWT-Based Wavelet Decomposition and Explainable Machine Learning with Signal Sculpting Topographies.Journal: Diagnostics (Basel, Switzerland)In common: other, methods / tools, EEG, 3 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 5 scripts, and 8 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:b5b5f6ffe7729e34…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/repo/github.com/ahsankhandoker/cap-hrv)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/repo/github.com/ahsankhandoker/cap-hrv.svg
:target: https://openscicode.org/badge/repo/github.com/ahsankhandoker/cap-hrv
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/repo/github.com/ahsankhandoker/cap-hrv"><img src="https://openscicode.org/badge/repo/github.com/ahsankhandoker/cap-hrv.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
