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