Skip to content

Commit

Permalink
Fix negative signals produced while doing moco
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-vincent committed Jul 6, 2019
1 parent 9e43193 commit 2d34b50
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions bst_plugin/process_nst_motion_correction.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,29 @@
OutputFiles = {};
return
end

if isempty(event.times) % no marked event
data_corr = sDataIn.F';
else
% Process only NIRS channels
channels = in_bst_channel(sInputs(iInput).ChannelFile);
nirs_ichans = channel_find(channels.Channel, 'NIRS');
data_nirs = sDataIn.F(nirs_ichans, :)';
prev_negs = any(data_nirs <= 0, 1);
% Keep track of channels that contained neg values
samples = round((event.times' - sDataIn.Time(1)) ./ diff(sDataIn.Time(1:2))) + 1;
data_corr = Compute(sDataIn.F', sDataIn.Time', samples);
data_corr = Compute(data_nirs, sDataIn.Time', samples);
% Fix negative values created by moco
new_negs = any(data_corr <= 0, 1) & ~prev_negs;
if any(new_negs)
warning('Motion correction introduced negative values. Will be fixed by global offset');
% TODO: use pair-specific offset see /home/tom/Projects/Research/Software/mfipcode/sandbox/nirstorm/mfip_correct_negChan.m
offset = 2*abs(min(data_corr(:)));
data_corr = data_corr + offset;
end
data_corr_full = sDataIn.F';
data_corr_full(:, nirs_ichans) = data_corr;
data_corr = data_corr_full;
end
if 0
nirs_data_full = in_bst(sInputs(iInput).FileName, [], 1, 0, 'no');
Expand All @@ -114,6 +131,8 @@
% OutputFiles = {sInputs(iInput).FileName};
end



% Save time-series data
sDataOut = db_template('data');
sDataOut.F = data_corr';
Expand Down

0 comments on commit 2d34b50

Please sign in to comment.