Tutorial 1: Playback data, and display on monitor
We will start with the following setup wherein we will playback data to the buffer as if it is recorded in real-time. This is convenient, since it will allow you to develop and test your BCI without having to rely on real-time recordings.
Starting the data buffer
The EEsynth uses the FieldTrip buffer to communicate data between modules. It is the place where raw (or processed) data is stored and updated with new incoming data. For more information on the FieldTrip buffer, check the FieldTrip documentation.
- Navigate to the buffer module directory /eegsynth/module/buffer
- Copy the buffer.ini to your own ini directory (e.g. to /eegsynth/inifiles, which would be in ../../inifiles relative to the buffer module directory)
- Start up the buffer module, using your own ini file: ./launchcontrol.sh -i ../../inifiles/launchcontrol.ini. Note here that the buffer module is one of the few modules that are an executable written in C, run from a bash script rather than Python. However, it does function exactly the same concerning the user-specific ini files.
- If the buffer module is running correctly, it does not print any feedback in the terminal. So no news is good news!
Writing pre-recorded data from HDD to the buffer
We will then write some prerecorded data into the buffer as if it was being recorded in real-time
- Download some example data in .edf format. For example, from our data directory on Google Drive
- Place the .edf file in a directory, e.g. in /eegsynth/datafiles
- Navigate to the playback module directory /eegsynth/playback
- Copy the playback.ini to your own ini directory (e.g. to /eegsynth/inifiles, which would be in ../../inifiles relative to the buffer module directory)
- Edit your playback.ini to direct the playback module to the right edf data file, e.g. under [playback] edit: file = ../../datafiles/testBipolar20170827-0.edf
- Edit the two playback.ini options for playback and rewind so that it will play back automatically (and not rewind): play=1 and rewind=0
- Make note that you can comment out (hide from the module) lines of text by adding a semicolon (;) at the beginning of the line
- Now start up the playback module, using your own .ini file: python playback.py -i ../../inifiles/playback.ini
- If all is well, the module will print out the samples that it is 'playing back'. This is that data that is successively entered into the buffer as if was just recorded
Plotting streaming data in the buffer
If you made it so far the buffer is working. However, we can now also read from the buffer and visualize the data as it comes in, using the plotsignal module. Note you need to be in a graphical environment for this.
- Navigate to the plotsignal module directory /eegsynth/plotsignal
- Copy the plotsignal.ini to your own ini directory (e.g. to /eegsynth/inifiles, which would be in ../../inifiles relative to the buffer module directory)
- Edit your plotsignal.ini to plot the first two channel, but editing under [arguments] edit: channels=1,2
- Now start up the plotsignal module, using your own .ini file: python plotsignal.py -i ../../inifiles/plotsignal.ini
- If you see your data scroll by, bravo!
Tutorial 2: using Redis for interacting with modules
Now we have set up a basic minimal pipe-line with data transfer, we can introduce communication between modules used the Redis database. Redis is the place where modules communicate via 'key-value' pairs. Read the online documentation on the EEGsynth website for more background on the use of Redis.
Writing and reading from Redis
After installation of the EEGsynth, the Redis database should be running in the background at startup. To check whether Redis is working you can monitor Redis while adding and reading 'key-value' pairs. For the purpose of the tutorial we will use the LaunchControl MIDI controller to enter values from the LaunchControl to Redis. If you do not have a Launchcontrol, you can enter values by hand. We will discuss this as well (just skip this part).
- Navigate to launchcontrol module directory /eegsynth/module/launchcontrol
- Copy the launchcontrol.ini to your own ini directory (e.g. to /eegsynth/inifiles, which would be in ../../inifiles relative to the launchcontrol module directory)
- Start up the launchcontrol module, using your own ini file: python launchcontrol.py -i ../../inifiles/launchcontrol.ini
- You will see the connected MIDI devices printed in the terminal. If you have not set up the .ini file correctly yet, read out the MIDI device name from the output, and replace the device name, e.g. device=Launch Control under the [midi] field of your .ini file.
- Now restart the launchcontrol module. If everything is working correctly, a move of any of the sliders will print a key-value pair in the terminal.
You can also add values to Redis directly in Python:
- Start up Python, i.e. type python in the terminal
- Import Redis, i.e. type import r as redis
- Set a key-value pair, by typing r.set('test_key','10')
- Read a key-value pair, by typing r.set('test_key')
You can now monitor the actions of Redis by opening a new terminal window and running redis-cli monitor. You should be able to see both set and get actions. So monitor this window while adding values in Redis as described above to see if it is working correctly.