Skip to content

Commit

Permalink
Bugfix: Correct sfreq when reading EDF files
Browse files Browse the repository at this point in the history
  • Loading branch information
rcassani committed Dec 13, 2022
1 parent 232af6a commit 2b8d016
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions toolbox/io/in_fread_edf.m
Expand Up @@ -35,11 +35,6 @@
if (nargin < 4) || isempty(ChannelsRange)
ChannelsRange = [1, nChannels];
end
if (nargin < 3) || isempty(SamplesBounds)
SamplesBounds = [0, sFile.header.nrec * sFile.header.signal(ChannelsRange(1)).nsamples - 1];
end
nTimes = round(sFile.header.reclen * sFile.header.signal(ChannelsRange(1)).sfreq);
iTimes = SamplesBounds(1):SamplesBounds(2);
% Block of times/channels to extract
nReadChannels = double(ChannelsRange(2) - ChannelsRange(1) + 1);
% Read annotations instead of real data ?
Expand Down Expand Up @@ -73,6 +68,18 @@
end
end

if (nargin < 3) || isempty(SamplesBounds)
SamplesBounds = [0, sFile.header.nrec * sFile.header.signal(ChannelsRange(1)).nsamples - 1];
end
% Convert SamplesBounds to the correct sampling frequency
if sFile.header.signal(ChannelsRange(1)).sfreq ~= sFile.prop.sfreq
SamplesBounds(2) = SamplesBounds(2) + 1;
TimesBounds = SamplesBounds ./ sFile.prop.sfreq;
SamplesBounds = round(TimesBounds * sFile.header.signal(ChannelsRange(1)).sfreq);
SamplesBounds(2) = SamplesBounds(2) - 1;
end
nTimes = round(sFile.header.reclen * sFile.header.signal(ChannelsRange(1)).sfreq);
iTimes = SamplesBounds(1):SamplesBounds(2);

%% ===== READ ALL NEEDED EPOCHS =====
% Detect which epochs are necessary for the range of data selected
Expand Down

0 comments on commit 2b8d016

Please sign in to comment.