From 7cfd075883b0429199ff044e9a22456ba5555fcf Mon Sep 17 00:00:00 2001 From: jfrey Date: Fri, 1 Dec 2017 18:55:25 +0200 Subject: [PATCH 1/2] Compute effective sampling rate even when nominal is 0 Fix crash when used with eeglab associataed functions. --- Matlab/xdf/load_xdf.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Matlab/xdf/load_xdf.m b/Matlab/xdf/load_xdf.m index 0792c17..bd9001c 100644 --- a/Matlab/xdf/load_xdf.m +++ b/Matlab/xdf/load_xdf.m @@ -552,10 +552,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 +563,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 From e95ef68b0ea6f644cceeb036cbbd9662621f1fdb Mon Sep 17 00:00:00 2001 From: jfrey Date: Fri, 1 Dec 2017 21:28:46 +0200 Subject: [PATCH 2/2] Add a warning about effective srate when nominal is 0. --- Matlab/eeg_load_xdf.m | 5 ++++- Matlab/xdf/load_xdf.m | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) 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 bd9001c..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