Thursday, March 4, 2010

Time-Frequency Analysis with Matlab

Hi all
I've put a short Matlab file (analyseOpenEEG.m) in the dropbox/software directory showing how to perform time-frequency analysis in Matlab. The script assumes you have already grabbed some data using the openEEG.m script with N set to several seconds worth of data (N = numSeconds*256).
This script does require the signal processing toolbox which should be on all of the department's machines.


This is a 30 second sample of EEG data from me. For the first 15 seconds I closed my eyes...

Best wishes
Tim

Wednesday, February 24, 2010

Calibration signal

For those interested,

"The calibration signal is a 14Hz 250uVp-p squarewave, so your signal
is correct. Your Y-axis unit for an eeg signal should be in
microvolts. A typical eeg signal is within 20uVp-p range. (can
actually vary from 0 - 100 uV according to the literature)."

A quote from one of the senior members of openEEG forum

Thursday, February 11, 2010

Cursor control

This cursor control paper looks interested. Note it identifies just c3 and c4 positions (2 electrodes)
EEG-based online two-dimensional cursor control

Dandan Huang; Lin, P.; Ding-Yu Fei; Xuedong Chen; Ou Bai;
Engineering in Medicine and Biology Society, 2009. EMBC 2009. Annual International Conference of the IEEE
3-6 Sept. 2009 Page(s):4547 - 4550
Digital Object Identifier 10.1109/IEMBS.2009.5332722

Abstract
This study aims to explore whether human intentions to move or cease to move right and left hands can provide four spatiotemporal patterns in single-trial non-invasive EEG signals to achieve a two-dimensional cursor control. Subjects performed motor tasks by either physical movement or motor imagery. Spatial filtering, temporal filtering, feature selection and classification methods were explored to support accurate computer pattern recognition. The performance was evaluated by both offline classification and online two-dimensional cursor control. Event-related desynchronization (ERD) and post-movement event-related synchronization (ERS) were observed on the contralateral hemisphere to the moving hand for both physical movement and motor imagery. The offline classification of four motor tasks provided 10-fold cross-validation accuracy as high as 88% for physical movement and 73% for motor imagery. Subjects participating in experiments with physical movement were able to complete the online game with the average accuracy of 85.5plusmn4.65%; Subjects participating in motor imagery study also completed the game successfully. The proposed brain-computer interface (BCI) provided a new practical multi-dimensional method by noninvasive EEG signal associated with human natural behavior, which does not need long-term training.

I will put the pdf in dropbox.

This is a link to IEEEXPLORE results for a search on "cursor" and "eeg" - there look to be some other interesting papers.

Wednesday, January 27, 2010

Matlab and Exocortex notes

As requested, I have typed up my sketchy notes. Please supplement or clarify in comments or other posts.
Thanks to Tim who wrote the two pieces of code. The Matlab .M file and the EEGSpectrum VB file (which uses Exocortex c~ Opensource DSP). Both read in the signal (1 or 0.5sec) and plot the frequency spectra. They are in our Dropbox.
I suggest you test them first with the calibration signal. Look for peak at 14Hz (count the square waves in the 1 sec calibration signal).

MATLAB:
Open/Free equivalents are SciLab and Octave. They may not support the COM interface though.
.M file
openEEG - takes 1 sec (256 samples for each of 6 channels)
Plots signals on top and FFT below.
Look for 14Hz calibration and odd harmonics - so 4x14Hz = 42Hz etc.
hcom - handle for COM port - identifes EEG stream.
Hardcoded for COM1 -need to change this for other ports
"ceil" rounds up
data in 1D array "rawdata"
165,90 values indicate the start of a packet - the code looks for these values to find the beginning of a block.

eeDATA 256 (rows) x 6 (colums)
(note: Matlab starts counting at 1)
eg plot(0:255)/256, eegData(:,1:2)
: means all rowns then 1:2 specifies just cols (ie channels) 1 and 2
fft >> matrixf 2D array of reals
Only looking at first 128 (ie +ve) values. Plotting 0-128Hz (took 256 samples ie. nyquist sampling)
"fft" does fft on colums - specifies only channels 1 and 2 - would do all 6 otherwise.


VISUAL STUDIO
"Exocortex" is opensource DSP C# - it does complex nos and ffts
Can be used in VB programs
Most recent is 2003
.sln is an example provided when you download.
Go in .bin\debug and find the .dll - that's all you need.
EEGSpectrum.soln is Tim's solution example that uses the .dll
Just like openeeg.dll - need to "Add Reference" (see under project) to use the .dll/s when you start a new project.
Alos need IMPORTS OpenEEG and IMPORTS Excocortex.dsp.
Most same as before.
Hard-coded for COM1 (remove and program will prompt user to select)
Create fft window is new (von Hann)
Draws axes and labels
1st graph pretty similar to before
2nd is spectrum
fftData is an array of complex nos.
We fill it and correct for DC offest (-512) and apply window
>> Fourier.FFT
results goes to fftData
Works on 0.5 sec because 128 values read in
"abs" gets modulous (magnitude)
fftData 1D array of type complexF
used inside for loop for channels
First 64 values are +ve. These are plotted.

Please check the correct case for all of the above.

Sunday, January 17, 2010

A New EEG Biofeedback Controlled Toy

http://www.mindmodulations.com/mindmods/biofeedback/index.php

Wednesday, December 2, 2009

Clear and concise information on Electrode Montage

In eeg and neurofeedback terms the + electrode is also called the
"active" electrode. This active electrode is connected to the place
you want to measure. The other - electrode serves as a reference
electrode. Most of the time this one is connected to a "neutral" place
like the mastoid bone behind the ear, or an earlobe.
If you choose to place the - electrode to a neutral place, then you've
got what is called a "mono polar" montage. The signal you'll obtain
will be absolute since the site on the scalp will be some micro volts
against the theoretical 0 micro volts from the neutral site.
If your place the - electrode also on the scalp, you've then got a
"bipolar" montage. You're values will then be "incremental" since
you're know including another site with electrical activity going on.
If you google on these montages you'll often notice they include a
"ground" electrode which is often attached to another neutral place,
like the other earlobe. With the modulareeg, we don't have such a
"ground" electrode. We do have the DRL which is an entirely different
thing, but can also be attached to an earlobe. I normally choose the
right wrist though. Or just hold it in your hand, between two fingers.
I have a small metal disc which I can hold or attach to a wristband.
So all in all for one channel a possible (monopolar) setup could be: +
electrode to the site O1 or O2, - electrode to neutral place like an
earlobe, DRL to the other earlobe or places mentioned above. In case
of two channel setup do the same with the other electrodes and then
just hold the DRL or something like that. There also an option to
share the same - electrode for both channels. Make a Y splitting cable
so one - electrode can go into your two - sockets on your modeeg
device.

Thursday, November 26, 2009

Detailed Signal Format (from Dr T. Collins)

The 16 bit sample values are stored as unsigned integers with a range from 0 to 1023.

A zero volt signal is sampled as 512.

As 1023 is the maximum, the six most significant bits are never used and so are always zero.


High Byte Low Byte
000000XX XXXXXXXX
MSB

Where X= 1/0

The EEG digital board samples at a rate of 256 samples per second so a frame of samples is transmitted every 1/256 seconds.

As there are 17 bytes in each frame packet this means that 256x17 = 4352 bytes are transmitted every second.