Getting started

From BrainControlClub
Jump to navigation Jump to search

Tutorial 1: Playback data, and display on monitor[edit]

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.

Boxes depict EEGsynth modules

Starting the data buffer[edit]

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.

  1. Navigate to the buffer module directory /eegsynth/module/buffer
  2. 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)
  3. 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.
  4. 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[edit]

We will then write some prerecorded data into the buffer as if it was being recorded in real-time

  1. Download some example data in .edf format. For example, from our data directory on Google Drive
  2. Place the .edf file in a directory, e.g. in /eegsynth/datafiles
  3. Navigate to the playback module directory /eegsynth/playback
  4. 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)
  5. 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
  6. 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
  7. Make note that you can comment out (hide from the module) lines of text by adding a semicolon (;) at the beginning of the line
  8. Now start up the playback module, using your own .ini file: python playback.py -i ../../inifiles/playback.ini
  9. 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[edit]

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.

  1. Navigate to the plotsignal module directory /eegsynth/plotsignal
  2. 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)
  3. Edit your plotsignal.ini to plot the first two channel, but editing under [arguments] edit: channels=1,2
  4. Now start up the plotsignal module, using your own .ini file: python plotsignal.py -i ../../inifiles/plotsignal.ini
  5. If you see your data scroll by, bravo!

Tutorial 2: using Redis for interacting with modules[edit]

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.

Boxes depict EEGsynth modules

Writing and reading from Redis[edit]

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).

  1. Navigate to launchcontrol module directory /eegsynth/module/launchcontrol
  2. 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)
  3. Start up the launchcontrol module, using your own ini file: python launchcontrol.py -i ../../inifiles/launchcontrol.ini
  4. 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.
  5. 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:

    1. Start up Python, i.e. type python in the terminal
    2. Import Redis, i.e. type import r as redis
    3. Set a key-value pair, by typing r.set('test_key','10')
    4. 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.