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

**URL:** <https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052>\
**Category:** Software\
**Tags:** eeg\
**Created:** [May 16, 2019, 5:26am UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052 "2019-05-16T05:26:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lemchast](https://neurobb.com/letter_avatar_proxy/v4/letter/l/ac8455/32.png) [@Lemchast](https://neurobb.com/u/Lemchast)\
**Post date:** [May 16, 2019, 5:26am UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052/1 "2019-05-16T05:26:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Marko\_Car](https://neurobb.com/user_avatar/neurobb.com/marko_car/32/230_2.png) [@Marko\_Car](https://neurobb.com/u/Marko_Car)\
**Post date:** [May 17, 2019, 7:52am UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052/2 "2019-05-17T07:52:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wjcroft](https://neurobb.com/user_avatar/neurobb.com/wjcroft/32/33_2.png) [@wjcroft](https://neurobb.com/u/wjcroft)\
**Post date:** [May 17, 2019, 4:27pm UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052/3 "2019-05-17T16:27:01Z")

</div>

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/](http://uazu.net/fidlib/)

> **[uazu/fidlib](https://github.com/uazu/fidlib)**
>
> Fidlib run-time filter design and execution library. CURRENTLY UNMAINTAINED. Consider daschuer/mixxxdj fork if this doesn't work for you. - uazu/fidlib

William

---

<div class="post-metadata">

**Author:** ![Lemchast](https://neurobb.com/letter_avatar_proxy/v4/letter/l/ac8455/32.png) [@Lemchast](https://neurobb.com/u/Lemchast)\
**Post date:** [May 27, 2019, 5:55pm UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052/4 "2019-05-27T17:55:37Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Lemchast](https://neurobb.com/letter_avatar_proxy/v4/letter/l/ac8455/32.png) [@Lemchast](https://neurobb.com/u/Lemchast)\
**Post date:** [May 27, 2019, 6:00pm UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052/5 "2019-05-27T18:00:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![wjcroft](https://neurobb.com/user_avatar/neurobb.com/wjcroft/32/33_2.png) [@wjcroft](https://neurobb.com/u/wjcroft)\
**Post date:** [May 27, 2019, 6:17pm UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052/6 "2019-05-27T18:17:35Z")

</div>

Lem, I suggest you start with BrainBay,

[http://www.shifz.org/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.

---

<div class="post-metadata">

**Author:** ![Marko\_Car](https://neurobb.com/user_avatar/neurobb.com/marko_car/32/230_2.png) [@Marko\_Car](https://neurobb.com/u/Marko_Car)\
**Post date:** [May 29, 2019, 12:45pm UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052/7 "2019-05-29T12:45:06Z")

</div>

> [@Lemchast](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![Marko\_Car](https://neurobb.com/user_avatar/neurobb.com/marko_car/32/230_2.png) [@Marko\_Car](https://neurobb.com/u/Marko_Car)\
**Post date:** [May 29, 2019, 12:47pm UTC](https://neurobb.com/t/extracting-frequency-bands-alpha-beta-gamma-etc-from-raw-eeg-data/1052/8 "2019-05-29T12:47:27Z")

</div>

> [@Lemchast](#):
>
> Will you be filtering noise (e.g. eye blinks) or just extracting the frequency bands?

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](http://yahoo.com)

regards  
Marko
