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