Skip to content

Add channel rereferencing across language bindings - #847

Draft
Daniiiil1 wants to merge 1 commit into
brainflow-dev:masterfrom
Daniiiil1:codex/brainflow-rereference-channels
Draft

Add channel rereferencing across language bindings#847
Daniiiil1 wants to merge 1 commit into
brainflow-dev:masterfrom
Daniiiil1:codex/brainflow-rereference-channels

Conversation

@Daniiiil1

Copy link
Copy Markdown

Summary

  • add a reference operation to the C++, C#, Java, Julia, MATLAB, Node.js, Python, Rust, and Swift DataFilter APIs
  • compute the sample-wise mean of selected reference channels before mutating data, so overlapping reference and target channel lists are safe
  • validate empty matrices, empty channel lists, rectangular inputs where applicable, and out-of-range indices
  • demonstrate the operation in each language's existing downsampling example; the R example uses the Python binding as the R package already does
  • add Julia, Rust, and Swift unit coverage, including overlapping channel lists and invalid arguments

Motivation

EEG pipelines commonly need to re-reference multiple channels against the mean of one or more reference electrodes. BrainFlow currently requires users to implement that operation themselves in every language. This adds one consistent operation following the API proposed in #619.

For input matrix data, the implementation first computes

reference_signal[t] = mean(data[channel, t] for channel in reference_channels)

and then applies

data[channel, t] -= reference_signal[t]

to every channel in channels_to_reference. The reference signal is computed completely before any target row is changed.

Closes #619.

Validation

  • Python: 640 randomized matrix/channel configurations matched an independent NumPy calculation at rtol=1e-13; invalid lists and indices were also checked
  • Node.js: npm run build passed; direct runtime behavior and invalid-argument checks passed
  • C#: complete brainflow.sln Release build passed with 0 warnings and 0 errors
  • Swift: the BrainFlow target and swift-downsampling product both build successfully
  • repository diff check: git diff --check passed

The draft PR lets the full BrainFlow CI validate the remaining platform-specific C++, Java, Julia, MATLAB, R, Rust, and Swift test paths.

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

Successfully merging this pull request may close these issues.

add method to rereference channels

1 participant