OSCR

A dataset of EEG and ECG recordings around the onset of NREM sleep from infancy to adolescence.

Code ↔ Paper

9 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 9 matches · 2 of them tie a paragraph to a whole file, not to given lines: weak matches, whose lines are not tinted
  1. [1] § Methods › Data acquisition ↔ subfunctions/read_into_montage.m, the whole file · a weak match · score 0.86 · double banana, bipolar montage, channel, EEG
  2. [2] § Technical Validation ↔ quality_assesssment_for_github.m, lines 98–177 · score 0.78 · burst sharpness, post N2 onset, relative alpha, pre N2 onset, Spearman, centile
  3. [3] § Data Records ↔ quality_assesssment_for_github.m, lines 1–24 · score 0.73 · anon_codex_age_sex.csv, quantized age, quantized sex, female
  4. [4] § Technical Validation ↔ subfunctions/single_channel_features.m, lines 1–52 · score 0.73 · relative spectral power, spectral entropy, modified, PSD, duration, vector
  5. [5] § Technical Validation ↔ quality_assesssment_for_github.m, lines 613–685 · score 0.73 · minute epoch, Pan Tompkins, ECG features, notch, quality, median
  6. [6] § Data Records ↔ anonymize_dataset_for_github.m, lines 116–167 · score 0.63 · anon codex, quantized sex, quantized age, EDF
  7. [7] § Technical Validation ↔ quality_assesssment_for_github.m, lines 255–303 · score 0.63 · post N2 onset, pre N2 onset, predicted age, kernel, correlation
  8. [8] § Technical Validation ↔ quality_assesssment_for_github.m, lines 255–303 · score 0.63 · post N2 onset, pre N2 onset, predicted age, kernel, correlation
  9. [9] § Data Records ↔ subfunctions/read_into_montage.m, the whole file · a weak match · score 0.62 · referential montage, microvolts, EDF, channels, EEG

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 897 lines · 31 KB · MIT · 5 matches

  1. % Quality Assessment Open EEG Data
  2. % READ IN CSV file with filenames, quantized age and sex
  3. filename = 'anon_codex_age_sex.csv';
  4. % Specify range and delimiter
  5. dataLines = [2, Inf];
  6. opts = delimitedTextImportOptions("NumVariables", 3);
  7. opts.DataLines = dataLines;
  8. opts.Delimiter = ",";
  9. opts.VariableNames = ["AnonFilename", "QuantizedAgeyears", "QuantizedSex"];
  10. opts.VariableTypes = ["string", "double", "categorical"];
  11. opts.ExtraColumnsRule = "ignore";
  12. opts.EmptyLineRule = "read";
  13. opts = setvaropts(opts, "AnonFilename", "WhitespaceRule", "preserve");
  14. opts = setvaropts(opts, ["AnonFilename", "QuantizedSex"], "EmptyFieldRule", "auto");
  15. % Import the data
  16. anoncodex = readtable(filename, opts);
  17. fnames = cellstr(anoncodex{:,1});
  18. ages = anoncodex{:,2};
  19. sex = anoncodex{:,3};
  20. s1 = contains(sex, 'M'); % M - Male
  21. sex = s1;
  22. %s2 = contains(sex, 'F'); % F - Female
  23. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24. %
  25. % EEG ANALYSIS
  26. %
  27. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  28. % PERFORM BASIC EVALUATIONS ON DATASET
  29. fs1 = 250;
  30. val1a = zeros(1, length(fnames)); val1b = val1a; val2 = val1a;
  31. for ii = 1:length(fnames)
  32. [dat, hdr, label, fs, scle, offs] = read_edf(fnames{ii});
  33. data_bp_mont = read_into_montage(dat, label, scle, fs, fs1, 0);
  34. anno = per_ha_art(data_bp_mont, fs1);
  35. val2(ii) = sum(sum(anno))/prod(size(anno))*100;
  36. [nf1, nf2] = noise_floor(data_bp_mont, anno, fs1);
  37. val1a(ii) = mean(nf1); val1b(ii) = mean(nf2);
  38. end
  39. save('results_qa_v1.mat', 'val1a', 'val1b', 'val2');
  40. load results_qa_v1
  41. X = [ages sex]; % convert sex to binary first
  42. y1 = fitlm(X, val1a');
  43. y2 = fitlm(X, val1b');
  44. % SIMPLE FEATURE EXTRACTION
  45. fts = cell(1, length(fnames));
  46. %parpool(8) consider using parpool if possible
  47. for ii = 1:length(fnames)
  48. ii
  49. fts{ii} = get_fts(fnames, ii);
  50. end
  51. %cd('L:\Lab_JamesR\nathanST\FBA_paeds_project\Documents\paper3_open_data')
  52. save('results_qa_feats_v1.mat', 'fts', 'ages', 'sex')
  53. load results_qa_feats_v1
  54. % CORRELATIONS WITH AGE
  55. fv1 = zeros(length(fts), 32); fv2 = fv1;
  56. for ii = 1:length(fts)
  57. fval = fts{ii};
  58. fv1(ii,:) = median(fval(1:10,:));
  59. A = size(fval);
  60. if A(1)<21
  61. fv2(ii,:) = median(fval(11:end,:)); % pre N2 onset
  62. else
  63. fv2(ii,:) = median(fval(11:21,:)); % post N2 onset
  64. end
  65. end
  66. p1 = corr(fv1, ages);
  67. p2 = corr(fv2, ages);
  68. val = unique(ages);
  69. prs = [1:2:length(val) ; 2:2:length(val)];
  70. x1 = ages(sex==0);
  71. x2 = ages(sex==1);
  72. xx = linspace(min(ages), max(ages), 100);
  73. A = size(fv2);
  74. for ii = 1:A(2)
  75. ii
  76. y1 = fv2(sex==0,ii);
  77. y2 = fv2(sex==1,ii);
  78. y1v = zeros(1, length(val)); y2v = y1v;
  79. for jj = 1:length(val)
  80. y1v(jj) = median(y1(x1==val(jj)));
  81. y2v(jj) = median(y2(x2==val(jj)));
  82. end
  83. cohD = zeros(length(prs), 5);
  84. for jj = 1:length(prs)
  85. dum = meanEffectSize(y1(x1==val(prs(1,jj)) | x1==val(prs(2,jj))), y2(x2==val(prs(1,jj)) | x2==val(prs(2,jj))));
  86. cohD(jj,:) = [dum.Variables sum(x1==val(prs(1,jj)) | x1==val(prs(2,jj))) sum(x2==val(prs(1,jj)) | x2==val(prs(2,jj)))];
  87. end
  88. end
  89. % START PLOTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90. figure;
  91. subplot(2,2,1);
  92. f = zeros(1,17);
  93. for ii = 1:17
  94. rf = find(ages>=ii-1 & ages<ii);
  95. f(ii) = median(fv1(rf,25));
  96. end
  97. x = [1:17]-0.5;
  98. B = polyfit(x([1:15 17]), f([1:15 17]),2);
  99. res = fv1(:,25)-polyval(B,ages);
  100. rx = find(abs(res)<5e-4);
  101. plot(ages(rx), fv1(rx,25), '.');
  102. ylabel('Hjorth 2')
  103. xlabel('Age (y)')
  104. axis([-1 17 0 2e-3])
  105. set(gca, 'position', [0.1 0.575 0.375 0.375], 'FontName', 'times', 'FontSize', 12)
  106. title('Pre- N2 onset')
  107. text(0, 1.75e-3, 'A', 'FontName', 'times', 'FontSize', 14)
  108. pp = corr(ages, fv1(:,25), 'type','Spearman');
  109. text(10, 0.25e-3, ['r = ' num2str(pp, '%1.3f')], 'FontName', 'times', 'FontSize', 12)
  110. subplot(2,2,3);
  111. f = zeros(1,17);
  112. for ii = 1:17
  113. rf = find(ages>=ii-1 & ages<ii);
  114. f(ii) = median(fv1(rf,30));
  115. end
  116. x = [1:17]-0.5;
  117. B = polyfit(x([1:15 17]), f([1:15 17]),2);
  118. res = fv1(:,30)-polyval(B,ages);
  119. rx = find(abs(res)<0.02);
  120. plot(ages(rx), fv1(rx,30), '.');
  121. ylabel('Burst Sharpness')
  122. xlabel('Age (y)')
  123. axis([-1 17 -.97 -0.89])
  124. set(gca, 'position', [0.1 0.1 0.375 0.375], 'FontName', 'times', 'FontSize', 12)
  125. text(15, -0.9, 'B', 'FontName', 'times', 'FontSize', 14)
  126. pp = corr(ages, fv1(:,30), 'type','Spearman');
  127. text(0, -0.96, ['r = ' num2str(pp, '%1.3f')], 'FontName', 'times', 'FontSize', 12)
  128. subplot(2,2,2);
  129. f = zeros(1,17);
  130. for ii = 1:17
  131. rf = find(ages>=ii-1 & ages<ii);
  132. f(ii) = median(fv2(rf,16));
  133. end
  134. x = [1:17]-0.5;
  135. B = polyfit(x([1:15 17]), f([1:15 17]),3);
  136. res = fv2(:,16)-polyval(B,ages);
  137. rx = find(abs(res)<5);
  138. plot(ages(rx), fv2(rx,16), '.');
  139. ylabel('Relative Alpha* Power (%)')
  140. xlabel('Age (y)')
  141. axis([-1 17 0 17.5])
  142. set(gca, 'position', [0.6 0.575 0.375 0.375], 'FontName', 'times', 'FontSize', 12)
  143. title('Post- N2 onset')
  144. text(0, 15, 'C', 'FontName', 'times', 'FontSize', 14)
  145. pp = corr(ages, fv2(:,16), 'type','Spearman');
  146. text(10, 2, ['r = ' num2str(pp, '%1.3f')], 'FontName', 'times', 'FontSize', 12)
  147. subplot(2,2,4);
  148. f = zeros(1,17);
  149. for ii = 1:17
  150. rf = find(ages>=ii-1 & ages<ii);
  151. f(ii) = median(fv2(rf,1));
  152. end
  153. x = [1:17]-0.5;
  154. B = polyfit(x([1:15 17]), f([1:15 17]),2);
  155. res = fv2(:,1)-polyval(B,ages);
  156. rx = find(abs(res)<4);
  157. plot(ages, fv2(:,1), '.');
  158. ylabel('Amplitude (5^{th} centile; \muV)')
  159. xlabel('Age (y)')
  160. axis([-1 17 0 15])
  161. set(gca, 'position', [0.6 0.1 0.375 0.375], 'FontName', 'times', 'FontSize', 12)
  162. text(15, 13, 'D', 'FontName', 'times', 'FontSize', 14)
  163. pp = corr(ages, fv1(:,1), 'type','Spearman');
  164. text(0, 2, ['r=' num2str(pp, '%1.3f')], 'FontName', 'times', 'FontSize', 12)
  165. % END PLOTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  166. % TRAIN GPR based age prediction - 5-fold CV 80:20 split
  167. % Find outliers in features
  168. rfs = zeros(1,length(fv1));
  169. for jj = 1:32
  170. y = fv1(:,jj); x = ages;
  171. B = polyfit(x,y,2);
  172. res = y - polyval(B, x);
  173. dum = zeros(1, length(y)); dum(find(abs(res)>6*std(res)))=1;
  174. rfs = rfs+dum;
  175. y = fv2(:,jj); x = ages;
  176. B = polyfit(x,y,2);
  177. res = y - polyval(B, x);
  178. dum = zeros(1, length(y)); dum(find(abs(res)>6*std(res)))=1;
  179. rfs = rfs+dum;
  180. end
  181. % get rid of outliers for now
  182. nref = find(rfs==0);
  183. fv1 = fv1(nref,:);
  184. fv2 = fv2(nref,:);
  185. ages = ages(nref);
  186. % split up data into 5 folds for cross-validation
  187. pid_in1 = 1:length(fv1);
  188. pma_in1 = ages;
  189. Mc = 5;
  190. out = zeros(1,1000);
  191. for qq = 1:1000
  192. rng(qq)
  193. pd = unique(pid_in1);
  194. y = cell(1,Mc);
  195. rx = ones(1,length(pd));
  196. K = floor(length(pd)/Mc); dum = rem(length(pd), Mc);
  197. K = K.*ones(1,Mc); K(1:dum) = K(1)+1;
  198. for ii = 1:Mc
  199. rz = find(rx==1);
  200. dum = randsample(length(rz), K(ii), false);
  201. rx(rz(dum)) = 0;
  202. y{ii} = rz(dum);
  203. end
  204. y{end} = [y{end}' ; find(rx==1)']';
  205. for ii = 1:Mc
  206. y{ii} = pd(y{ii});
  207. end
  208. ss = cell(1, Mc);
  209. for ii = 1:Mc
  210. rf = y{ii};
  211. ag = [];
  212. for jj = 1:length(rf); ag = [ag pma_in1(find(pid_in1==rf(jj)))]; end
  213. ss{ii} = ag;
  214. end
  215. pv = zeros(1,6); c1 = 1;
  216. for ii = 1:Mc
  217. for jj = ii+1:Mc
  218. [~, pv(c1)] = kstest2(ss{ii}, ss{jj});
  219. c1 = c1+1;
  220. end
  221. end
  222. out(qq) = mean(pv);
  223. end
  224. nr = find(out==max(out)); % nr = 7
  225. rng(nr)
  226. yr = cell(1,Mc);
  227. rx = ones(1,length(pd)); %rt = 1-rx; %rr = 1:length(pid);
  228. for ii = 1:Mc
  229. rz = find(rx==1);
  230. dum = randsample(length(rz), K(ii), false);
  231. rx(rz(dum)) = 0;
  232. yr{ii} = rz(dum);
  233. end
  234. yr{end} = [yr{end}' ; find(rx==1)']';
  235. for ii = 1:Mc; yr{ii} = pd(yr{ii}); end
  236. % do training and testing of age prediction for both pre- and post- N2
  237. % onset data
  238. pred1 = []; pred2 = []; agx = [];
  239. for ii = 1:Mc
  240. ii
  241. dum = zeros(1,length(fv1));
  242. dum(yr{ii})=1;
  243. r1 = find(dum==1); r2 = find(dum==0);
  244. rGP1 = fitrgp(fv1(r2,:), ages(r2), 'BasisFunction', 'constant', 'KernelFunction', 'matern52', 'Standardize', true);
  245. out1 = predict(rGP1, fv1(r1,:));
  246. pred1 = [pred1 ; out1];
  247. rGP2 = fitrgp(fv2(r2,:), ages(r2), 'BasisFunction', 'constant', 'KernelFunction', 'matern52', 'Standardize', true);
  248. out2 = predict(rGP1, fv2(r1,:));
  249. pred2 = [pred2 ; out2];
  250. agx = [agx ; ages(r1)];
  251. end
  252. % START PLOTTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  253. figure;
  254. subplot(1,2,1)
  255. plot(agx, pred1 ,'.')
  256. title('Pre- N2 Onset')
  257. set(gca, 'FontName', 'times', 'Fontsize', 16)
  258. xlabel('Age (y)'); ylabel('Predicted Age (y)')
  259. grid on; hold on;
  260. plot([-2 18], [-2, 18], 'k')
  261. axis([-1 17 -1, 17])
  262. set(gca, 'position', [0.075 0.15 0.4 0.8], 'Xtick', [0:2:16], 'Ytick', [0:2:16])
  263. %text(0, 16, 'A', 'FontName', 'times', 'Fontsize', 14)
  264. pp = corr(agx, pred1);
  265. text(10, 2, ['r = ' num2str(pp, '%1.3f')], 'FontName', 'times', 'FontSize', 16)
  266. subplot(1,2,2)
  267. plot(agx, pred2 ,'.')
  268. title('Post- N2 Onset')
  269. set(gca, 'FontName', 'times', 'Fontsize', 16)
  270. xlabel('Age (y)'); ylabel('Predicted Age (y)')
  271. grid on; hold on;
  272. plot([-2 18], [-2, 18], 'k')
  273. axis([-1 17 -1, 17])
  274. set(gca, 'position', [0.575 0.15 0.4 0.8], 'Xtick', [0:2:16], 'Ytick', [0:2:16])
  275. %text(0, 16, 'B', 'FontName', 'times', 'Fontsize', 14)
  276. pp = corr(agx, pred2);
  277. text(10, 2, ['r = ' num2str(pp, '%1.3f')], 'FontName', 'times', 'FontSize', 16)
  278. % END PLOTTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  279. % DO SPECTRAL ANALYSIS
  280. addpath('L:\Lab_JamesR\nathanST\FBA_paeds_project\Code\fba_code_107052022\subfunctions')
  281. spa = cell(1, length(fnames)); spb = spa;
  282. %parpool(6)
  283. for ii = 1:length(fnames)
  284. ii
  285. [spa{ii}, spb{ii}] = get_spectra(fnames, ii);
  286. end
  287. save('results_qa_spec_v1.mat', 'spa', 'spb', 'ages', 'sex')
  288. load results_qa_spec_v1
  289. rn = [0 1 ; 1 3 ; 3 7 ; 7 17];
  290. d1 = 10*log10(cell2mat(spa')); d2 = 10*log10(cell2mat(spb'));
  291. spec_pre_mean = zeros(4, 257); spec_pre_std = spec_pre_mean; spec_post_mean = spec_pre_mean;
  292. spec_post_std = spec_pre_mean;
  293. for ii = 1:4
  294. rf = find(ages> rn(ii,1) & ages <= rn(ii,2));
  295. length(rf)
  296. spec_pre_mean(ii,:) = mean(d1(rf,:));
  297. spec_pre_std(ii,:) = std(d1(rf,:));
  298. spec_post_mean(ii,:) = mean(d2(rf,:));
  299. spec_post_std(ii,:) = std(d2(rf,:));
  300. end
  301. % START PLOTTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  302. figure; set(gcf, 'Position', [1000 150 800 680])
  303. subplot(4,4,[1 2 5 6]); hold on;
  304. f = linspace(0, 32, 257); rf = 6:255;
  305. for ii = 1:4
  306. h(ii) = plot(f(rf), spec_pre_mean(ii,rf), 'LineWidth', 2);
  307. end
  308. title('Pre- N2 Onset')
  309. axis([0 32 -10 40])
  310. legend(h, '0-1y','1-3y','3-7y','7-16y')
  311. set(gca, 'Fontname', 'times', 'fontsize', 14, 'Xtick', [0:4:32], 'XTickLabel', [0:4:32])
  312. xlabel('Frequency (Hz)', 'Fontname', 'times', 'fontsize', 16);
  313. ylabel('Power (dB)', 'Fontname', 'times', 'fontsize', 16);
  314. grid on
  315. set(gca, 'Position', [0.075 0.575 0.405 0.4])
  316. %text(4, 35, 'A', 'Fontname', 'times', 'fontsize', 18)
  317. fr = [9 10 13 14];
  318. pst1(1,:) = [0.075 0.285 0.19 0.2];
  319. pst1(2,:) = [0.295 0.285 0.19 0.2];
  320. pst1(3,:) = [0.075 0.075 0.19 0.2];
  321. pst1(4,:) = [0.295 0.075 0.19 0.2];
  322. for ii = 1:4
  323. subplot(4,4, fr(ii))
  324. cc = get(h(ii), 'color');
  325. g1 = spec_pre_mean(ii,:)+2*spec_pre_std(ii,:);
  326. g2 = spec_pre_mean(ii,:)-2*spec_pre_std(ii,:);
  327. j = patch([f(rf(1)) f(rf) f(rf(250:-1:1)) f(rf(1))], [g2(rf(1)) g1(rf) g2(rf(250:-1:1)) g1(rf(1))], cc);
  328. set(j, "EdgeColor", 'none')
  329. hold on;
  330. plot(f(rf), spec_pre_mean(ii,rf), 'color', [1 1 1]);
  331. axis([0 32 0 40])
  332. set(gca, 'Position', pst1(ii,:),'Xtick', [0:8:32], 'Fontname', 'times', 'fontsize', 14)
  333. switch ii
  334. case 1
  335. set(gca, 'Xticklabel', {}, 'Fontname', 'times', 'fontsize', 14)
  336. ylabel('Power (dB)', 'Fontname', 'times', 'fontsize', 16);
  337. text(20, 32, '0-1y', 'Fontname', 'times', 'fontsize', 14)
  338. case 2
  339. set(gca, 'Yticklabel', {}, 'Xticklabel', {}, 'Fontname', 'times', 'fontsize', 14)
  340. text(20, 32, '1-3y', 'Fontname', 'times', 'fontsize', 14)
  341. case 3
  342. set(gca, 'Fontname', 'times', 'fontsize', 14)
  343. xlabel('Frequency (Hz)', 'Fontname', 'times', 'fontsize', 16);
  344. ylabel('Power (dB)', 'Fontname', 'times', 'fontsize', 16);
  345. text(20, 32, '3-7y', 'Fontname', 'times', 'fontsize', 14)
  346. case 4
  347. set(gca, 'Yticklabel', {}, 'Fontname', 'times', 'fontsize', 14)
  348. xlabel('Frequency (Hz)', 'Fontname', 'times', 'fontsize', 16);
  349. text(20, 32, '7-16y', 'Fontname', 'times', 'fontsize', 14)
  350. end
  351. grid on;
  352. axis([0 32 -10 40])
  353. end
  354. subplot(4,4,[3 4 7 8]);
  355. hold on;
  356. f = linspace(0, 32, 257); rf = 6:255;
  357. for ii = 1:4
  358. h1(ii) = plot(f(rf), spec_post_mean(ii,rf), 'LineWidth', 2);
  359. end
  360. title('Post- N2 Onset')
  361. axis([0 32 -10 40])
  362. legend(h1, '0-1y','1-3y','3-7y','7-16y')
  363. set(gca, 'Fontname', 'times', 'fontsize', 14, 'Xtick', [0:4:32], 'XTickLabel', [0:4:32])
  364. xlabel('Frequency (Hz)', 'Fontname', 'times', 'fontsize', 16);
  365. ylabel('Power (dB)', 'Fontname', 'times', 'fontsize', 16);
  366. grid on
  367. set(gca, 'Position', [0.575 0.575 0.405 0.4])
  368. %text(4, 35, 'B', 'Fontname', 'times', 'fontsize', 18)
  369. fr = [9 10 13 14];
  370. pst1(1,:) = [0.575 0.285 0.19 0.2];
  371. pst1(2,:) = [0.795 0.285 0.19 0.2];
  372. pst1(3,:) = [0.575 0.075 0.19 0.2];
  373. pst1(4,:) = [0.795 0.075 0.19 0.2];
  374. for ii = 1:4
  375. subplot(4,4, fr(ii))
  376. cc = get(h1(ii), 'color');
  377. g1 = spec_post_mean(ii,:)+2*spec_post_std(ii,:);
  378. g2 = spec_post_mean(ii,:)-2*spec_post_std(ii,:);
  379. j = patch([f(rf(1)) f(rf) f(rf(250:-1:1)) f(rf(1))], [g2(rf(1)) g1(rf) g2(rf(250:-1:1)) g1(rf(1))], cc);
  380. set(j, "EdgeColor", 'none')
  381. hold on;
  382. plot(f(rf), spec_post_mean(ii,rf), 'color', [1 1 1]);
  383. axis([0 32 0 40])
  384. set(gca, 'Position', pst1(ii,:),'Xtick', [0:8:32], 'Fontname', 'times', 'fontsize', 14)
  385. switch ii
  386. case 1
  387. set(gca, 'Xticklabel', {}, 'Fontname', 'times', 'fontsize', 14)
  388. ylabel('Power (dB)', 'Fontname', 'times', 'fontsize', 16);
  389. text(20, 32, '0-1y', 'Fontname', 'times', 'fontsize', 14)
  390. case 2
  391. set(gca, 'Yticklabel', {}, 'Xticklabel', {}, 'Fontname', 'times', 'fontsize', 14)
  392. text(20, 32, '1-3y', 'Fontname', 'times', 'fontsize', 14)
  393. case 3
  394. set(gca, 'Fontname', 'times', 'fontsize', 14)
  395. xlabel('Frequency (Hz)', 'Fontname', 'times', 'fontsize', 16);
  396. ylabel('Power (dB)', 'Fontname', 'times', 'fontsize', 16);
  397. text(20, 32, '3-7y', 'Fontname', 'times', 'fontsize', 14)
  398. case 4
  399. set(gca, 'Yticklabel', {}, 'Fontname', 'times', 'fontsize', 14)
  400. xlabel('Frequency (Hz)', 'Fontname', 'times', 'fontsize', 16);
  401. text(20, 32, '7-16y', 'Fontname', 'times', 'fontsize', 14)
  402. end
  403. grid on;
  404. axis([0 32 -10 40])
  405. end
  406. % END PLOTTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  407. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  408. %
  409. % Plot some example EEG recordings
  410. %
  411. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  412. filename = 'anon_codex_age_sex.csv';
  413. % Specify range and delimiter
  414. dataLines = [2, Inf];
  415. opts = delimitedTextImportOptions("NumVariables", 3);
  416. opts.DataLines = dataLines;
  417. opts.Delimiter = ",";
  418. opts.VariableNames = ["AnonFilename", "QuantizedAgeyears", "QuantizedSex"];
  419. opts.VariableTypes = ["string", "double", "categorical"];
  420. opts.ExtraColumnsRule = "ignore";
  421. opts.EmptyLineRule = "read";
  422. opts = setvaropts(opts, "AnonFilename", "WhitespaceRule", "preserve");
  423. opts = setvaropts(opts, ["AnonFilename", "QuantizedSex"], "EmptyFieldRule", "auto");
  424. % Import the data
  425. anoncodex = readtable(filename, opts);
  426. fnames = cellstr(anoncodex{:,1});
  427. ages = anoncodex{:,2};
  428. sex = anoncodex{:,3};
  429. ref1 = find(ages>7 & ages<=20);
  430. % BASIC EVALUATIONS
  431. fs1 = 250;
  432. [B,A] = butter(4, [1 64]./fs1, 'bandpass');
  433. r1 = fs1*5*60+1; r2 = r1+8*fs1-1;
  434. cc(1,:) = [1 0.25 0.25];
  435. cc(2,:) = [1 0.25 0.25];
  436. cc(3,:) = [1 0.25 0.25];
  437. cc(4,:) = [1 0.25 0.25];
  438. cc(5,:) = [0.1 0.6 1];
  439. cc(6,:) = [0.1 0.6 1];
  440. cc(7,:) = [0.1 0.6 1];
  441. cc(8,:) = [0.1 0.6 1];
  442. cc(9,:) = [0.85 0 0];
  443. cc(10,:) = [0.85 0 0];
  444. cc(11,:) = [0.85 0 0];
  445. cc(12,:) = [0.85 0 0];
  446. cc(13,:) = [0 0 0.96];
  447. cc(14,:) = [0 0 0.96];
  448. cc(15,:) = [0 0 0.96];
  449. cc(16,:) = [0 0 0.96];
  450. cc(17,:) = [0 0 0];
  451. cc(18,:) = [0 0 0];
  452. fr = [8 57 694 158];
  453. str{1} = 'Fp2-F4'; % Fp2-F4, Fp2-F4
  454. str{2} = 'F4-C4'; % F4-C4, F4-C4
  455. str{3} = 'C4-P4'; % C4-P4, C4-P4
  456. str{4} = 'P4-O2'; % P4-O2, P4-O2
  457. str{5} = 'Fp1-F3'; % Fp1-F3, Fp1-F3
  458. str{6} = 'F3-C3'; % F3-C3, F3-C3
  459. str{7} = 'C3-P3'; % C3-P3, C3-P3
  460. str{8} = 'P3-O1'; % P3-O1, P3-O1
  461. str{9} = 'Fp2-F8'; % Fp2-F8, Fp2-F8
  462. str{10} = 'F8-T4'; % F8-T4, F8-T8
  463. str{11} = 'T4-T6'; % T4-T6, T8-P8
  464. str{12} = 'T6-O2'; % T6-O2, P8-O2
  465. str{13} = 'Fp1-F7'; % Fp1-F7, Fp1-F7
  466. str{14} = 'F7-T3'; % F7-T3, F7-T7
  467. str{15} = 'T3-T5'; % T3-T5, T7-P7
  468. str{16} = 'T5-O1'; % T5-O1, P7-O1
  469. str{17} = 'Fz-Cz'; % Fz-Cz, Fz-Cz
  470. str{18} = 'Cz-Pz'; % Cz-Pz, Cz-Pz
  471. str{19} = 'ECG';
  472. % START PLOTTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  473. figure
  474. subplot(2,2,1); hold on
  475. [dat, hdr, label, fs, scle, offs] = read_edf(fnames{fr(1)});
  476. [data_bp_mont, ecg] = read_into_montage(dat, label, scle, fs, fs1, 0);
  477. dbp = filtfilt(B,A, data_bp_mont')';
  478. t = linspace(0,8, length(r1:r2));
  479. for jj = 1:18
  480. plot(t, dbp(jj,r1:r2)-jj*100, 'color', cc(jj,:))
  481. end
  482. plot(t, (ecg(r1:r2)-median(ecg(r1:r2)))./10-(jj+1)*100, 'Color', [0 0.6 0])
  483. set(gca, 'Ytick', [-1900:100:-100], 'Yticklabel', str(19:-1:1), 'Xticklabel', {})
  484. axis([0 8 -2000 0])
  485. set(gca, 'Position', [0.075 0.535 0.435 0.45], 'fontname', 'times', 'fontsize', 10)
  486. text(0.175, -150, 'A', 'BackgroundColor', [1 1 1], 'fontname', 'times', 'fontsize', 14)
  487. subplot(2,2,2); hold on
  488. [dat, hdr, label, fs, scle, offs] = read_edf(fnames{fr(2)});
  489. [data_bp_mont, ecg] = read_into_montage(dat, label, scle, fs, fs1, 0);
  490. dbp = filtfilt(B,A, data_bp_mont')';
  491. t = linspace(0,8, length(r1:r2));
  492. for jj = 1:18
  493. plot(t, dbp(jj,r1:r2)-jj*100, 'color', cc(jj,:))
  494. end
  495. plot(t, (ecg(r1:r2)-median(ecg(r1:r2)))./20-(jj+1)*100, 'Color', [0 0.6 0])
  496. set(gca, 'Ytick', [-1900:100:-100], 'Yticklabel', {}, 'Xticklabel', {})
  497. axis([0 8 -2000 0])
  498. set(gca, 'Position', [0.55 0.535 0.435 0.45], 'fontname', 'times', 'fontsize', 10)
  499. text(0.175, -150, 'B', 'BackgroundColor', [1 1 1], 'fontname', 'times', 'fontsize', 14)
  500. subplot(2,2,3); hold on
  501. [dat, hdr, label, fs, scle, offs] = read_edf(fnames{fr(3)});
  502. [data_bp_mont, ecg] = read_into_montage(dat, label, scle, fs, fs1, 0);
  503. dbp = filtfilt(B,A, data_bp_mont')';
  504. t = linspace(0,8, length(r1:r2));
  505. for jj = 1:18
  506. plot(t, dbp(jj,r1:r2)-jj*100, 'color', cc(jj,:))
  507. end
  508. plot(t, (ecg(r1:r2)-median(ecg(r1:r2)))./10-(jj+1)*100, 'Color', [0 0.6 0])
  509. set(gca, 'Ytick', [-1900:100:-100], 'Yticklabel', str(19:-1:1))
  510. axis([0 8 -2000 0])
  511. set(gca, 'Position', [0.075 0.075 0.435 0.45], 'fontname', 'times', 'fontsize', 10)
  512. xlabel('time (s)')
  513. text(0.175, -150, 'C', 'BackgroundColor', [1 1 1], 'fontname', 'times', 'fontsize', 14)
  514. subplot(2,2,4); hold on
  515. [dat, hdr, label, fs, scle, offs] = read_edf(fnames{fr(4)});
  516. [data_bp_mont, ecg] = read_into_montage(dat, label, scle, fs, fs1, 0);
  517. dbp = filtfilt(B,A, data_bp_mont')';
  518. t = linspace(0,8, length(r1:r2));
  519. for jj = 1:18
  520. plot(t, dbp(jj,r1:r2)-jj*100, 'color', cc(jj,:))
  521. end
  522. plot(t, (ecg(r1:r2)-median(ecg(r1:r2)))./10-(jj+1)*100, 'Color', [0 0.6 0])
  523. set(gca, 'Ytick', [-1900:100:-100], 'Yticklabel', {})
  524. axis([0 8 -2000 0])
  525. set(gca, 'Position', [0.55 0.075 0.435 0.45], 'fontname', 'times', 'fontsize', 10)
  526. xlabel('time (s)')
  527. text(0.175, -150, 'D', 'BackgroundColor', [1 1 1], 'fontname', 'times', 'fontsize', 14)
  528. plot([1.5 1.5 2.5], [-950 -1050 -1050], 'k', 'LineWidth', 1)
  529. % END PLOTTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  530. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  531. %
  532. % ECG ANALYSIS
  533. %
  534. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  535. filename = 'anon_codex_age_sex.csv';
  536. % Specify range and delimiter
  537. dataLines = [2, Inf];
  538. opts = delimitedTextImportOptions("NumVariables", 3);
  539. opts.DataLines = dataLines;
  540. opts.Delimiter = ",";
  541. opts.VariableNames = ["AnonFilename", "QuantizedAgeyears", "QuantizedSex"];
  542. opts.VariableTypes = ["string", "double", "categorical"];
  543. opts.ExtraColumnsRule = "ignore";
  544. opts.EmptyLineRule = "read";
  545. opts = setvaropts(opts, "AnonFilename", "WhitespaceRule", "preserve");
  546. opts = setvaropts(opts, ["AnonFilename", "QuantizedSex"], "EmptyFieldRule", "auto");
  547. % Import the data
  548. anoncodex = readtable(filename, opts);
  549. fnames = cellstr(anoncodex{:,1});
  550. ages = anoncodex{:,2};
  551. sex = anoncodex{:,3};
  552. % BASIC EVALUATIONS
  553. load('artefact_detection_models.mat');
  554. fs1 = 250; fs2 = 12; epl = 5*60*fs1; olap = 30*fs1;
  555. [Bn0,An0] = butter(4, 2*2/fs1, 'high');
  556. [Bn1,An1] = butter(2, 2*[48 52]/fs1 , 'stop');
  557. [Bn2,An2] = butter(2, 2*[98 102]/fs1 , 'stop');
  558. % CALCULATE HRV FEATURES FROM 5-minute epochs of ECG
  559. tadj = fs1*10; % correct for any poential end effects
  560. feat = cell(length(fnames),2);
  561. for ii = 1:length(fnames)
  562. ii
  563. [dat, hdr, label, fs, scle, offs] = read_edf(fnames{ii});
  564. [ecg, fs] = read_into_montage_ecg(dat, label, scle, fs);
  565. ecg = resample(ecg, fs1, fs);
  566. ecg = filtfilt(Bn1, An1, ecg); ecg = filtfilt(Bn2, An2, ecg); % notch at 50 notch at 100
  567. ecg = filtfilt(Bn0,An0, ecg);
  568. block_no = floor(length(ecg)/olap)-epl/olap+1; fts = NaN*ones(block_no,38);
  569. MM = (floor(length(ecg)/fs1/2))*2;
  570. flag1 = 0; flag2 = 0;
  571. fts = NaN*ones(block_no, 38); ag = NaN*ones(block_no,1);
  572. try
  573. for jj = 1:block_no
  574. r1 = (jj-1)*olap+1-tadj; r2 = r1+epl-1+2*tadj;
  575. if r1<1; r1 = 1; flag1 = 1; end; if r2>MM*fs1; r2 = MM*fs1; flag2 = 1; end
  576. ecg1 = ecg(r1:r2); ecg2 = ecg((jj-1)*olap+1:(jj-1)*olap+epl);
  577. if flag1 == 1; ecg1 = [zeros(1,tadj) ecg1]; end
  578. if flag2 == 1; ecg1 = [ecg1 zeros(1,tadj)]; end
  579. qts = quantile(ecg1, [0.01 0.99]); if abs(qts(1))>abs(qts(2)); ecg1 = -ecg1; end
  580. qts = quantile(ecg2, [0.01 0.99]); if abs(qts(1))>abs(qts(2)); ecg2 = -ecg2; end
  581. afts = calculate_features_ecg(ecg2, fs1);
  582. [~, out1] = predict(Mdl1, afts); [~, out2] = predict(Mdl2, afts); [~, out3] = predict(Mdl3, afts);
  583. if (out1(2) < 0) && (out2(2) < 0.5) && (out3(2) < 0)
  584. [~, rr, ~] = pan_tompkin_adapt(ecg1,fs1);
  585. rr(rr<=tadj)=0; rr(rr>=epl+tadj)=0;
  586. rr = rr(rr>0);
  587. if (length(rr)>200) && (length(rr)<900)
  588. fts(jj,:) = calculate_features_valid(rr, fs);
  589. ag(jj) = ages(ii);
  590. end
  591. end
  592. end
  593. feat{ii,1} = fts;
  594. feat{ii,2} = ag;
  595. catch
  596. end
  597. end
  598. save('ecg_features_online_data.mat', 'feat', '-v7.3');
  599. load('ecg_features_online_data.mat');
  600. % Find outliers
  601. fv1 = NaN*ones(length(feat), 38); fv2 = fv1; age = zeros(length(feat),1);
  602. for ii = 1:length(feat)
  603. fts = feat{ii,1};
  604. fv1(ii,:) = median(fts(1:2,:));
  605. fv2(ii,:) = median(fts(11:end,:));
  606. age(ii) = feat{ii,2}(1);
  607. end
  608. rf = find(~isnan(age) & ~isnan(sum(fv1'))' & ~isnan(sum(fv2'))');
  609. fv1 = fv1(rf,:);
  610. fv2 = fv2(rf,:);
  611. age = age(rf,:);
  612. rfs = zeros(1,length(fv1));
  613. for jj = 1:38
  614. y = fv1(:,jj); x = age;
  615. B = polyfit(x,y,2);
  616. res = y - polyval(B, x);
  617. dum = zeros(1, length(y)); dum(find(abs(res)>6*std(res)))=1;
  618. rfs = rfs+dum;
  619. y = fv2(:,jj); x = age;
  620. B = polyfit(x,y,2);
  621. res = y - polyval(B, x);
  622. dum = zeros(1, length(y)); dum(find(abs(res)>6*std(res)))=1;
  623. rfs = rfs+dum;
  624. end
  625. % remove outliers
  626. nref = find(rfs==0);
  627. fv1 = fv1(nref,:);
  628. fv2 = fv2(nref,:);
  629. age = age(nref);
  630. % TRAIN GPR age predictor - 5 fold CV 80:20 split
  631. pid_in1 = 1:length(fv1);
  632. pma_in1 = age;
  633. Mc = 5;
  634. out = zeros(1,1000);
  635. for qq = 1:1000
  636. rng(qq)
  637. pd = unique(pid_in1);
  638. y = cell(1,Mc);
  639. rx = ones(1,length(pd)); %rt = 1-rx; %rr = 1:length(pid);
  640. K = floor(length(pd)/Mc); dum = rem(length(pd), Mc);
  641. K = K.*ones(1,Mc); K(1:dum) = K(1)+1;
  642. for ii = 1:Mc
  643. rz = find(rx==1);
  644. dum = randsample(length(rz), K(ii), false);
  645. rx(rz(dum)) = 0;
  646. y{ii} = rz(dum);
  647. end
  648. y{end} = [y{end}' ; find(rx==1)']';
  649. for ii = 1:Mc
  650. y{ii} = pd(y{ii});
  651. end
  652. ss = cell(1, Mc);
  653. for ii = 1:Mc
  654. rf = y{ii};
  655. ag = [];
  656. for jj = 1:length(rf); ag = [ag pma_in1(find(pid_in1==rf(jj)))]; end
  657. ss{ii} = ag;
  658. end
  659. pv = zeros(1,6); c1 = 1;
  660. for ii = 1:Mc
  661. for jj = ii+1:Mc
  662. [~, pv(c1)] = kstest2(ss{ii}, ss{jj});
  663. c1 = c1+1;
  664. end
  665. end
  666. out(qq) = mean(pv);
  667. end
  668. nr = find(out==max(out)); % nr = 7
  669. rng(nr)
  670. yr = cell(1,Mc);
  671. rx = ones(1,length(pd)); %rt = 1-rx; %rr = 1:length(pid);
  672. for ii = 1:Mc
  673. rz = find(rx==1);
  674. dum = randsample(length(rz), K(ii), false);
  675. rx(rz(dum)) = 0;
  676. yr{ii} = rz(dum);
  677. end
  678. yr{end} = [yr{end}' ; find(rx==1)']';
  679. for ii = 1:Mc; yr{ii} = pd(yr{ii}); end
  680. pred1 = []; pred2 = []; agx = [];
  681. for ii = 1:Mc
  682. ii
  683. dum = zeros(1,length(fv1));
  684. dum(yr{ii})=1;
  685. r1 = find(dum==1); r2 = find(dum==0);
  686. rGP1 = fitrgp(fv1(r2,:), age(r2), 'BasisFunction', 'constant', 'KernelFunction', 'matern52', 'Standardize', true);
  687. out1 = predict(rGP1, fv1(r1,:));
  688. pred1 = [pred1 ; out1];
  689. rGP2 = fitrgp(fv2(r2,:), age(r2), 'BasisFunction', 'constant', 'KernelFunction', 'matern52', 'Standardize', true);
  690. out2 = predict(rGP1, fv2(r1,:));
  691. pred2 = [pred2 ; out2];
  692. agx = [agx ; age(r1)];
  693. end
  694. % START PLOTTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  695. figure;
  696. subplot(1,2,1)
  697. plot(agx, pred1 ,'.')
  698. title('Pre- N2 Onset')
  699. set(gca, 'FontName', 'times', 'Fontsize', 16)
  700. xlabel('Age (y)'); ylabel('Predicted Age (y)')
  701. grid on; hold on;
  702. plot([-2 18], [-2, 18], 'k')
  703. axis([-1 17 -1, 17])
  704. set(gca, 'position', [0.075 0.15 0.4 0.8], 'Xtick', [0:2:16], 'Ytick', [0:2:16])
  705. %text(0, 16, 'A', 'FontName', 'times', 'Fontsize', 14)
  706. pp = corr(agx(~isnan(agx)), pred1(~isnan(agx)));
  707. text(10, 2, ['r = ' num2str(pp, '%1.3f')], 'FontName', 'times', 'FontSize', 16)
  708. subplot(1,2,2)
  709. plot(agx, pred2 ,'.')
  710. title('Post- N2 Onset')
  711. set(gca, 'FontName', 'times', 'Fontsize', 16)
  712. xlabel('Age (y)'); ylabel('Predicted Age (y)')
  713. grid on; hold on;
  714. plot([-2 18], [-2, 18], 'k')
  715. axis([-1 17 -1, 17])
  716. set(gca, 'position', [0.575 0.15 0.4 0.8], 'Xtick', [0:2:16], 'Ytick', [0:2:16])
  717. %text(0, 16, 'B', 'FontName', 'times', 'Fontsize', 14)
  718. pp = corr(agx(~isnan(agx)), pred2(~isnan(agx)));
  719. text(10, 2, ['r = ' num2str(pp, '%1.3f')], 'FontName', 'times', 'FontSize', 16)
  720. % END PLOTTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  721. % just artefact stuff
  722. filename = 'anon_codex_age_sex.csv';
  723. % Specify range and delimiter
  724. dataLines = [2, Inf];
  725. opts = delimitedTextImportOptions("NumVariables", 3);
  726. opts.DataLines = dataLines;
  727. opts.Delimiter = ",";
  728. opts.VariableNames = ["AnonFilename", "QuantizedAgeyears", "QuantizedSex"];
  729. opts.VariableTypes = ["string", "double", "categorical"];
  730. opts.ExtraColumnsRule = "ignore";
  731. opts.EmptyLineRule = "read";
  732. opts = setvaropts(opts, "AnonFilename", "WhitespaceRule", "preserve");
  733. opts = setvaropts(opts, ["AnonFilename", "QuantizedSex"], "EmptyFieldRule", "auto");
  734. % Import the data
  735. anoncodex = readtable(filename, opts);
  736. fnames = cellstr(anoncodex{:,1});
  737. ages = anoncodex{:,2};
  738. sex = anoncodex{:,3};
  739. % BASIC EVALUATIONS
  740. load('artefact_detection_models.mat');
  741. fs1 = 250; fs2 = 12; epl = 5*60*fs1; olap = epl;
  742. [Bn0,An0] = butter(4, 2*2/fs1, 'high');
  743. [Bnx,Anx] = butter(4, 1/fs1, 'high');
  744. [Bn1,An1] = butter(2, 2*[48 52]/fs1 , 'stop');
  745. [Bn2,An2] = butter(2, 2*[98 102]/fs1 , 'stop');
  746. W = floor(fs1/3);
  747. tadj = fs1*10; % correct for any poential end effects
  748. feat = cell(length(fnames),3);
  749. fband = [0.5 1 ; 1 3 ; 3 25 ; 25 125]; df = diff(fband');
  750. for ii = 1:length(fnames)
  751. ii
  752. [dat, hdr, label, fs, scle, offs] = read_edf(fnames{ii});
  753. [ecg, fs] = read_into_montage_ecg(dat, label, scle, fs);
  754. ecg = resample(ecg, fs1, fs);
  755. ecg = filtfilt(Bn1, An1, ecg); ecg = filtfilt(Bn2, An2, ecg); % notch at 50 notch at 100
  756. ecg0 = filtfilt(Bnx, Anx, ecg);
  757. ecg = filtfilt(Bn0,An0, ecg);
  758. block_no = floor(length(ecg)/olap)-epl/olap+1; fts = NaN*ones(block_no,38);
  759. MM = (floor(length(ecg)/fs1/2))*2;
  760. flag1 = 0; flag2 = 0;
  761. fts = NaN*ones(block_no, 38); ag = NaN*ones(block_no,1);
  762. try
  763. artx1 = []; artx2 = []; artx3 = []; c1 = 0;
  764. pow = zeros(block_no,4);
  765. for jj = 1:block_no
  766. r1 = (jj-1)*olap+1-tadj; r2 = r1+epl-1+2*tadj;
  767. if r1<1; r1 = 1; flag1 = 1; end; if r2>MM*fs1; r2 = MM*fs1; flag2 = 1; end
  768. ecg1 = ecg(r1:r2); ecg2 = ecg((jj-1)*olap+1:(jj-1)*olap+epl);
  769. %spectral_analysis
  770. [Pxx, f] = pwelch(ecg2, hamming(2^13), 2^12, 2^13, fs1);
  771. for qq = 1:4
  772. rf = find(f>=fband(qq,1) & f<fband(qq,2));
  773. pow(jj,qq) = sum(Pxx(rf))./df(qq);
  774. end
  775. if flag1 == 1; ecg1 = [zeros(1,tadj) ecg1]; end
  776. if flag2 == 1; ecg1 = [ecg1 zeros(1,tadj)]; end
  777. qts = quantile(ecg1, [0.01 0.99]); if abs(qts(1))>abs(qts(2)); ecg1 = -ecg1; end
  778. qts = quantile(ecg2, [0.01 0.99]); if abs(qts(1))>abs(qts(2)); ecg2 = -ecg2; end
  779. afts = calculate_features_ecg(ecg2, fs1);
  780. [~, out1] = predict(Mdl1, afts); [~, out2] = predict(Mdl2, afts); [~, out3] = predict(Mdl3, afts);
  781. if (out1(2) < 0) && (out2(2) < 0.5) && (out3(2) < 0)
  782. c1 = c1+1;
  783. [~, rr, ~, art1, art2, art3] = pan_tompkin_adapt_count_error(ecg1,fs1);
  784. artx1(c1,:) = art1;
  785. artx2(c1,:) = art2;
  786. if isempty(art3); artx3(c1,:) = [0 length(rr)]; else; artx3(c1,:) = [art3 length(rr)]; end
  787. end
  788. end
  789. feat{ii,1} = artx2; feat{ii,2} = artx3;
  790. feat{ii,3} = pow;
  791. catch
  792. end
  793. end
  794. save('artefact_features_online_data.mat', 'feat', '-v7.3');
  795. seg_out = []; nn_adj = []; flag_bad = zeros(length(feat),2); pow = [];
  796. for ii = 1:length(feat)
  797. A1 = size(feat{ii,3}); A2 = size(feat{ii,2});
  798. if isempty(feat{ii,2})
  799. flag_bad(ii,:) = [A1(1) 0];
  800. else
  801. flag_bad(ii,:) = [A1(1) A2(1)];
  802. end
  803. dum = feat{ii,1};
  804. if ~isempty(dum)
  805. dum(isnan(dum(:,2)),2) = 0;
  806. seg_out = [seg_out ; dum];
  807. nn_adj = [nn_adj ; feat{ii,2}];
  808. end
  809. pow = [pow; feat{ii,3}];
  810. end

quality_assesssment_for_github.m at commit 5619620, under MIT · at the source

Overview

Authors: Nathan J. Stevenson1, Kartik K. Iyer1, James A. Roberts1, Eero Ahtola2, Leena Lauronen2, Sampsa Vanhatalo2,3,4
  1. Brain Modelling Group, QIMR Berghofer,Brisbane, Australia
  2. Clinical Neurophysiology, New Children’s Hospital, Helsinki University Hospital and University of Helsinki,Helsinki, Finland
  3. Paediatric Research Center, New Children’s Hospital, Helsinki University Hospital,Helsinki, Finland
  4. BABA Center, Department of Physiology, University of Helsinki,Helsinki, Finland
Journal: Scientific data, volume 13, issue 1, article 1018
Dates: received 24 October 2025; accepted 28 April 2026; published online 5 May 2026
Type: Data paper · Language: English
License: CC BY
Identifiers: DOI 10.1038/s41597-026-07356-3 · PMID 42086555 · PMCID PMC13350081 · OpenAlex W7160335086
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: EEG (modality), other (modality), human (organism), methods / tools (subfield)
Methods: Preprocessing, Evoked potentials, Physiology & signal measures
MeSH: Electrocardiography*, Electroencephalography*, Sleep*, Sleep Stages*, Adolescent, Brain, Child, Child, Preschool, Humans, Infant (* major topic)
Journal subjects: Data Descriptor
Topic: EEG and Brain-Computer Interfaces (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Citations: cited by 2 papers (Europe PMC); 16 references in the paper

Abstract

Paediatric brain activity can be measured effectively during light sleep; a vigilance state that manifests with similar phenomenology on the EEG across childhood. Here, we describe a curated dataset of EEG and ECG recordings from 1032 subjects from 2 months to 16 years of age (Helsinki Kids 1 K – HK1K). All subjects had age-appropriate EEG and ECG recordings, along with typical neurodevelopment, as confirmed by a clinical review of their medical records over the four years following the recording. These data can be used to define normative ranges of paediatric EEG/ECG, train foundation models of paediatric EEG/ECG, and generate age prediction algorithms that underpin measures of brain age gap.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 9 matches between paragraphs and lines of code.

nstevensonUH/EEG_release_supporting_code

License: MIT
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: 56196206b14d9d100f88a428efd65c73ea1e3b40, 15 October 2025
Languages: MATLAB (33)
Size: 36 files, 33 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
35 files

sccn.ucsd.edu/eeglab/index.php

License: none: the authors keep all their rights
State: the link answers, verified on 28 September 2026
Evidence: the link answers
Software Heritage: not checked
Found in: the text, “Usage Notes”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 28 September 2026: the link answers (HTTP 200)
  • 28 September 2026: the link answers (HTTP 200)

Code availability

MATLAB code that assists in accessing the EEG and ECG recordings within this dataset, and reproduces all analyses undertaken in this data descriptor, is available on Github (https://github.com/nstevensonUH/EEG_release_supporting_code).

Reproduced under the paper's license (CC BY), from the paper cited above.

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:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 33 scripts, each with its path and the digest of its content;
  • 9 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

Datasets cited

Data availability

The dataset is freely available to access at Zenodo (10.5281/zenodo.17138539).

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, 28 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 6 authors, 10 MeSH terms, 2 funders, 15 references.

Cite

This paper

Stevenson, N. J., Iyer, K. K., Roberts, J. A., Ahtola, E., Lauronen, L., & Vanhatalo, S. (2026). A dataset of EEG and ECG recordings around the onset of NREM sleep from infancy to adolescence. Scientific data, 13(1), 1018. https://doi.org/10.1038/s41597-026-07356-3

BibTeX

@article{stevenson2026dataset,
author = {Stevenson, Nathan J. and Iyer, Kartik K. and Roberts, James A. and Ahtola, Eero and Lauronen, Leena and Vanhatalo, Sampsa},
title = {{A dataset of EEG and ECG recordings around the onset of NREM sleep from infancy to adolescence}},
journal = {Scientific data},
year = {2026},
month = may,
volume = {13},
number = {1},
pages = {1018},
publisher = {Nature Publishing Group},
issn = {2052-4463},
doi = {10.1038/s41597-026-07356-3},
url = {https://doi.org/10.1038/s41597-026-07356-3},
pmid = {42086555},
pmcid = {PMC13350081}
}

RIS

TY - JOUR
AU - Stevenson, Nathan J.
AU - Iyer, Kartik K.
AU - Roberts, James A.
AU - Ahtola, Eero
AU - Lauronen, Leena
AU - Vanhatalo, Sampsa
TI - A dataset of EEG and ECG recordings around the onset of NREM sleep from infancy to adolescence
T2 - Scientific data
J2 - Sci Data
PY - 2026
DA - 2026/05/05
VL - 13
IS - 1
SP - 1018
SN - 2052-4463
PB - Nature Publishing Group
DO - 10.1038/s41597-026-07356-3
UR - https://doi.org/10.1038/s41597-026-07356-3
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41597-026-07356-3",
"type": "article-journal",
"title": "A dataset of EEG and ECG recordings around the onset of NREM sleep from infancy to adolescence",
"container-title": "Scientific data",
"author": [
{
"family": "Stevenson",
"given": "Nathan J."
},
{
"family": "Iyer",
"given": "Kartik K."
},
{
"family": "Roberts",
"given": "James A."
},
{
"family": "Ahtola",
"given": "Eero"
},
{
"family": "Lauronen",
"given": "Leena"
},
{
"family": "Vanhatalo",
"given": "Sampsa"
}
],
"container-title-short": "Sci Data",
"volume": "13",
"issue": "1",
"page": "1018",
"DOI": "10.1038/s41597-026-07356-3",
"PMID": "42086555",
"PMCID": "PMC13350081",
"ISSN": "2052-4463",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41597-026-07356-3",
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
5
]
]
}
}

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.1093/sleep/zsaf410 [code]
Does twitch-spindle coupling differ between N2 and N3 sleep in 6-month-olds?
Journal: Sleep
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, EEG, 2 references
[2] doi:10.1007/s12021-026-09810-4 [code]
Meta-Analysis of Face-Validity Indicators in Automatically Detected Dog Sleep Spindles.
Journal: Neuroinformatics
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, methods / tools, EEG
[3] doi:10.1038/s41597-026-07807-x [code]
A Multimodal fNIRS-EEG Dataset for Unilateral Limb Motor Imagery.
Journal: Scientific data
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, methods / tools, EEG
[4] doi:10.1002/hbm.70599 [code]
Group Joint ICA (gjICA): A Method for Multimodal Fusion of Concurrent EEG and fMRI Data.
Journal: Human brain mapping
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, methods / tools, EEG
[5] doi:10.1371/journal.pone.0352191 [code]
Bayesian Uncertainty-aware Deep Learning with noisy labels: Tackling annotation ambiguity in EEG seizure detection.
Journal: PloS one
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, methods / tools, EEG
[6] doi:10.1038/s41598-026-52322-z [code]
A transparent wheel-based platform for locomotion-on-demand and multi-view body and facial kinematics in head-fixed mice.
Journal: Scientific reports
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, other, methods / tools
[7] doi:10.64898/2026.05.08.26348885 [code]
Insights from nine nights of self-applied, low-density sleep EEG during sleep restriction therapy: a proof-of-concept evaluation
Journal: medRxiv (preprint)
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, other, EEG
[8] doi:10.1093/braincomms/fcag204 [code]
Altered rhythmic and arrhythmic electroencephalographic activity during non-rapid eye movement sleep in amnestic mild cognitive impairment.
Journal: Brain communications
In common: Statistics and Machine Learning Toolbox, EEG, 1 reference
[9] doi:10.1002/hbm.70602 [code]
Neuroimaging Correlates of Post-Stroke Pain After Ischemic Stroke: Secondary Analysis of the INSPiRE-TMS Trial.
Journal: Human brain mapping
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, other
[10] doi:10.1126/sciadv.aec9837 [code]
AI-driven tripartite classification for optimizing wearable bioelectronics in depression management.
Journal: Science advances
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, other

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.

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: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.