diff --git a/Matlab/eeg_load_xdf.m b/Matlab/eeg_load_xdf.m index f344bd5..ac14ed3 100644 --- a/Matlab/eeg_load_xdf.m +++ b/Matlab/eeg_load_xdf.m @@ -13,7 +13,10 @@ % (default: 'EEG') % % 'effective_rate' : if true, use the effective sampling rate instead of the nominal -% sampling rate (as declared by the device) (default: false) +% sampling rate (as declared by the device). Note that using +% effective_rate can lead to incorrect results if the nominal +% sampling rate is 0 (i.e. non constant sample interval) +% (default: false) % % 'exclude_markerstreams' : can be a cell array of stream names to exclude from % use as marker streams (default: {}) diff --git a/Matlab/xdf/load_xdf.m b/Matlab/xdf/load_xdf.m index 0792c17..4409d6d 100644 --- a/Matlab/xdf/load_xdf.m +++ b/Matlab/xdf/load_xdf.m @@ -348,6 +348,7 @@ if temp(id).srate > 0 temp(id).sampling_interval = 1/temp(id).srate; else + warning('Nominal sampling rate of stream %s is 0. Calculated effective sampling rate might not be meaningful, relying on this rate is not recommended.', header.info.name); temp(id).sampling_interval = 0; end % fread parsing format for data values @@ -552,10 +553,10 @@ end % calculate the weighted mean sampling rate over all segments - temp(k).effective_rate = sum(bsxfun(@times,[segments.effective_srate],[segments.num_samples]/sum([segments.num_samples]))); + temp(k).effective_srate = sum(bsxfun(@times,[segments.effective_srate],[segments.num_samples]/sum([segments.num_samples]))); % transfer the information into the output structs - streams{k}.info.effective_srate = temp(k).effective_rate; + streams{k}.info.effective_srate = temp(k).effective_srate; streams{k}.segments = segments; end end @@ -563,7 +564,14 @@ else % calculate effective sampling rate for k=1:length(temp) - temp(k).effective_srate = (length(temp(k).time_stamps) - 1) / (temp(k).time_stamps(end) - temp(k).time_stamps(1)); end + if length(temp(k).time_stamps) > 0 + temp(k).effective_srate = (length(temp(k).time_stamps) - 1) / (temp(k).time_stamps(end) - temp(k).time_stamps(1)); + else + temp(k).effective_srate = 0; + end + % transfer the information into the output structs + streams{k}.info.effective_srate = temp(k).effective_srate; + end end % copy the information into the output