Olimex OpenEEG

About

Sleep Tracking

The Olimex EEG-SMT is a device that connects to a computer via USB. It allows you to monitor parts of the brain and record data during sleep. You can then visualise and mark this data to see what your sleep was composed of.

The accuracy or quality of readings varies greatly from user to user. This difference in accuracy could be due to computer hardware or the surroundings at the time of recording. In some cases sources of interference affecting quality can be identified and bypassed.

Assuming clear reliable readings can be set up, it’s fairly easy to determine what types of sleep you went through. As in this example (seen the image below), where the part showing sleep stages at different times is determined by the user after the sleep, and the blue spectrogram would be dependant on the computer, environment and electrode placement used along with the Olimex to record the sleep.

Other applications

According to Olimex, “Many people are interested in what is called neurofeedback or EEG biofeedback training, a generic mental training method which makes the trainee consciously aware of the general activity in the brain. This method shows great potential for improving many mental capabilities and exploring consciousness. Other people want to do experiments with brain-computer interfaces or just want to have a look at their brain at work.”

What this means is that the device can be used for more than sleep recording, which is worth considering when comparing it to other sleep tracking solutions in terms of price.

Data viewing and marking tools

SleepEEGTools (Spectrogram Analysis)

The main way to view and mark Olimex EEG sleep data is with SleepEEGTools (seen in the image above). This software displays Olimex EEG data as a spectrogram.

With it you can select the various sleep stages by clicking different parts of the spectrogram, then save the sleep stages you’ve selected and view them the next time you open that reading.

It is common practice to check their marking with others on the Polyphasic Sleeping Discord server by sharing screenshots of this program, especially among new users.

Marking Guide

See the image below for a visual reference for the guide.

Readings can start with wake followed by NREM1. The wake state may be blank, or in some cases a indicated by a thin bold frequency around 10 Hz (the latter is not shown), with NREM1 being largely blank.

NREM2/3 is often indicated by a thick bold frequency between between 10 and 15 Hz, with a varyingly thin frequency below that.

The NREM3 or SWS will have a more intense frequency than the NREM2 in the 0 to 10 Hz range. This increase in intensity may be present throughout the 0 to 10 Hz range, or it may be limited to a thick bold frequency between 5 to 10 Hz range (the latter is not shown).

The REM can be seen as the upper NREM2/3 frequency moving up to around the 20 to 25 Hz range before coming back down at the end of a cycle in a bow shape. For some the bow shape may not be present, in which case it may appear as that upper NREM2/3 frequency disappearing for the duration of the REM period. Additionally there would commonly be a thin frequency between 0 and 10 Hz (thinner than that of NREM2/3 usually).

REM would be easier to identify in a core due to its positioning between sleep cycles. After this is done you can try to spot that visual representation in shorter naps, where you don’t have full sleep cycles for context.

A quick word on interference: generally it is unlikely to make one sleep stage look like another, outside of making readings harder to distinguish in general.

If your reading differs significantly from what has been described above, it may still be possible to determine sleep stages. Please check the General Marking section.

Raw Data Plots

Viewing parts of raw data plots can sometimes be a useful way to confirm a specific sleep stage after marking sleep data visualised in its entirety.

A commonly used Windows application that can produce these plots and is DatPlot. It’s setup and usage with Olimex data is described in the setup section.

Marking Guide

The identifiers you would be looking for might not be visible on the scale of a core sleep that lasts multiple hours, so you would have to know where to expect an event and look for it on a scale where it would be visible, such as several minutes, or in some cases in a 20 minute nap.

A REM movement can indicate the start of REM sleep and can last 1-3 seconds. These movements can appear in clusters separated by a few seconds (an example of one is shown in the image below).

NREM2/3 can be indicated by k-complexes which are pulses lasting around 900 ms, appearing at most 1-3 times a minute. Unlike REM movements, k-complexes should be visible in channels which are further away from the eyes. They may look roughly as follows:

Note: k-complexes can often be followed by spindles (or a set of several pulses in a lower frequency than the k-complex pulse), though they haven’t been spotted in Olimex readings.

These events generally do not max out the frequency range, so events which do are most likely noise.

Another thing to note, the images above are meant as general examples of what the events might look like and their appearance would vary depending on what timescale you’re looking at. Therefore you should pay close attention to whether matching visual events line up with the time scale that these events would normally take place in.

General Marking Guidance

To identify sleep stages based on EEG data from scratch (or to get additional confirmation of marking performed) with the visualisation methods mentioned above: it is a good idea to read up on the sleep mechanics, as this would give you a better understanding of what to expect from a reading.

It might also be a good idea to start with a core sleep recording, if possible, so you can get an initial visual representation of every sleep type there is from the start.

Additionally, the community of sleep trackers on the Polyphasic Sleeping Discord server will likely be able to help you with marking if you ask nicely, as experience in marking different EEG readings (and sleep patterns in general) can make it easier to mark the readings whether your reading looks the same as most or differs in some way.

Parts

Hardware

EEG

You will need the main EEG-SMT device, and 5 electrodes.

According to the manual, “You can either choose to use 5 passive electrodes or 4 active electrodes + 1 passive electrode (needed for electrical feedback). However, when using active electrodes instead, no skin preparation is required and better performance can be achieved under imperfect conditions.”

The above parts are available on the Olimex website.

You also need a USB cable with a type B connector to use the device, a 1.5 metre length is usually recommended.

Accessories

You’ll need some way to hold the electrodes on your head while you sleep. Some examples of ways to achieve this are covered in the electrode positioning description in the Hardware Setup section.

Software

Firstly you need are a way to record the sleeps with the Olimex. The most common way to do this is with OpenViBE. Though, theoretically you should be able to use any software which has support for “OpenEEG Modular EEG P2” devices. There is also a open source project called SleePi on GitHub for this purpose.

Secondly, you need a way to look over the whole reading, to be able to view mark it. SleepEEGTools is a commonly used spectrogram tool for this purpose.

Thirdly, you may want a way to plot the reading in its raw form for viewing of some markers which benefit from this type of view. A commonly used Windows tool for this purpose is DatPlot.

The data viewing and marking tools section covers the use of some of the commonly used software.

For Windows 10 users, there is a guide detailing how to install everything you need for recording and marking (mainly with the most commonly used software).

Olimex also has a manual for setting up the device which may be worth looking at.

Hardware Setup

Initial Device Setup

Note: there isn’t any real need to remove the electrodes once they’re been plugged into the main device, and doing so has caused the electrode jacks to break for some users, so it’s best to avoid it by making sure they’re plugged in correctly from the start.

To get the EEG-SMT ready (with the above in mind), identify the one passive electrode (if you got one passive and four active electrodes) and plug it into the DRL jack. Compared to the active electrodes it should not have black parts on the cable side. Plug the rest in the remaining sockets.

Electrode positioning

The DLR electrode (used for feedback or noise cancellation) can go on the ear (as stated in the Olimex manual) or in the middle of the forehead, good results have been achieved with both for sleep tracking purposes. The rest of the electrodes change position based on what you want to track.

There are a couple of basic ideas concerning sleep tracking with the Olimex: there are two electrode pairs (or channels), data relevant to sleep is generally recorded on/around the forehead and/or the eyes.

The most basic electrode layout would be to ignore the distinction between the two channels and position the electrodes in a line on the forehead randomly (with the DLR in the middle). This can work well enough.

Taking the channels individually, you can get a more diverse/complete data set by focussing on a specific area with each channel. One channel could be on the forehead as mentioned previously, and the other could be closer to or around the eyes for more REM data detail in that channel. Both channels could also be around each eye.

Positioning around the eyes can be better for sleep tracking. Some layouts (of electrode pairs) with the eyes in mind include: placing one electrode above and one below the eye, one electrode next to the eye (on the outer side of the face) and one above, placing all electrodes on the forehead (with one channel over the eyes and the other higher up).

It’s worth trying out different layouts to get the best readings.

Common Electrode Placement Solutions

This section covers common ways to hold the electrodes on the head for sleep tracking.

Elastic Headband

One of the most simple ways to apply a headband is to put the electrode wires through the headband at the back of your head (going up), over the top of your head towards the front, where the ends of the electrodes could be held anywhere the band goes.

This is a decent way to get the electrodes in place without much initial preparation, but it will mean that you will have to adjust the position of the electrodes each time, rather than just placing an assembled placement solution on the head. And this way is fairly limited to the forehead area, realistically.

To make the headband easier to use day-to-day, you can sew the electrodes in place. This would remove the short prep time you would otherwise have to go through every time you use it.

Additionally you could combine multiple headbands in a DIY solution to more rigidly position electrodes in specific places.

Ski goggles

The shape of ski goggles allow the positioning of electrodes around the eyes and can be a good general base for attaching the electrodes in general. The cover of the glasses can be removed to make them more practical indoors.

This solution may be slightly more involved than a simple headband, with some DIY effort required, but the eye based recording could yield better results.

Note: the ski goggles need to be rigid to ensure that the electrodes don’t move during sleep.

Software Setup

Windows 10 Software Setup for Sleep Reading and Marking

Then to get the device recognised by your computer, get the ‘setup executable’ in the  ‘Windows*’ row here . Install that and restart your PC.

After doing so (if you have the EEG device plugged in), your mouse may start going crazy. You can unplug the EEG for now. To stop the mouse glitch you can go into the registry (Start > Run/Search > “regedit” > Enter), and edit the ‘Start’ to 4 value in the following entry: “HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\sermouse”. It should be 3 by default. Then, plug in the EEG again and the mouse shouldn’t move on its own anymore.

OpenViBE Setup

Download and run the stable windows installer for the OpenViBE software from this page. This is what you’ll need to record the sleeps with the device, so run through the installer.

Once you’ve installed OpenViBE to do the recording, you’ll need to run ‘OpenViBE acquisition server’ and ‘OpenViBE designer’ each time. They should be in the start menu.

To set up the acquisition server, you’ll need to know the COM port of the EEG device. You can get this by right clicking on the Windows icon and on selecting Device Manager. From the top menu in device manager, in view, click ‘Show hidden devices’, if it’s not ticked. Then look in the ‘Ports (COM & LPT)’ section, if there is only one item, that COM port will be the EEG, if there is more than one, you can right click and check properties for each until you find one that has the ‘Manufacturer’ listed as ‘FTDI’. Note the COM port number.

Now plug in the EEG (if it’s not already plugged in) and run the acquisition server. In the window that appears, from the ‘Driver’ dropdown select ‘OpenEEG Modular EEG P2’. Then click the ‘Driver Properties’ button, and in the window that pops up: change the ‘Number of channels’ to 2 and set the ‘Device’ to the COM port you previously identified.

Click Apply on the ‘Device configuration’ window and click Connect and Play. You should then see ‘Receiving…’ and ‘0 clients connected’. In this state, when you set up the other part of OpenViBE, you will be able to connect to the device and record sleeps. When you confirm this state, click Disconnect, and close the Acquisition Server windows for now. Closing them properly like this will make it remember the configuration, when you run it next time. Unplugging the EEG while the acquisition server is running can cause it to crash, in which case the settings are not saved (unless they were already saved previously).

Next run the ‘OpenViBE designer’. Create a new design from the new option from the ‘File’ menu at the top.

In the search box (to the right of the interface): type ‘acquisition’ and drag-and-drop Acquisition client to the design workspace (to the left in the interface).

Then in the search box: type ‘display’ and drag-and-drop the Signal Display box to the design workspace.

Finally in the search box: type ‘writer’ and drag-and-drop the ‘CSV File Writer (Deprecated)’ box to the design workspace. The deprecated version specifically is necessary for the other software to work, so make sure you have the right version.

Then connect the three elements as shown in the image below.

To set up the CSV File Writer, double click on it. Then in the new window, next to the filename, click on the button to browse to a location where you want your readings to be saved. While browsing, set the name to “record-[$core{date}-$core{time}].csv” or something similar. This will put the date and time of the recording in the name when saving, so it will be easy to identify specific readings. When you’re done browsing, click Apply.

Now save this design setup with the ‘Save’ option in the File menu at the top. The design you save should be loaded automatically the next time you run the Designer.

At this point you’re ready to record sleeps. If the acquisition server is running in the previously described state, you can press the play button to start recording and see a live preview of the signal. You can close the OpenViBE windows for now.

SleepEEGTools Setup

Next is the setup of the SleepEEG tools for sleep viewing and marking. To run the SleepEEGTools, you’ll need python 3. It’s available here. Use the big button that says  ‘Download Python 3…’. Then run the installer that you downloaded. On the first screen make sure the ‘Add Python … to PATH’ is checked.

Then click Install Now. You can close it when it’s done.

Next you’ll need to go here and look for the ‘Tools for Visual Studio …’, then from that section you can download the ‘Build Tools for Visual Studio’. Run the installer.

When you see the ‘Workloads’ options, check ‘Visual C++ build tools’ and click install. Once it’s done, you close the installer and restart.

Now find the ‘Visual Studio …’ folder in your start menu and run the ‘x86_x64 Cross Tools Command Prompt …’. In the window that pops up, type: ‘pip install numpy spectrum matplotlib’ and press enter.

Finally visit https://github.com/PolyphasicDevTeam/SleepEEGTools and click on ‘Clone or download’ and select ‘Download ZIP’. Extract what you download and place it somewhere you’ll be able to find it. With that stuff installed, you should be good to go for sleep marking.

At this point the basic setup is complete.

Reading and Opening Readings for Marking

To record, make sure the EEG is plugged in with the red light on, run ‘OpenViBE acquisition server’ and click Connect and Play, then run ‘OpenViBE designer’ and click the play button at the top to start recording, then the stop button to stop recording.

To mark sleeps with this setup go into your SleepEEGTools folder, right click while holding shift, and click ‘Open PowerShell window here’. Once the PowerShell window opens, run the marking tools by entering ‘python open.py’ which opens a browsing window. Here you would locate a reading, which would then open up the marking window.

For a readout marking guide see the SleepEEGTools section under ‘Olimex EEG data viewing and marking tools’.

OpenViBE acquisition server’ Additional Setup

To potentially make the signal from your EEG less noisy: go in the OpenViBE acquisition server Preferences menu, make sure ‘Drift Correction’ is set to ‘Disable’ and click ‘Apply’, then try to tweak the sampling frequency (in the ‘Driver Properties’ menu) such that drift builds as slowly as possible. In other words, try to ‘connect’ and ‘play’ when your device is plugged in and see how much the drift value (given in ms) moves up or down over time, then try different sampling frequency values to see which is closest to a consistent amount of drift.

Datplot Setup and Usage

You can download Datplot here. Installation should be straight forward, if Windows produces some errors, restart and try again.

To use it for displaying Olimex data:

  1. Select ‘Load New Data Source…’ in the file menu at the top and find a reading, in the import window that pops up: set ‘Get column (parameter) names from line’ to 1, set the ‘Column delimiter’ to semicolon, and click ‘Import Data’.
  2. Then in the top right ‘X-Axis parameter’ dropdown select ‘Time (s)’, right click on the empty graph and select ‘Add’ in the ‘Graph Pane’ menu.
  3. In the top chart right click > ‘Data Curve’ > ‘Add’, select ‘Channel 1’ from the ‘Parameter Name to Plot’ dropdown, click ‘Plot  Curve’ and close.
  4. Repeat step 3 with the bottom chart and select ‘Channel 2’ instead of ‘Channel 1’ where applicable.
  5. For each of the charts: right click the plotted data line > ‘Data Curve’ > ‘Format’, in the menu that pops up click ‘Hide Symbol’ > ‘Apply’ > ‘Close’.
  6. Use the scroll wheel on the mouse for zooming/panning.

The right click options for charts allow you to scale charts to fit data in various ways, which can be useful.

Note: the program will work slower or faster depending on how fast your hardware is (faster CPU and/or more RAM means better performance) and more importantly how long the sleep you’re loading is.

If you’re having trouble reading the data due to performance issues, you might need to edit the recording file and cut away anything you don’t want to look at specifically. You can identify a part of the sleep to read in SleepEEGTools as a guide for what to cut away and what to keep.

Main author: Litchnom