Skip to content

Commit

Permalink
Bug fix: Muse EEG reader (more fixes...)
Browse files Browse the repository at this point in the history
  • Loading branch information
ftadel committed Mar 19, 2019
1 parent a2b6312 commit eebf072
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions toolbox/io/in_data_muse_csv.m
Expand Up @@ -85,21 +85,37 @@
% Replace all commas "," with dots "." in the values
RecMat(RecMat == ',') = '.';
% Parse the fixed string
RecMat = textscan(RecMat, strFormat, 'Delimiter', colSeparator);
RecMat = textscan(RecMat, strFormat, 'Delimiter', colSeparator, 'TreatAsEmpty', '#NOM?');
else
% Read the rest of the file
RecMat = textscan(fid, strFormat, 'Delimiter', colSeparator);
RecMat = textscan(fid, strFormat, 'Delimiter', colSeparator, 'TreatAsEmpty', '#NOM?');
end
% Close file
fclose(fid);
% Check for errors
if isempty(RecMat) || isempty(RecMat{1})
error('File is could not be read as CSV.');
end
% If the last line is incomplete: delete it
lastFullRow = length(RecMat{end});
if (length(RecMat{1}) > lastFullRow)
for i = 1:length(RecMat)
if (length(RecMat{i}) > lastFullRow)
RecMat{i} = RecMat{i}(1:lastFullRow);
end
end
end


% ===== CONVERT TIMESTAMPS TO TIME =====
bst_progress('text', 'Processing time stamps...');
% Remove the empty timestamps
iNoTime = find(cellfun(@isempty, RecMat{iTimestamp}));
if ~isempty(iNoTime)
for i = 1:length(RecMat)
RecMat{i}(iNoTime) = [];
end
end
% Convert time stamps to datenum
rawTime = datenum(RecMat{iTimestamp})';
% Set t=0 at the first sample
Expand All @@ -113,22 +129,10 @@
% Find a column that has non-empty values that is not a special column
iColAll = setdiff(1:length(Labels), [iTimestamp, iElements]);
iColRec = iColAll(~cellfun(@(c)all(isnan(c)), RecMat(iColAll)));
% If the last line is incomplete: delete it
lastFullRow = length(RecMat{iColRec(end)});
if (length(RecMat{iColRec(1)}) > lastFullRow)
for i = 1:length(RecMat)
if (length(RecMat{i}) > lastFullRow)
RecMat{i} = RecMat{i}(1:lastFullRow);
end
end
if (length(rawTime) > lastFullRow)
rawTime = rawTime(1:lastFullRow);
end
end
% Rebuild data matrix
rawF = [RecMat{iColRec}]';
% Find events
iTimeEvt = find(isnan(rawF(1,:)));
iTimeEvt = find(all(isnan(rawF),1));
% Get event timing
evtTime = rawTime(iTimeEvt);
% Get event labels
Expand All @@ -140,7 +144,12 @@
% Remove events from data matrix
rawF(:,iTimeEvt) = [];
rawTime(iTimeEvt) = [];

% Remove other missing values: replacing with values
iMissing = find(any(isnan(rawF),1));
if ~isempty(iMissing)
disp(sprintf('BST> Muse: Missing data at %d time points. Replacing with zeros...', length(iMissing)));
rawF(isnan(rawF)) = 0;
end

% ===== REINTERPOLATE =====
bst_progress('text', 'Inteprolating recordings...');
Expand Down

0 comments on commit eebf072

Please sign in to comment.