Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding median operator to Bonsai.Dsp #2082

Open
J-M-White opened this issue Dec 16, 2024 · 2 comments
Open

Consider adding median operator to Bonsai.Dsp #2082

J-M-White opened this issue Dec 16, 2024 · 2 comments

Comments

@J-M-White
Copy link

Common Average Referencing (CAR) of multi-channel electrophysiology signals is frequently performed by subtracting the median signal from all channels. As far as I'm aware, there is not a built-in operator in Bonsai for calculating the median of the rows/columns of a matrix. Although it's not too complicated to write an extension to do this, I feel that a median operator would fit naturally in the Bonsai.Dsp package and that having one would reduce friction for people trying to process ephys signals in Bonsai.

I could imagine this being implemented as either:

  1. an additional option in the Reduce operator (however, this would mean moving Reduce away from being a direct port of the equivalent OpenCV function); or
  2. a standalone operator.

I'd be curious to hear others' thoughts on whether this is worth adding and if so what form it should take.

@glopesdev
Copy link
Member

@J-M-White there is an operator for common mode rejection in the Dsp package called ReferenceChannels.

This one however uses the mean rather than the median to compute the reference value for performance reasons.

I understand that for some signals it might be more relevant to use the median to do this instead. In that case it would probably make sense to extend this operator with a property allowing to switch between the algorithm used to compute the common reference (mean or median, default mean for back compatibility).

What do you think? It should be possible to compute the signal median using OpenCV but some research might be needed to do this efficiently at scale using vectorised operations. I think Sort is implemented row-wise but not entirely sure.

@J-M-White
Copy link
Author

@glopesdev I think adding median referencing as an option within ReferenceChannels makes a lot of sense and very nicely addresses the use case I brought up in the original Issue. It does prevent the user from directly accessing the median signal itself, though (as far as I can tell). I feel like there are other use cases where the median itself is the desired output. For example, I currently compute the median of a rolling Buffer of values to determine moving thresholds for some of my closed-loop feedback experiments.

What do you think of having both an independent Median operator and a median option in ReferenceChannels (using the same, underlying median function)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants