Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute effective sampling rate even when nominal rate is 0 + better handle empty streams. #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Matlab/eeg_load_xdf.m
Original file line number Diff line number Diff line change
Expand Up @@ -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: {})
Expand Down
14 changes: 11 additions & 3 deletions Matlab/xdf/load_xdf.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -552,18 +553,25 @@
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
end
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
Expand Down