This introduces some linear recombination of the signals. The same linear recombination needs to be applied to the rows of the forward model and to the noise covariance matrix, otherwise the inverse model would not be correctly designed for your cleaned recordings.
end
% ===== LOAD HEAD MODEL =====
bst_progress('text', 'Loading head model...');
bst_progress('inc', 1);
% Get headmodel file
HeadModelFile = sStudyChannel.HeadModel(sStudyChannel.iHeadModel).FileName;
% Load head model
HeadModel = in_bst_headmodel(HeadModelFile, 0, 'Gain', 'GridLoc', 'GridOrient', 'GridAtlas', 'SurfaceFile', 'MEGMethod', 'EEGMethod', 'ECOGMethod', 'SEEGMethod', 'HeadModelType');
% Apply current SSP projectors
if ~isempty(ChannelMat.Projector)
% Rebuild projector in the expanded form (I-UUt)
Proj = process_ssp2('BuildProjector', ChannelMat.Projector, [1 2]);
% Apply projectors
if ~isempty(Proj)
% Get all sensors for which the gain matrix was successfully computed
iGainSensors = find(sum(isnan(HeadModel.Gain), 2) == 0);
% Apply projectors to gain matrix
HeadModel.Gain(iGainSensors,:) = Proj(iGainSensors,iGainSensors) * HeadModel.Gain(iGainSensors,:);
% Apply SSPs on both sides of the noise covariance matrix
NoiseCovMat.NoiseCov = Proj * NoiseCovMat.NoiseCov * Proj';