↑ Return to Projects

Print this Page

EEG – Electroencephalography with LabVIEW and Mindwave Mobile

The Origins

EEG or electroencephalography are since Hans Berger in 1929 exposed that the activity of the brain could be measured from electrodes situated in the human skull.  With EEG we could measure in fact, the functional state of the brain and diagnose some future or actual problems.  This is the most common way to measure injuries in the brain and functional brain disturbances, but the creation of the signal is not well understood.

Different regions of the cortex have different cytoarchitectures and each region has its own morphological patterns, aspects of intrinsic organization of the cortex are general.  Most of the cortical cells are arranged in the form of columns, in which the neurons are distributed with the main axes of the dendritic trees parallel to each other and perpendicular to the cortical surface. This radial orientation is an important condition for the appearance of powerful dipoles. Figures below lists the parts of human brain cortex and zones of interest..  These layers are places of specialized cell structures and within places of different functions and different behaviors in electrical response.  An area of very high activity is, for example, layer IV, which neurons function to distribute information locally to neu- rons located in the more superficial (or deeper) layers.   Neurons in the superficial layers receive information from other regions of the cortex. Neurons in layers II, III, V, and VI serve to output the information from the cortex to deeper structures of the brain.

brain

Lobes of the human brain, external cerebrum, midbrain areas such as the dience- phalon and the hindbrain areas such as the cerebellum, medulla, etc.neuron_layers

Different layers (columns) of the brain cortex.  Pyramidal cells in layers III and V are mainly responsible for the generation of the EEG.

EEG Signals

The EEG signal consists of spontaneous potential fluctua- tions that also appear without a sensory input. It seems to be a stochastic signal, but it is also composed of quasi- sinusoidal rhythms. The synchrony of cerebral rhythms may occur from pacemaker centers in deeper cortical layers like the thalamus or in subcortical regions, acting through diffuse synaptic linkages, reverberatory circuits incorporating axonal pathways with extensive ramifications, or electrical coupling of neuronal elements. The range of amplitudes is normally from 10mV to 150mV, when recorded from electrodes attached to the scalp. The EEG signal consists of a clinical relevant frequency range of 0.5–50 Hz (10).

The most common frequency bands of EEG are the most common way of analysis.  This information can reveal physiological and statistical evidence but each band could vary on people and animals with is behaviours and metal sanity, age, etc.  The most important patterns of human EEG are described below.

eeg_range

 

Example of EEG Bands

eeg_signals

The phenomena of alpha de-synchronization channel could be used to get the eyes closed/open detection.

Delta Waves

The appearance of delta waves are common in neonatal and infant EEGs and during in sleep stages in adult EEGs.  If delta EEGs appears by itself in a adult it means cerebral injury

Theta Waves

In the beginning where part of the delta waves, but scientists discovered the importance activity of these waves.  Its region of interaction is between thalamic region and play dominant part in childhood and infancy.  The normal adult waking of theta waves are a few or small amount of these frequencies observed in drowsiness and sleep.  Large amount of theta waves are associated between different amount of pathologies.

Alpha Waves

These are originated on the posterior half back of the head and are from occipital an parietal regions.  These waves are observed during conditions of awakeness, physical relaxation and mental innactivity.  Can be blocked by mental activity or an influx of light when eyes are opened.

Beta Waves

Are presented in a healthy addult and the area of formation are in the frontal and central region of the cortex.  Typical voltage of beta waves are less than 30uV.  Beta activity increase when the organism is added with barbiturerates, some non barbiturates sedatyves and minor tranquilizers.  It also appears during mental activity and tension.

Clinical EEG

The most common EEG uses up to 30 landmarks on the skull using bipolar derivation (two electrodes on the skull and the difference is the gradient of potential).  Unipolar derivation is done with an electrode or group of electrodes with the active part (activity) and the inactive part (usually nose or ear).  The advantage of unipolar derivation are that the amplitude of each deflection is proportional to the magnitude of the potential change that causes it and the demonstration of small time differences between the occurrence of a widespread discharge at several electrode.

eeg_areas

Common areas of bipolar EEG sensory.

Emotiv Epoch EEG

The below paragraph is extracted from emotiv page directly.
Based on the latest developments in neuro-technology, Emotiv presents a revolutionary personal interface for human computer interaction. Emotiv EPOC is a high resolution, multi-channel, wireless neuroheadset. The EPOC uses a set of 14 sensors plus 2 references to tune into electric signals produced by the brain to detect the user’s thoughts, feelings and expressions in real time. The EPOC connects wirelessly to PCs running Windows or MAC OS X.
Experience the fantasy of controlling and influencing the virtual environment with your mind. Access applications and play games developed specifically for the EPOC, or use the EmoKey to connect to current PC games and experience them in a completely new way. 
 
If you or any of your 3rd party applications require access to raw EEG data, you will need to purchase the Emotiv EEG Neuroheadset. 
emotiv
Emotiv Epoch EEG Neuroheadset

Neurosky Mindwave

The below paragrah was extracted from Neurosky directly

Measuring Electroencephalogram (EEG) activity has historically required complex, intimidating and immovable equipment costing thousands of dollars. NeuroSky is unlocking a new world of solutions for education and entertainment with our research-grade, mobile, embeddable EEG biosensor solutions. Precisely accurate, portable and noise-filtering, our EEG biosensors translate brain activity into action.

Our EEG solution digitizes analog electrical brainwaves to power the user-interface of games, education and research applications. We amplify and process raw brain signals to deliver concise input to the device. Our brainwave algorithms, developed by NeuroSky researcher and our partner universities and research institutions are uncovering new ways to interact with our world.

neurosky

Mindwave Mobile EEG Neuroheadset

Both EEGs are good.  Neurosky Mindwave is cheap, easy to hack and usefull for develop simple applications and filters for study brainwave signals.  One thing to note is that Neurosky EEG is only for develop games and must not be used to study the signals as a medical device, this is not the goal of this company.  The cost of the Neurosky Mindwave Mobile is about 100 USD.

Emotiv EEG is good at a clinical level because gives you a lot of information of regions from F1 to F15, has an gyroscope to sense orientation of the head and a SDK for developer or researcher in Linux and Windows.  The cost of the EEG rounds about 300 USD. But if you need to get raw data for better analysis you need to buy the complete package of EEG neuroheadset, and software, its around 750 USD.

Because ease of use this note is based on Neurosky Mindwave.

Pairing the Mindwave Mobile with the Bluetooth Device.

The first thing is to detect the Mac Address of your device.  For achive this task you must download to your andriod phone a bluetooth mac address finder like are in the play store.  I recommend you Bluetooth Address Finder.

bluetooth_scanner

Next turn on the mindwave mobile and wait the blue light to start blinking.  When the light comes on hold again to the top position a few seconds the switch and will start to blink a little faster.

Then start the bluetooth application on your phone and in a few seconds you will have the mac address that you want like this below.

neurosky_mac

The BD_ADDR (Bluetooth Device Address) of the my Mindwave Mobile.

Just for information.  The three lower bytes are called LAP (Lower Address Part) of your bluetooth device.   Next we must set our bluetooth device.  I am using a Roving Network  RN-41 Module.

RN-41_USBWhen connected to USB follow up these commands to set the device autoconnect activity.

6/14/2014 15:11:55.888 [TX] – $$$
6/14/2014 15:11:55.959 [RX] – CMD<CR><LF>

6/14/2014 15:12:03.871 [TX] – SM,3<CR><LF>

6/14/2014 15:12:03.957 [RX] – AOK<CR><LF>

6/14/2014 15:12:06.655 [TX] – SP,0000<CR><LF>

6/14/2014 15:12:06.751 [RX] – AOK<CR><LF>

6/14/2014 15:12:35.424 [TX] – SR,74e5439c6264<CR><LF>

6/14/2014 15:12:35.600 [RX] – AOK<CR><LF>

6/14/2014 15:12:50.152 [TX] – R,1<CR><LF>

6/14/2014 15:12:50.223 [RX] – Reboot!<CR><LF>

For the next step now you will need only to turn on the bluetooth of the mindwave mobile, wait some seconds and they will automatically pair.  The scenario should act and finalize exactly like that figure below.

mindwave_paired

Bluetooth connection for PC and Mindwave Mobile completely paired

Midwave Mobile Frames

First letx explain the frame output of mindwave mobile.  There are two frame that are outputed at variable rates.

AA 04 80 02 00 56 27 AA AA 04 80 02 00 53 2A AA AA 20 02 38 83 18 02 43 EA 00 03 90 00 00 89 00 00 47 00 00 1E 00 00 28 00 00 3B 00 00 27 04 00 05 00 E7 AA AA 04 80 02 00 53 2A AA AA 04 80 02 00 55 28 AA AA 04 80 02 00 54 29 AA AA 04 80 02 00 54 29 AA

Purple frame is outputted every 512 Hz and is not exchangeable the frequency time of output.

Green frame is outputed every 1 Hz and is not exchangeable the frequency time of output.

The frames contains useful information about raw values and calculated values.  The below table lists the different frames that are output of every frame.

For the 512 Hz frame the information output is:

byte: value // Explanation

[ 0]: 0xAA  // [SYNC]
[ 1]: 0xAA  // [SYNC]
[ 2]: 0x04  // [PLENGTH] (payload length) of 8 bytes
[ 3]: 0x80  // [RAW_WAVE_VALUE] 16-bit two's-compliment signed value (high-order byte followed by low-order byte) (-32768 to 32767)
[ 4]: 0x02  // [VLENGHT] (payload variable length) of 'n' bytes 
[ 5]: 0x00  // [RAW_HIGH] high order byte of raw data two's compliment signed value
[ 6]: 0x53  // [RAW_LOW]  low order byte of raw data two's compliment signed value
[ 7]: 0x2A  // [CHKSUM] (1's comp inverse of 8-bit Payload sum)


For the 1 Hz frame the information output is:

byte: value // Explanation

[ 0]: 0xAA  // [SYNC]
[ 1]: 0xAA  // [SYNC]
[ 2]: 0x20  // [PLENGTH] (payload length) of 32 bytes
[ 3]: 0x02  // [POOR_SIGNAL_QUALITY] (0 to 255)
[ 4]: 0x38  // 56 of 255 
[ 5]: 0x83  // [ASIC_EEG_POWER] eight big-endian 3-byte unsigned integer values representing delta, theta, low-alpha, high-alpha, low-beta, high-beta, low-gamma, and mid-gamma EEG band power values
[ 6]: 0x18  // upper  byte of EEG_POWER_DELTA
[ 7]: 0x02  // middle byte of EEG_POWER_DELTA
[ 8]: 0x43  // lower  byte of EEG_POWER_DELTA
[ 9]: 0xEA  // upper  byte of EEG_POWER_THETA
[10]: 0x00  // middle byte of EEG_POWER_THETA
[11]: 0x03  // lower  byte of EEG_POWER_THETA
[12]: 0x90  // upper  byte of EEG_POWER_LOW_ALPHA 
[13]: 0x00  // middle byte of EEG_POWER_LOW_ALPHA 
[14]: 0x00  // lower  byte of EEG_POWER_LOW_ALPHA 
[15]: 0x89  // upper  byte of EEG_POWER_HIGH_ALPHA
[16]: 0x00  // middle byte of EEG_POWER_HIGH_ALPHA
[17]: 0x00  // lower  byte of EEG_POWER_HIGH_ALPHA
[18]: 0x47  // upper  byte of EEG_POWER_LOW_BETA
[19]: 0x00  // middle byte of EEG_POWER_LOW_BETA
[20]: 0x00  // lower  byte of EEG_POWER_LOW_BETA
[21]: 0x1E  // upper  byte of EEG_POWER_HIGH_BETA
[22]: 0x00  // middle byte of EEG_POWER_HIGH_BETA
[23]: 0x00  // lower  byte of EEG_POWER_HIGH_BETA
[24]: 0x28  // upper  byte of EEG_POWER_LOW_GAMMA
[25]: 0x00  // middle byte of EEG_POWER_LOW_GAMMA
[26]: 0x3B  // lower  byte of EEG_POWER_LOW_GAMMA 
[27]: 0x00  // upper  byte of EEG_POWER_MID_GAMMA 
[28]: 0x00  // middle byte of EEG_POWER_MID_GAMMA 
[29]: 0x27  // lower  byte of EEG_POWER_MID_GAMMA
[31]: 0x04  // [ATTENTION]  eSense (0 to 100)
[32]: 0x00  // Attention level
[33]: 0x05  // [MEDITATION] eSense (0 to 100)
[34]: 0x00  // Meditation level 
[35]: 0xE7  // [CHKSUM] (1's comp inverse of 8-bit Payload sum)

More information about the protocol and de-packing could be encountered here.

LABVIEW Graphical Code

MindwaveProject

Because for my use there was no way to start the Thinkgear communication API in LabVIEW, i decided to make my own thinkgear library.

LabVIEW_front_panel

LabVIEW Front Panel of the Application.  This displays all signals captured by the Neurosky Mindwave and finally makes the FFT Power Spectrum.  You can also copy and paste the data to make further analysis in Matlab or any favorite software.

Mindwave_vi

LabVIEW Block Diagram of the Application.  Basically you must start the VI (MindwaveInit.vi) and start capturing frames (MindwaveStream.vi); finally when you are finished then close the VI (MindwaveCLOSE.vi).

There are several blocks of work that i have created, and are hidden in the structure of the project.  You could download the project and navigate to the structure of the Neurosky folder.  Should look like this:

MindwaveLib

Image of non-hidden and hidden function blocks for Mindwave Mobile.

Mindwave Init

This function basically starts the bluetooth SPP (Serial Port Profile) hardware with the baudrate desired.  It is used to start receiving packets from our headset device.

MindwaveInitMindwave Stream

Mindwave stream does the complete job of unpack the received data of the frames of 512 Hz and 1 Hz filling a structure that you could access later to make calculations.

MindwaveStream

Mindwave Precise

This block is a variation of the above MidwaveStream.vi, the difference is that you could wait to capture the RAW EEG (512 Hz frame) or the Variable Length (1 Hz frame) via an input.

MindwavePrecise

Mindwave Auto

This block as above blocks do the recopilation of information of the frames, but sequentially, first the raw eeg and then later the variable lenght data.

MindsaveAUTO

Mindwave Close

When you are done with communications you must close the serial port channel for other programs to start using this resource.

MindwaveClose

Here is the Github code that i developed.  Remember this content is under Creative Commons license..

Finally here is a video of explanation of the use of Mindwave and LabVIEW.

Permanent link to this article: http://cerescontrols.com/projects/eeg-electroencephalography-with-labview-and-mindwave-mobile/

23 comments

Skip to comment form

  1. Laila

    Hi,
    Thanks for the application.
    In the block diagram of the main application you applied the FFT directly on the raw data without preprocessing the raw data. from my understanding the raw data need some processing to remove the noise.
    Does the mindwave library provide the pre-processings? or is it OK to apply the FFT directly?

  2. sid

    thanks rangel it worked

  3. sid

    after opening labview.lvproj it is saying project is corrupted

  4. sid

    but there is no download option for neurosky labview.lvproj??

  5. sid

    but how to find neurosky.lvlib??

    1. Rangel Alvarado

      You just find it on my github. Just load Neurosky Labview.lvproj it should do the work.

      If you have more troubles send me an email to issaiass@hotmail.com to share more info.

  6. siddharth

    is midwave compatible with windows 8 ,64 bit and labview 32 bit ??
    what are the components and softwares required to interface mindwave with labview

    1. Rangel Alvarado

      Right now I am using Windows 8.1 64 bit and LabVIEW 32 bit

      You need VISA (its free from NI website) and a BT to USB (using Virtual Comm Port) for make it easy to access, but if you have experience with raw BT and LabVIEW, go ahead.

      1. siddharth

        thnaks for the information.
        i am having bluetooth driver in my laptop, so is it required for BT to USB connection?

      2. siddharth

        thanks for the information.
        i am having bluetooth driver in my laptop, so is it required for BT to USB connection?
        is it mandatory to purchase RN-41 ?

        1. Rangel Alvarado

          It is not mandatory to have a USB to BT device if you can extract your data from the BT characteristic.

          But, for this example using specific hardware and situation to work as it is described on the document it is.

          1. sid

            after loading the vi it is asking find the library neurosky.lvlib?????

  7. siddharth

    is mindwave compatible with windows 7 ,32 bit n labview 2014 32 bit

    1. Rangel Alvarado

      Supported platforms: Windows (XP/7/8/8.1/10), Mac (OSX 10.7.5 or later), iOS (iOS 8 or later) and Android (Android 2.3 or later).
      When I say LabVIEW, I had used it with the NI VISA Serial (BT-RS232), off course is compatible. I had never used it with the LabVIEW BT VISA drivers.

  8. Maulud Hidayat

    Hallo, thanks for the vi. but i have some problem while opening that vi. something error and i have to browse that missing file. how to fix that please/

    1. Rangel Alvarado

      Which kind of error? Do you installed VISA? Which file? Remember i am using a specific hardware to communicate with the PC, a Roving Networks (now Microchip) device.

  9. Doru Ursutiu

    Whay the frequency it is so small (not in the expected range).
    Also de values are in the range 1E-41 ??

    1. Rangel Alvarado

      All values where captured ok in bytes, the problem is the IEEE-754 representation that i didn’t solve.

  10. sriram

    can we get this program? because i tried but again and again get com port error.

    1. Rangel Alvarado

      Ensure that you installed VISA correctly, the runtime is free and for download on NI website.

  11. masajista alicante

    Muy chulo, me ha gustado mucho

  12. azimah

    Hi.. i need to use labview to extract data for my master.

    I’m willing to donate certain amount for missing component in the labview file that you provide…

    can we discuss about it? need it urgently.. thank you

    1. Rangel Alvarado

      Which specific component is missing?

Leave a Reply

Your email address will not be published. Required fields are marked *