Skip to content

First-pass average referencing differs between PyPREP and Matlab PREP #75

Closed

Description

@a-hurst

In MATLAB PREP, robust re-referencing starts by detecting noisy channels, calculating the median signal excluding all channels bad by NaN, bad by flat, or bad by low SNR, and then re-referencing the data using that signal. PyPREP does almost the same thing, except it leaves in channels bad by low SNR which results in numeric differences when those sorts of channels are present:

pyprep/pyprep/reference.py

Lines 233 to 240 in 051edd6

self.unusable_channels = _union(
noisy_detector.bad_by_nan, noisy_detector.bad_by_flat
)
# According to the Matlab Implementation (see robustReference.m)
# self.unusable_channels = _union(self.unusable_channels,
# noisy_detector.bad_by_SNR)
# but maybe this makes no difference...

Based on the above code & comment, it looks like this difference is deliberate? Is there an intentional reason to include these channels when calculating a median reference? If so, I'll make it a matlab_strict thing and document it in the "deliberate differences" page. If not, I'll just make a PR to add those in.

Looking at the MatPREP Git history, it looks like the SNR channels were a deliberate addition to the list of exclusions from the initial reference, added when the default method of calculating the initial reference signal was changed from "huber mean" (?) to median. Maybe it's worth asking Dr. Robbins about?

Anyway, if I add "bad-by-SNR" channels to the list of initial unusables in PyPREP, the initial average-referenced signal is identical to the one in MATLAB PREP.

Activity

  1. sappelhoff commented on May 4, 2021

    @sappelhoff
    Owner

    git blame tells me that this was added by @adam2392 when he merged in the work by @AamnaLawrence and @Nick3151 back then. And apparently @yjmantilla noticed that it's odd in #32, and left the comment that you now stumbled on.

    I guess it's just an oversight and fixing it now would be good. I cannot remember this being a deliberate choice - and unless somebody else chimes in, we should go ahead with a fix :)

    Maybe it's worth asking Dr. Robbins about?

    I don't think so. Not unless we start running into problems after the fix.

    Anyway, if I add "bad-by-SNR" channels to the list of initial unusables in PyPREP, the initial average-referenced signal is identical to the one in MATLAB PREP.

    Cool, +1

  2. added this to the 0.4.0 milestone on May 4, 2021
  3. Nick3151 commented on May 6, 2021

    @Nick3151
    Contributor

    Thank you for pointing out! It should just be an oversight. Go ahead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions