LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for walk-through on how to calculate a band ratio along with macro

Hi All, 

 

I'm new to EEG data classification and analysis and am seeking some help with software recommendations and a bit of a programming walkthrough (if necessary). I thank you in advance for reading and for your support. 

 

To provide a general overview, using an Emotiv EEG headset, I am trying to calculate a band ratio in real-time, namely the "engagement index" or combined beta power / (combined alpha power + combined theta power). I'm open to using any open-source or low cost software to compute this index. 

 

In addition, I need software or a combination of software that can in real-time or with some slight delay trigger keystrokes when certain fluctuations in this index occurs. For example, if the index drops below .50 I would like for the system to press Z or some other key I designate or, if the index raises above .70 I would like for the system to press F or some other key I designate. 

 

I suppose for now I'll cut this post off before going into potentially unnecessary detail.

 

Thank you! 

0 Kudos
Message 1 of 6
(712 Views)

Hello cube0,

 

Are you looking to use LabVIEW or other NI software/hardware for your application? Do you have specific questions about NI products or are you just asking for general knowledge? Either way, you can download an evaluation of LabVIEW 2013 from our website (https://lumen.ni.com/nicif/US/EVALLV/content.xhtml) and test it for your application for up to 30 days. I would also encourage you to browse through the forums and community examples to get an idea of what LabVIEW can do.  

Jonathan L.
Product Support Engineer
National Instruments
0 Kudos
Message 2 of 6
(670 Views)

I have done some theta "band ratio" calculations in quasi-real-time with LabVIEW.

 

What is the bandwidth (or sampling rate) of your raw data? How many samples do you read at a time? How are you defining alpha, beta, and theta power? How do you define "real-time" or, more specifically, what is the maximum latency you cna tolerate between the collection of a set of raw data samples and the resluts of the analysis? 

 

Some of the code I have is proprietary, so I cannot give it to you, but I may be able to make suggestions.

 

Lynn

0 Kudos
Message 3 of 6
(655 Views)

I received a PM from cube0 regarding this thread. As I mentioned in my reply, I prefer to keep the relevant technical discussions on the Forum so that others may contribute or benefit. Portions of the PM are copied below, followed by my comments.

 


What is the bandwidth (or sampling rate) of your raw data?

  

    I believe Emotiv's sample per second rate is 256, but I would prefer to use 400 to keep my data analysis consistent with the literature I've read. 

 

How many samples do you read at a time?

   

    I would like for 1,024 data points to be read at a time (roughly 2 1/2 seconds) and then I would like to convert that into a spectral power form using FFT.           After that, I would like to apply the index alpha / theta (not the one I originally mentioned). 

 

 

How are you defining alpha, beta, and theta power?

 

 

     Does my last answer suffice for this? I'll only be using one electrode for the index @ Cz. 

 

How do you define "real-time" or, more specifically, what is the maximum latency you caa tolerate between the collection of a set of raw data samples and the resluts of the analysis? 

 

     It doesn't need to be "completely" real-time. A couple of sentences of latency is OK. 

 

To give you an idea, I would like for the index to be calculated and for fluctuations in the value of that index to be capable of triggering conditional actions or macros. However, the ability of whatever program or programs I use to trigger keystrokes or inject commands into another program is essential. 

 

I'm somewhat new to EEG but very new to programming, so I'm supremely useless at the moment in this area. I'm open to using LabView, Mind Worksation, etc. ...


 

If Emotiv's sampe rate cannot be changed, you will  be stuck with 256 samples per second. LabVIEW has a Resample VI but it cannot create any new information at higher frequencies which was not in the original data. You will have to decide whether compatibility with the literature is more important than using the equipment you now have.

 

To get 1024 samples, you can either accumulate the samples in a buffer from the setup you have which appears to read 30 samples at a time, or change the device (if feasible) to read 1024 samples at a time. The latter depends on your hardware device and what it can do.  I have no knowledge of that device and cannot advise you on that.

 

An FFT of the data calculates the spectrum. What portion (frequency range) within that spectrum is assigned to alpha, beta, and theta? From my past experience a theta wave is not always present. Do you calculate the index differently if a wave is present in a band or not?

 

When you wrote "A couple of sentences of latency..." did you mean a couple of seconds? Seconds is not a problem. Calculating a 1024 point FFT takes only a few milliseconds and the rest of the calculations are like much faster.

 

The ability to control or communicate with another program is not universal or standardized. It depends on what options the developer of that program included.

 

Lynn

0 Kudos
Message 4 of 6
(632 Views)

If Emotiv's sampe rate cannot be changed, you will be stuck with 256 samples per second. LabVIEW has a Resample VI but it cannot create any new information at higher frequencies which was not in the original data. You will have to decide whether compatibility with the literature is more important than using the equipment you now have. To get 1024 samples, you can either accumulate the samples in a buffer from the setup you have which appears to read 30 samples at a time, or change the device (if feasible) to read 1024 samples at a time. The latter depends on your hardware device and what it can do.  I have no knowledge of that device and cannot advise you on that.

 

   I learned the following when researching this: "EPOC has a fixed sampling rate of 128 Hz. Internally it is oversampled at 2048 Hz per channel but this bandwidth is used to remove very high frequency artefacts (mainly high harmonics    of the electrical makns frequency) which otherwise alias to brain frequencies. The signal is heavily filtered and reduced to 128Hz for wireless transmission. The main reason other systems offer higher sampling rates is to allow              enough bandwidth to remove these signals anyway (ok, there are other reasons too, such as looking at very fast evoked potentials, but EPOC has an upoer bandwidth limit of around 43Hz anyway to avoid 50Hz and 60Hz                    interference).

 

   So it would look like I would need to collect samples in a buffer. 

 

An FFT of the data calculates the spectrum. What portion (frequency range) within that spectrum is assigned to alpha, beta, and theta? From my past experience a theta wave is not always present. Do you calculate the index differently if a wave is present in a band or not?

 

 

    Apologies. Frequency ranges are the following: Alpha 8-12hz , Beta 13-22 hz. I would like to use the index alpha / beta, actually. Due to the sensitivity of the theta wave's behavior on brain typography, I've decided to remove theta from the index and opt for the alpha / beta index as some other researchers have. About calculating the index if a wave is present in a band or not, I'm not sure I understand. 

 

When you wrote "A couple of sentences of latency..." did you mean a couple of seconds? Seconds is not a problem. Calculating a 1024 point FFT takes only a few milliseconds and the rest of the calculations are like much faster.

 

   Oops! Great, I suspected it'd probably be this quick. Again, I'd like for the index to be calculated every 2.5 or 5 seconds, and for conditional actions to established that trigger different keystrokes or launch different programs depending on the average value of the index over the preceding 2.5-5 second period. 

 

Thanks again for your help. 

 

 

0 Kudos
Message 5 of 6
(613 Views)

It sounds to me like whoever designed EPOC did not know how to do it right and so took a bunch of software shortcuts to overcome the shortcomings of their hardware.  Sorry but it looks like you are stuck with 128 Hz while using that equipment.

 

Now, the number of samples read on each loop of the program has little to do with the sampling rate, although the rate does set a limit. Using the EPOC rate of 128 Hz (samples per second) let's look at some possibilities. If you read once per second and read all available samples, you would get 128 samples on each read. If you read 16 times per second, only 8 samples would be available for each read. One complication is that the clocks which determine the sample rate and the read (or loop) rate are usually different clocks. Unless their frequencies are perfectly accurate or synchronized, they will eventually drift apart. The effect would be that sometimes you would get 7 samples or 9 samples rather than 8.  To further complicate things you could read (or attempt to read) more samples or fewer samples than are currently available.  What occurs in those cases depends on the hardware and software being used. Trying to read 1000 samples from a 128 sample/second converter once a second would either produce an error, would cause it to wait ~8 seconds, would report old samples which had already been read, or possibly other behavior. If you only read one sample each second while the converter was acquiring 128, you will soon get a buffer overflow error because you are not reading the data fast enough to keep up.

 

I am not sure how clear that is, but the idea is that the sample rate and the number of samples read are related but different concepts.

 

Most likely you will want some kind of buffer. It will give you mcuh more flexibility in handling and analyzing the data.

 

Alpha and beta frequency ranges are what I was after.

 

We see signals similar to these two graphs indicating that theta is not present or is present. Do alpha and beta turn on and off like that?

 

to Theta or not to Theta.png

 

Although this quick simulation does not show it, the energy in the theta band during non-theta episodes is usually significantly lower. Is that what you are trying to detect?

 

Lynn

0 Kudos
Message 6 of 6
(605 Views)