Extracting frequency bands (alpha, beta, gamma etc.) from raw EEG data

I recently bought a NeuroSky MindWave Mobile headset. So far, I have written a simple Visual C# program that reads raw EEG data from the headset (via Bluetooth).

I would like to process this raw data and display the EEG band frequencies (delta, theta, alpha, beta & gamma) to the user. From what I have understood, this will most likely require a Fast Fourier Transform.

I have also read that ocular artefacts (e.g. eye blinks) and other noise needs to be filtered prior to extracting these frequencies.

Which filters should I use and what are the best open-source .NET libraries with implementations of these filters? Code examples would be lovely as well!

Many thanks in advance for any help whatsoever! I really appreciate it.

You can use some of FFT libraries for C#
Roughly, you can do the following.
Divide your signal into epoch (for example 1-4 seconds long).
For each of the epochs, calculate FFT.
Average for all epochs.
If your epoch is for example 1 second long, and sampling rate is Fs = 250 HZ, then you shall obtain 125 samples of FFT. This is related to the frequency ranges from 0 - 125Hz (Fs/2). Then you need to sum samples in the rage of interest. For example, teh sample related to 12 Hz =
If you need any help, you can send me the file so that I can try and give you the code.
There are better ways to do this, with Hamming or other averaging windows, but this is the most basic way.

If you just want SOME of the bands, for example if you are doing a neurofeedback program that rewards / inhibits certain bands – the alternative is to use band filters instead of FFT. This is a common approach used in VPL’s such as BrainBay, BioEra, Bioexplorer, OpenViBE, neuromore, etc.

An excellent C language IIR filter design library is Jim Peters FIDLIB. It’s actually the engine used by BioEra and BrainBay. A great feature of this library is that the filter type (bandpass, lowpass, highpass, notch; Butterworth, Bessel, etc.) and band edges can all be specified at runtime. This is how the VPL’s allow dynamic changing of these parameters.

http://uazu.net/fidlib/

William

Hi Marko!

Thanks a lot for the swift reply (and apologies for my delayed response)! I would be very grateful if you could help with the code.

I have included an abbreviated snippet of my program below as requested.

// Called when data is received from a device
public void OnDataReceived(object sender, EventArgs e) {
    Device.DataEventArgs de = (Device.DataEventArgs)e;
    DataRow[] tempDataRowArray = de.DataRowArray;

    TGParser tgParser = new TGParser();
    tgParser.Read(de.DataRowArray);            

    /* Loops through the newly parsed data of the connected headset*/
    for (int i = 0; i < tgParser.ParsedData.Length; i++) {
        if (tgParser.ParsedData[i].ContainsKey("Raw"))
        {
            Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
        }
    }
}

Basically, every time data is received from the headset, the OnDataReceived() method is called. If the “Raw” data is present, it is printed to the console.

I also have a couple of questions:

  • How will the performance be if the FFT is applied to data as it is received from the headset and displayed to the user live?
  • Will you be filtering noise (e.g. eye blinks) or just extracting the frequency bands?

Again, thanks very much for your help!

Many thanks, wjcroft! I am checking out FIDLIB right now and looking at band filters. Are there any good code examples/open-source projects that you know of filter data from a NeuroSky MindWave headset?

Lem, I suggest you start with BrainBay,

http://www.shifz.org/brainbay/

It is a VPL, Visual Programming Language environment, where you do the signal processing by positioning various DSP elements and connect the signal flows with lines. No programming required. BrainBay uses the FIDLIB mentioned earlier internally. So you can do your filters or FFT without any programming.

BrainBay supports a number of EEG interfaces, including Neurosky.

There will be some delay, as you must calculate FFT on every 1 second or .5 second, for example.

You can do the filtering of eye blinks before, but you can try without that.

for further communication, please use
m_car at yahoo.com

regards
Marko