-
Notifications
You must be signed in to change notification settings - Fork 21
Data Handling
SBS2 can be used to record EEG data, timed information about events (such as stimuli presentation or user responses), and data from other sensors.
Sbs2 by default creates two type of files for every recording:
After the recording of EEG data is completed, you should be able to find two above files in "smartphonebrainscanner2_readings" directory on your tablet/smartphone's sd card
(for developers: Set files location)
To convert these files into other convenient formats go to Scripts repository on GitHub and download the the whole repository by clicking "Download ZIP" button on the right. There you will find both Matlab and Python scripts to help you handle the data.
Copy the .raw and .meta files from your EEG recording device to your computer and you are ready to start converting the data.
Raw EEG recording and .meta file can be combined into .txt space-separated file using python script. For this you will need the decodeData.py file from 'python' folder in the scripts that you have downloaded from GitHub.
####Windows
- Install python inerpreter version 2.7.5 (note that using version 3.3.4 may fail to execute decodeData script) (by default in location: C:\Python27)
- Save your decodeData.py file in the same location you installed python interpreter (e.g. C:\Python27)
- Open Command Prompt terminal (Start->Programs->Accessories->Command Prompt or Start->Search:"cmd")
- In the terminal go the folder where you have installed python, typically you would type the command "cd C:\Python27" after which you should see C:\Python27>
in the Command Prompt type:
python decodeData.py /path/to/raw/file.raw
####LINUX python /path/to/decodeData.py /path/to/raw/file.raw
####Text file Produced .txt file will appear in the directory where the .raw and .meta files reside.
(To see the output generated by the python script click here)
When you have obtained .txt file using python script you can further manipulate it in Matlab.
Open Matlab and load sbs2_demo_rawdata2matlab.m file from 'scripts/matlab' in the core package.
Locate following two lines in the script and fill them with the name of .txt and .meta files
fname = {'emotivData_2012_02_06_12_00_17_demo01'} %Filenames (.txt & .meta)
fpath = '/home/cs/smartphonebrainscanner2/data'; %file path
This will create the set of data in Matlab for further analysis.
With the data imported to matlab this can be converted into EEGLAB for further analysis by the function sbs2_convert2eeglab.m. This function allows the user to
- Create EEG structure
- Assign channel labels and default positions
- Assign event information
- Do epoching with a specified time window
- Do baseline correction
A demo example of how to transform raw data into EEGLAB format is given in sbs2_demo_rawdata2eeglab.m.
With data imported to Matlab workspace using the sbs2_rawdata2matlab.m function, the data can be converted to Fieldtrip format fairly simple. A demo example is given in sbs2_demo_rawdata2fieldtrip.m. This script demonstrates how the continuous data is loaded and how to epoch the data if event markers are present from the .meta file.
It is possible to convert data to SPM8 format by first importing the data using the sbs2_rawdata2matlab.m and then organizing the data in accordance to the Fieldtrip format. Hereby the SPM function spm_eeg_ft2spm.m can be used to convert data from Fieldtrip format to SPM8 format. A demo script sbs2_demo_rawdata2spm.m illustrates how continuous raw data can be converted to SPM8 format.
The .raw files contains binary, decrypted dump from the EEG system (currently Emotiv EPOC). This files does not include any timing information and is a simple stream of 32bytes/packet.
The .meta files includes all the additional information for the EEG recording. The header (first line) is in format:
username:description:timestamp_created:reserved:device_serial_number
Subsequent entries are in the format:
event:timestamp:current_eeg_packet
A special event is START indicating beginning of the EEG recording. It should always happen on current_eeg_packet = 1:
START:1340196166896:1
Other events can be simply added in the code using insertIntoMetaFile(QString event)
method from Sbs2Callback
.
Using both .raw file and .meta file a .txt file can be produced using Python script (see next section). This is file containing EEG recording as a space-separate columns. The file looks like this:
no timestamp gyroX gyroY P7 FC6 T7 P8 O2 O1 FC5 F3 F4 T8 F7 F8 AF4 AF3 counter cq
1 1337342088724 1497 1804 6931 8451 8806 9136 9082 8380 8641 8632 8490 8736 7474 8620 8752 8267 3 F7:515
2 1337342088732 1498 1804 6936 8441 8793 9126 9101 8393 8633 8613 8473 8736 7447 8595 8730 8246 4 T7:521
3 1337342088740 1498 1802 6937 8418 8777 9106 9096 8389 8603 8599 8464 8709 7440 8568 8716 8227 5 P7:483
4 1337342088747 1498 1804 6953 8439 8770 9119 9102 8399 8605 8611 8475 8739 7444 8579 8732 8229 6 O1:510
5 1337342088755 1499 1804 6955 8471 8749 9121 9101 8394 8628 8629 8481 8774 7440 8595 8747 8238 7 O2:470
6 1337342088763 1498 1806 6929 8466 8734 9122 9071 8362 8622 8626 8473 8762 7446 8574 8737 8239 8 P8:467
7 1337342088771 1499 1807 6918 8457 8753 9138 9068 8354 8607 8628 8475 8765 7438 8542 8725 8231 9 T8:476
8 1337342088779 1498 1807 6925 8471 8767 9117 9086 8387 8622 8637 8479 8789 7439 8539 8731 8231 10 F8:495
9 1337342088786 1499 1806 6914 8473 8766 9051 9076 8397 8644 8629 8462 8785 7480 8535 8734 8233 11 AF4:474
10 1337342088794 1497 1804 6900 8455 8771 9059 9056 8367 8634 8609 8440 8789 7498 8508 8715 8218 12 FC6:486
11 1337342088802 1498 1805 6902 8451 8774 9104 9051 8354 8632 8602 8434 8815 7498 8475 8699 8208 13 F4:448
12 1337342088810 1497 1803 6901 8452 8771 9081 9054 8367 8654 8604 8432 8829 7528 8439 8700 8214 14
The columns denote:
- no - line number in the recording; events in the meta file are synced to this number
- timestamp - timestamp of the eeg packet created by taking the START event timestamp and counting 128/sec
- gyroX gyroY P7 FC6 T7 P8 O2 O1 FC5 F3 F4 T8 F7 F8 AF4 AF3 - raw data fields from the system
- counter - value generated by Emotiv EPOC 0 - 128, used to find lost packets (with accuracy of mod128)
- cq - channel quality field present only in packets 0-13 and 64-77 (cq value for 14 channels twice a second). The values translate to Emotiv SDK: black < 81, red < 221, orange < 314, yellow < 407, green >= 407
By default, all files produced by SBS2 are placed in the same directory. This directory is set by calling:
Sbs2Common::setDefaultCatalogPath();
and Sbs2Common::setCatalogPath(QString catalogPath_)
The default locations are:
#ifdef Q_WS_MAEMO_5
Sbs2Common::setCatalogPath("/home/user/MyDocs/smartphonebrainscanner2_readings/");
#elif defined(Q_OS_ANDROID)
Sbs2Common::setCatalogPath("/sdcard/smartphonebrainscanner2_readings/");
#else
Sbs2Common::setCatalogPath(QDir::toNativeSeparators(QDir::homePath())+"/smartphonebrainscanner2_readings/");
#endif
The script will produce output:
python decodeData.py /Users/arks/smartphonebrainscanner2_readings/emotivData_2012_05_18_13_54_48_.raw
working on file /Users/arks/smartphonebrainscanner2_readings/emotivData_2012_05_18_13_54_48_
file size is 148160
samples in the file 4630
META file is /Users/arks/smartphonebrainscanner2_readings/emotivData_2012_05_18_13_54_48_.meta
time in msec
start time 1337342088.724
frequency 128.0
time tick 0.0078125
output file /Users/arks/smartphonebrainscanner2_readings/emotivData_2012_05_18_13_54_48_.txt
finished, loss: 0 (0.00%)