Parsing packet from openEEG EEG-SMT in Matlab
"Mark O'Sullivan" <[email protected]> Tue, 27 Sep 2016 15:44:33 +0100
| Newsgroups | gmane.comp.science.openeeg.general |
|---|---|
| Message-ID | <CAK684N=sUJ_sNH7T3iFsV3ahQ+vCGMU9=iPE9GFebwBbvscgrg@mail.gmail.com> |
Hi all,
I have been trying to continuously take data from the Olimex EEG-SMT board
and parse the data coming from the serial port in Matlab, but so far have
been unsuccessful..
I have the code currently reading in a specified amount of data, parsing it
and giving me 6 channels of data. However, I want to be able to
continuously read in data and plot the data in real-time until a user
interrupt occurs. And I can't figure out how to adapt my code for this.
My logic for parsing the data is as follows..
Each packet starts with the 2 byte sync sequence 165, 90. Followed by
version number byte, then packet number byte and then the 6 channels of raw
EEG data (2 bytes each) and finally 1 byte of button state. Which gives 17
bytes per packet.
So, I open my serial connection, read in X number of samples..
% Find all the points where 165 is followed by 90, using something like
index = find(rawData == 165);
if (index(1)+1 ==90)
firstPacketStart = index(1);
end
% Build a matrix of all the packetStarts like this..
packetStarts = (0:(N-1))'*17 + firstPacketStart;
% Build a X row, 6 column matrix with the start samples of each packet + 4
to get to the first channel of actual data.
indicesMatrix = 4 + repmat(packetStarts, 1, 6) +
repmat(0:2:10, length(packetStarts), 1);
% Fill indicesMatrix with rawData.
eegData = (rawdata(indicesMatrix)*256 + rawdata(indicesMatrix
+ 1)) - 512;
% Extract channel 1.
channel1 = eegData(:,1);
Any help with code/documentation or anything with regard to parsing the
EEG-SMT serial data in matlab or continuous plotting of the EEG channel
would be very much appreciated!!
Best regards,
Mark O'Sullivan
------------------------------------------------------------------------------