Skip to content

Minimum of three iterations in robust re-reference? #26

Open
@a-hurst

Description

@a-hurst

Hi there,

I think I've discovered a small bug in the re-referencing logic of the PREP pipeline, but I wanted to make sure it isn't intentional behaviour before modifying anything on my end.

%% Remove reference from signal iteratively interpolating bad channels
iterations = 0;
noisyChannelsOld = [];
while true % Do at least 1 iteration
noisyStatistics = findNoisyChannels(signalTmp, referenceOut);
referenceOut.badChannels = ...
updateBadChannels(referenceOut.badChannels, noisyStatistics.noisyChannels);
noisyChannels = referenceOut.badChannels.all(:)';
if (iterations > 1 && (isempty(noisyChannels) ||...
(isempty(setdiff(noisyChannels, noisyChannelsOld)) ...
&& isempty(setdiff(noisyChannelsOld, noisyChannels))))) || ...
iterations > referenceOut.maxReferenceIterations
break;
end
noisyChannelsOld = noisyChannels;
sourceChannels = setdiff(referenceOut.referenceChannels, noisyChannels);
if length(sourceChannels) < 2
error('robustReference:TooManyBad', ...
'Could not perform a robust reference -- not enough good channels');
end
if ~isempty(noisyChannels)
signalTmp = interpolateChannels(signal, noisyChannels, sourceChannels);
else
signalTmp = signal;
end
referenceSignal = nanmean(signalTmp.data(referenceChannels, :), 1);
signalTmp = removeReference(signal, referenceSignal, referenceChannels);
iterations = iterations + 1;
fprintf('Iteration: %d\n', iterations);
end

In the above loop, iterations starts at zero and only get incremented at the end, after the "check if we should break the loop" logic. As a consequence, it means that the code actually does a maximum of 5 iterations by default, even though the default maximum is documented to be 4. Additionally, it means that PREP needs to do at least three iterations of this loop, even if the detected bad channels are unchanged between the first and second iterations. Looking at the original PREP publication, the pseudocode for this loop doesn't say anything about a minimum of iterations, so I'm wondering whether this is a bug or an intentional behaviour I don't understand.

Thanks in advance, and thank you for creating and maintaining this software!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions