Olimex OpenEEG: Difference between revisions

From Polyphasic Sleep Wiki
No edit summary
No edit summary
 
(23 intermediate revisions by the same user not shown)
Line 8: Line 8:
Signal quality depends on several factors, including electrode placement, electrical interference, and the user's environment. While results may vary, many users have successfully used this device to monitor sleep stages.
Signal quality depends on several factors, including electrode placement, electrical interference, and the user's environment. While results may vary, many users have successfully used this device to monitor sleep stages.


Generally, sleep stages follow a distinct pattern, as illustrated in the figure on the right. For more details, see section Sleep Stage Identification.
Generally, sleep stages follow a distinct pattern, as illustrated in the figure on the right. For more details, see section [[Olimex_OpenEEG#Sleep_Stage_Identification|Sleep stage identification]].


[[File:Sample Olimex data.jpg|thumb|Sleep stages in Olimex]]
[[File:Sample Olimex data.jpg|thumb|Sleep stages in Olimex]]


== Sleep Stage Identification ==
== Components ==
 
=== Hardware ===
 
[[File:Olimex.jpg|thumb|The Olimex EEG device<ref name="bakerdh" />]]
 
The main component that has to be acquired is the '''EEG-SMT device'''<ref name="eegsmt" />, which can be ordered directly from the Olimex website. Next, you will need '''electrodes'''. There are two options:
 
* 5 passive electrodes (EEG-PE)<ref name="eegpe" />
* 4 active electrodes<ref name="eegae" /> + 1 passive electrode
 
The second option is slightly more expensive but is the recommended choice. Active electrodes provide better performance under imperfect conditions and require no skin preparation.<ref name="openeeg" />
 
Finally, you will need to purchase a '''USB A to B cable'''. <ref name="eegcable" /> It is recommended to get a long cable, such as 1.8 meters, since you will be sleeping with the EEG connected to a laptop (in the default setup). The cable should be long enough to allow comfortable movement.
 
Lastly, you will need a way to secure the electrodes to your head while sleeping, which can be done using an elastic headband or other methods. The hardware setup section provides more details.
 
The standard way to set up an Olimex EEG for sleep recording is to connect it to a laptop during sleep. This method is the most widely tested by the community, so if you're unsure where to start, it's the recommended option. However, bringing a laptop to bed each night may be inconvenient. In that case, it's also possible to use a Raspberry Pi<ref name="sleepi" /> or a PinePhone, though these setups require DIY work and are not covered in this guide. If you manage to get one of these alternative setups working, please consider joining the [https://discord.com/invite/2kzXcg7Juf Discord server] and sharing your configuration. Your contribution would be much appreciated.
 
=== Software ===
 
The software setup can be done on both Windows and Linux, and potentially on macOS (though this has not been tested).
 
The first component you'll need is a program to record sleep sessions. The recommended options are OpenViBE<ref name="openvibe" /> or SleePi<ref name="sleepi" /> for Raspberry Pi. Once your recordings are complete and saved, you’ll need to load them into another program to mark the sleep stages. SleepEEGTools is the recommended choice for this task.
 
Additionally, you can use DatPlot to view the raw EEG data, for example, to visualize REM movements or detect K-complexes.
 
== Hardware setup ==
 
[[File:AE PE.webp|thumb|Active vs passive electrodes]]
 
First, identify one PE (passive electrode) and four AE (active electrodes). As shown in the image, active electrodes contain a black component (a chip), while passive electrodes do not.
 
Plug the electrodes into the main device: connect the PE to the DRL socket, and plug the remaining electrodes into the other four input sockets. Note: It’s recommended to avoid unplugging the electrodes from the device, as this can risk damaging the electrode jacks. Try to keep them plugged in at all times.
 
=== Electrode positioning ===
 
There are several ways to position the electrodes on the head. The main configurations are discussed below.
 
==== DRL in the middle, CH1 and CH2 on the sides ====
 
[[File:FP1 FP2 FPZ channels.jpg|thumb|Electrode placement at FP1, FP2, and FPZ]]
 
The simplest configuration places the DRL electrode in the middle (FPZ), with CH1+ and CH2+ above the right eyebrow (FP1), and CH1– and CH2– above the left eyebrow (FP2). This setup is reliable and allows both channels to record the same data, providing redundancy and improving data reliability.
 
==== DRL on the ear ====
 
As a variation of the setup above, the DRL electrode can also be placed on the ear instead of the center of the forehead.
 
==== CH2 around the eyes ====
 
It's also possible to sacrifice redundancy in favor of collecting more data. The first channel is used as before, but CH2 can be repurposed, for example, by placing it near or around the eyes to capture more detailed REM data.
 
=== Electrode placement solutions ===
 
[[File:Sleep mask.webp|thumb|Sleep mask electrode setup by a polyphasic community member]]
 
The electrodes need to remain attached to the head during sleep to record data. There are several ways to keep them in place, some of which are described below.
 
==== Elastic headband ====
 
The easiest way to attach the electrodes is by wearing an elastic headband across the forehead, with the electrodes placed inside. It should be snug enough to keep them from slipping out. For added convenience, the electrodes can also be sewn into the headband to avoid repositioning them manually each time.
 
==== Ski goggles or sleep mask ====
 
This method involves more DIY effort, but it allows electrode placement around the eyes to collect more detailed REM data. However, keeping the sleep mask or ski goggles securely in place during sleep can be challenging, especially for side sleepers, as the electrodes may shift. This should be taken into account.
 
=== Skin preparation ===
 
With the 4 AE + 1 PE setup, little to no skin preparation is typically required, and the electrodes can usually be placed directly on the skin. However, some users may still find it helpful to clean the electrode sites beforehand. In contrast, for the 5 PE setup, proper skin preparation is essential.
 
To prepare the skin, first remove any excess hair from the electrode sites to ensure optimal contact. Clean the area with mild soap and water or a non-alcoholic wipe, as alcohol-based wipes can dry out the skin and reduce electrical conductivity.<ref name="skinprep" />
 
== Software setup ==
 
The process of setting up the software will vary significantly depending on your operating system (assuming installation on a laptop). However, the general steps are similar and will be outlined in this guide.
 
=== Windows ===
 
=== Linux ===
 
==== OpenViBE installation ====
 
Start by downloading the stable source code (version 3.6.0 was used in this guide).<ref name="openvibedownload" /> Then, follow the [https://openvibe.inria.fr/build-instructions/ build instructions].
 
After running <code>conda env update -f conda/env_linux.yaml</code>, '''be sure to run''' <code>conda activate openvibe</code>. This step is required to build the program within the OpenViBE environment, even though it's not explicitly mentioned in the official instructions.
 
==== Configuring Acquisition Server ====
 
Run <code>sude dmesg -w</code> and plug in your device. This will help you identify the correct port (e.g. ttyUSB0).
 
Navigate to the <code>build/</code> directory of OpenViBE, then run <code>./bin/openvibe-acquisition-server</code>. Click Driver Properties, set Number of channels to 2, and set Device to the port you identified earlier (e.g. ttyUSB0).
 
You may also want to add your user to the <code>uucp</code> group and reboot to ensure proper permissions (<code>sudo usermod -a -G uucp <username></code>).
 
To reduce signal noise, open the Acquisition Server's Preferences menu. Set Drift Correction to Disable and click Apply. Then, go back to Driver Properties and adjust the sampling frequency to minimize drift.
 
To do this:
* Plug in your device.
* Click Connect and Play in the Acquisition Server.
* Observe the drift value over time.
* Try different sampling frequencies (e.g., 256, 257, etc.) to find the setting that causes the drift to change as slowly as possible.
 
==== Configuring Designer ====
 
[[File:Designer.webp|thumb|Design workspace connection]]
 
Disconnect and close the Acquisition Server window. Then run <code>./bin/openvibe-designer</code>. Go to File -> New. In the search bar, type "acquisition" and drag ''Acquisition Client'' to the design workspace (to the left side of the interface). Repeat this process for ''Signal Display'' and ''CSV File Writer (Deprecated)''. Note: the deprecated CSV File Writer is required for compatibility with other software.
 
Next, connect all the elements in the design workspace as shown in the image.
 
Configure the CSV File Writer by double clicking it. Use the folder button to choose where you want to save your sleep recordings. Set the filename to <code>record-[$core{date}-$core{time}].csv</code>. This will automatically include the date and time in the file name. Click Apply. Press Save, and select the name (like design_scenario). This will save the design, and it will automatically load the next time you open the Designer. Finally, close all OpenViBE windows.
 
==== Running OpenViBE ====
 
To record your sleep, enter the <code>build/</code> directory of OpenViBE and run <code>./bin/openvibe-acquisition-server</code>. In the Acquisition server window, click Connect, then Play. Next, use another terminal tab to run <code>./bin/openvibe-designer</code>. In the Designer window, click the Play button to start recording. You should see the signal being captured in real time.
 
Do not unplug the device while recording, as this may cause the program to hang.
 
When you're finished:
# Press Stop in the Designer window.
# Then press Stop and Disconnect in the Acquisition Server window.
 
After that, you can navigate to the folder you selected earlier to save your recordings. You’ll find the raw sleep data files there.
 
==== Installing SleepEEGTools ====
 
Run <code>git clone https://github.com/polyphasicdev/SleepEEGTools</code> to clone the SleepEEGTools repository. Then, navigate into the project directory by running <code>cd SleepEEGTools</code>. To set up a virtual environment, run <code>python -m venv venv</code> and <code>source venv/bin/activate</code>. Next, try running the program: <code>python open.py</code>. If it fails due to missing dependencies, install them using <code>pip install <package name></code> (replace <code><package name></code> with the actual missing package listed in the error). Once everything is installed, the program should run correctly. When you're finished, deactivate the environment by running <code>deactivate</code>.
 
==== Running SleepEEGTools to mark sleep ====
 
Navigate to the SleepEEGTools project directory. If you set up a virtual environment in the previous step, activate it by running <code>source venv/bin/activate</code>. Then, run <code>python open.py</code>. This will open a file browser window. Select a recording file to open the sleep marking interface.
 
Alternatively, you can run <code>python open.py openvibe <file name></code> to open the recording directly and skip the file selection dialog.
 
From there, you can manually analyze and mark the sleep stages. Detailed instructions for this process are provided in the [[Olimex_OpenEEG#Sleep_Stage_Identification|Sleep stage identification]] section.
 
=== MacOS ===
 
This setup has not been tested on macOS yet, so contributions are welcome.
 
== Sleep stage identification ==
 
[[File:Sample Olimex data.jpg|thumb|Sleep stages in Olimex]]
 
Follow the instructions in the section [https://polysleep.org/wiki/Olimex_OpenEEG#Running_SleepEEGTools_to_mark_sleep|Running SleepEEGTools to mark sleep] to launch the SleepEEGTools program and select a recording. This will open the marking window. From there, you can choose a sleep stage and click on different parts of the spectrogram to mark the stages manually. Once you're finished, click Save and Quit to store your annotations.
 
If you're unsure about how to mark sleep stages or have atypical recordings, feel free to join our [https://discord.com/invite/2kzXcg7Juf Discord server] and ask for help from experienced community members.
 
=== Sleep stages ===
 
As shown in the image, each sleep stage has a distinct pattern. With some practice, you'll be able to recognize these patterns and mark them accurately.
 
==== Wake/NREM1 ====
 
These two stages can appear quite similar. The wake state typically looks blank or appears messy with high-frequency activity. NREM1 is also mostly blank, but usually with less high-frequency noise.
 
==== NREM2/NREM3 ====
 
NREM2 ([https://en.wikipedia.org/wiki/Non-rapid_eye_movement_sleep#Stages light sleep]) and NREM3 ([https://en.wikipedia.org/wiki/Slow-wave_sleep slow-wave sleep]) are part of a continuum and are primarily differentiated by the amount of delta wave activity. In NREM2, delta waves are present but not dominant. NREM3 is characterized by a significant amount of delta activity, often exceeding 20% of the total brainwave activity.<ref name="nrem" />
 
Both NREM2 and NREM3 (SWS) show a bold frequency band between 10 and 15 Hz. This band is typically thicker in NREM2 and thinner in SWS. Additionally, SWS tends to show more intense low-frequency activity in the 0–10 Hz range.
 
==== REM ====
 
REM sleep is usually easy to identify in the spectrogram, especially within the core of a sleep cycle. REM episodes occur between NREM stages and are marked by a distinctive bow-shaped frequency band around 20–25 Hz near the end of the cycle.
 
=== Identification in naps ===
 
[[File:Rem beta.webp|thumb|REM nap, beta waves (20–28 Hz)]]
 
[[File:Wake.webp|thumb|Awake state, no well-defined beta waves]]
 
[[File:Nrem1 2.webp|thumb|NREM1 and NREM2 during a nap]]
 
Distinguishing sleep stages during a nap can be more challenging than during a full night of core sleep, but it is still possible. REM sleep is marked by beta activity, specifically in the 20–28 Hz range<ref name="remnrem" />, which helps identify REM naps.
 
The wake state appears similar but lacks clearly defined beta waves. It typically looks disorganized, featuring high frequencies without a distinct structure.
 
NREM naps usually begin with NREM1, which appears mostly blank, similar to wakefulness but with a clearer and more subdued pattern, as shown in the third image. The nap then progresses into NREM2. Both NREM2 and NREM3 are characterized by prominent sigma waves (12–16 Hz)<ref name="remnrem" />. Delta waves (0.3–3 Hz) are also present, being strong in NREM3 and weaker in NREM2.
 
REM naps are most common in the morning hours (between 3–11 a.m.), while NREM naps tend to occur in the afternoon.


== References == <!--T:3-->  
== References == <!--T:3-->  
Line 19: Line 200:
{{reflist|refs=
{{reflist|refs=
<ref name="eegsmt">{{cite web |url=https://www.olimex.com/Products/EEG/OpenEEG/EEG-SMT/open-source-hardware |title=Low Cost Open Source EEG Device Completely Assembled USB Interface |website=Olimex |access-date=2025-06-21}}</ref>
<ref name="eegsmt">{{cite web |url=https://www.olimex.com/Products/EEG/OpenEEG/EEG-SMT/open-source-hardware |title=Low Cost Open Source EEG Device Completely Assembled USB Interface |website=Olimex |access-date=2025-06-21}}</ref>
<ref name="eegpe">{{cite web |url=https://www.olimex.com/Products/EEG/Electrodes/EEG-PE/open-source-hardware |title= Low cost open source EEG device passive electrodes with 1m shielded cable to be used for the DRL connection |website=Olimex |access-date=2025-06-21}}</ref>
<ref name="eegae">{{cite web |url=https://www.olimex.com/Products/EEG/Electrodes/EEG-AE/open-source-hardware |title= Low cost open source EEG device active electrodes with 1m shielded cable |website=Olimex |access-date=2025-06-21}}</ref>
<ref name="eegcable">{{cite web |url=https://www.olimex.com/Products/Components/Cables/USB/CABLE-USB-A-B-1.8M/ |title= USB A to B cable 1.8m |website=Olimex |access-date=2025-06-21}}</ref>
<ref name="openeeg">{{cite web |url=https://www.olimex.com/Products/EEG/ |title= OpenEEG |website=Olimex |access-date=2025-06-21}}</ref>
<ref name="bakerdh">{{cite web |url=https://bakerdh.wordpress.com/2013/01/31/a-first-look-at-the-olimex-eeg-smt/ |title= A first look at the Olimex EEG-SMT |website=Daniel's Visionarium |access-date=2025-06-21}}</ref>
<ref name="sleepi">{{cite web |url=https://github.com/PolyphasicDevTeam/sleepi |title= SleePi |website=Github |access-date=2025-06-21}}</ref>
<ref name="openvibe">{{cite web |url=https://openvibe.inria.fr/ |title=Software for Brain Computer Interfaces and Real Time Neurosciences |website=OpenViBE |access-date=2025-06-21}}</ref>
<ref name="skinprep">{{cite web |url=https://thephysiologist.org/study-materials/electrodes-and-interference/ |title=Electrodes and Skin Prep |website=The Student Physiologist |access-date=2025-06-21}}</ref>
<ref name="openvibedownload">{{cite web |url=https://openvibe.inria.fr/downloads/ |title=OpenViBE Downloads |website=OpenViBE |access-date=2025-06-21}}</ref>
<ref name="nrem">{{cite web |url=https://neupsykey.com/introduction-to-sleep-and-polysomnography-3/ |title=
Introduction to Sleep and Polysomnography |website=Neupsy Key |access-date=2025-06-22}}</ref>
<ref name="remnrem">{{cite journal |vauthors=Uchida S, Maloney T, Feinberg I |date=1994 |title=Sigma (12–16 Hz) and beta (20–28 Hz) EEG discriminate NREM and REM sleep |journal=Brain Research |volume=659 |issue=1-2 |pages=243-248}}</ref>
}}
}}