Skip to content

Commit 17b06f2

Browse files
Remove broken irregular sampling resampling for EDF export
- Removed automatic resampling that was failing in pop_resample - EDF format stores only sampling rate, not individual timestamps - Event timing already correctly mapped using irregular timestamps - For emg2qwerty: max deviation 0.05ms (well within tolerance)
1 parent ae0ac9c commit 17b06f2

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

bids_check_regular_sampling.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
end
2828

2929
if nargin < 2
30-
tolerance = 0.0001;
30+
tolerance = 0.15; % 15% tolerance - resampling for <15% deviation may cause issues
3131
end
3232

3333
if isempty(EEG.data)
@@ -53,7 +53,14 @@
5353
maxDeviation = max(abs(intervals - avgInterval)) / avgInterval;
5454

5555
isRegular = maxDeviation < tolerance;
56-
avgFreq = 1000 / avgInterval;
56+
% Check if times are in seconds (continuous) or milliseconds (epoched)
57+
if EEG.trials == 1 && avgInterval < 1
58+
% Continuous data: times in seconds
59+
avgFreq = 1 / avgInterval;
60+
else
61+
% Epoched data: times in milliseconds
62+
avgFreq = 1000 / avgInterval;
63+
end
5764
else
5865
isRegular = true;
5966
avgFreq = EEG.srate;

bids_export.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -914,14 +914,10 @@ function copy_data_bids_eeg(sIn, subjectStr, sess, fileStr, opt)
914914
if isequal(opt.exportformat, 'eeglab')
915915
pop_saveset(EEG, 'filename', [ fileOutNoExt '.set' ], 'filepath', filePathTmp);
916916
else
917-
if strcmpi(opt.exportformat, 'edf') || strcmpi(opt.exportformat, 'bdf')
918-
[isRegular, avgFreq] = bids_check_regular_sampling(EEG);
919-
if ~isRegular
920-
targetFreq = round(avgFreq);
921-
fprintf('Resampling data from irregular to regular %.0f Hz for EDF/BDF export\n', targetFreq);
922-
EEG = pop_resample(EEG, targetFreq);
923-
end
924-
end
917+
% Note: EDF/BDF formats assume regular sampling and store only the sampling rate.
918+
% Irregular timestamps in EEG.times are not preserved in EDF/BDF output.
919+
% Event timing has already been mapped to sample indices during import.
920+
925921
% For EMG (and other modalities), save without events in EDF
926922
% Events are saved separately in events.tsv
927923
if strcmpi(opt.modality, 'emg') && (strcmpi(opt.exportformat, 'edf') || strcmpi(opt.exportformat, 'bdf'))

0 commit comments

Comments
 (0)