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

Method to reference channels for Issue #619 #630

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions java_package/brainflow/src/main/java/brainflow/DataFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,41 @@ public static double get_band_power (Pair<double[], double[]> psd, double freq_s
return res[0];
}

/**
* (re)reference channels
*
* To eliminate ground-related noise, an online reference is chosen out of the recorded EEG channels.
* This reference is used as “baseline” for all remaining EEG channels.
* This means the signal at the other EEG channels is expressed as the difference from this reference.
*
* Thie method averages data from reference_channels and then subtract the averaged data from channels_to_reference
*
* @param data data to process
* @param channels_to_reference channels to be referenced or expressed as difference from reference_channels averaged data
* @param reference_channels channels to use as reference or baseline
* @return void
*/
public static void reference (double[][] data, ArrayList<Integer> channels_to_reference, ArrayList<Integer> reference_channels)
throws BrainFlowError
{
// Calculate the average data points of reference_channels
double[] avg_reference = new double[data[0].length];
for (int channel : reference_channels) {
for (int i = 0; i < data[channel].length; i++) {
avg_reference[i] += data[channel][i];
}
}
for (int i = 0; i < avg_reference.length; i++) {
avg_reference[i] /= reference_channels.size();
}
// Subtract the average of reference_channels from each channel in channels_to_reference
for (int channel : channels_to_reference) {
for (int i = 0; i < data[channel].length; i++) {
data[channel][i] -= avg_reference[i];
}
}
}

/**
* calculate nearest power of two
*/
Expand Down