Library to apply BandPass filter for EEG signals in Processing

Hi, I want to filter my incoming EEG data in processing before plotting. I explored the “Sound” library of processing (https://processing.org/reference/libraries/sound/index.html), but I think this is specifically for audio signals only.

Is there a way to apply filters to EEG signals?
Please share insights.
Appreciate your time. Many thanks.

What kind of filters, specifically?

In principle there is no reason not to use an audio signal processing library to do a bandpass on wave data.

The sound library has a simple example:

…but more complex libraries, such as minim, for example, have bandpass examples as well:

It depends on what you are trying to accomplish.

Is this sonification, or are you doing something else with the signal? How is it coming in, how should it go out, etc.?

1 Like

There is a library called Signal Filter. This could be a good start. You need to check if you could use this filter with your data. One approach is to check the provided examples. You can also dive into the source code in github. At the end, you might check external libraries that does signal filtering for you or you could implement your own basic filters. Selecting a filter is based on the nature of your data. I would say that for EEG those filters should be well defined and documented.

Kf

1 Like

I am getting EEG data serially in real time from an Arduino board into an array that I am trying to apply a bandpass filter of 4-35 Hz on. I will be plotting the filtered data afterwards.

Yes, I explored that library, but I think it is only useful for noise (50/60 Hz) cancellation and not actual digital signal processing. Thank you for the suggestion though. :slight_smile:

we talked about that

and my idea is:

  • -a- if you sample single ended inputs (not differential ) you get
    that 50/60 Hz from any body
    ( just hold your finger on a arduino Ain )
  • -b- if you filter 50Hz you filter a critical content of what you want measure.
1 Like

Hi, I agree that powerline noise is one of the major noise components. But the EEG data (signal of interest) , in general, has a frequency range of 1 Hz to 40-45 Hz. I would want to get only 5 to 30 Hz. Hence, having a bandpass filter in my application is equally necessary.

actually a low pass filter might do it,
but filter 50 but get 30 [Hz] is not so easy
( you have to live with loss in amplitude and phase shift ( late ) )

but you not answer much questions,
so still not know if you have batch data to analyze, or stream?

you also possibly can not afford to use cpu demanding calculations.

so why not just try the most easy filter ever!

fil = inval * A + fil * B;

ok, there are some small things about that:
-a- tuning:
A + B = 1;

-b- init:
a startup is difficult for any filter, so
fist line could be
fil = inval;
to avoid big error at beginning.

// low pass filter
// numeric recursiv filter first order

float inval, fil;
float A=0.1, B = 1.0 - A;
int xpos=0;

void setup() {
  size(600, 200);
  inval = height - mouseY;
  fil = inval;
  frameRate(10);
  background(200, 200, 0);
  println("reading mouseY");
}

void draw() {
  inval = height - mouseY;
  fil = inval * A + fil * B;
  strokeWeight(2);
  stroke(200, 0, 0);
  point(xpos, height-inval);
  stroke(0, 200, 0);
  point(xpos, height-fil);
  strokeWeight(1);
  stroke(200, 200, 0);   // clean line in front:
  line(xpos+1, 0, xpos+1, height);
  xpos++;
  if (xpos > width ) xpos = 0;
}

2019-01-22_19-37-51_snap

2 Likes

Hey ! Thanks that’s what I did.
Apologies for not being very active.

I was getting values from Arduino IDE in realtime (@250 Hz so approx. 4 milliseconds per value).

In Processing:

  • Read values in serialevent() one by one – stored in a dynamically shifting array.

  • Used this array to perform dot product (convolution) with the imported filter coefficients (FIR filter).

– I generated filter coefficients using MATLAB.

This workaround works quite good.

Now, I am trying to optimize this filter code further for the same reason you pointed out (calculations are demanding!) – looking into PVector class.

Appreciate your help even though the information I provided was not enough (new on the forum - learning curve). My process seems validated now. Thanks.