COsleep: Closed- and Open-loop Sleep Stimulations with Auditory Stimuli
Following the tutorial on how to get a sleep recording/lab for under $1000 using OpenBCI here a continuation on….
Open Hard- and Software for in-sleep Closed– and Open-loop Targeted and Untargeted Memory Reactivation/Disruption with full-PSG recording.
Stay safe, use hardware and software with caution and on your own risk. The (negative) consequences of auditory stimulation protocols during sleep are sufficiently explored yet.
Only works with OpenBCI Cyton board (from firmware starting at version 2.x.x) and Linux.
So you need a Linux distribution for this to work, I would recommend Ubuntu 18.04 LTS because I tested it, it is used by many, it is easy entry …. and you do not have to be a PC nerd to install it properly and safely. Ubuntu is quick to install, see a tutorial to install Ubuntu alongside Windows … or search the web.
If you are lazy and do not want to install anything, or just try COsleep, install the USB image on an USB stick and boot from it (UEFI and BIOS). A Debian Live 9.8.0 is on there and pre-configured where you can run COsleep from the folder structure found in the root folder /cosleep. Using the USB stick bootable version will (likely) not alter your PC in any way and it works on most common notebooks/laptops/PCs out of the box.
A poster with pictures and infographics, lists’n’stuff shows an example to pack an OpenBCI in a cheap and safe Box. I call it the “Somnofredics Plus PSG”. Its a fun project from a serious collaboration work.
For hardware setup I recommend to read the previous tutorial here.
FYI: The recordings I gained with this setup were comparable proprietary devices (2 top of the market products from two companies, i.e. parallel recordings on the same electrodes). I am confident in the quality of OpenBCI recordings (the ADS1299 is really worth its high ~$50 price tag over similar cheaper AD-converters). Also confirming Rashid et al. (Nov. 2018)
A tutorial on the software will maybe follow later.
- EOG (two bipolar electrodes around the eyes)
- EMG (two bipolar electrodes on the chin, musculus mentalis)
- two EEG Deviations at C3 and C4 according to the international 10-20 Electrode placement system (that is C3:A2, C4:A1).
- (optional) further electrodes, mainly in the 16 channel setup and if you have more electrode connectors and electrodes left.
The setup records C3, C3, A1 (left mastoid) and A2 (right mastoid) signals separatly referenced to a placed reference electrode at Cz and uses as a bias Bias/Ground electrode at Fpz (placed at the center of the forehead). one of those electrodes can be replaced to an occipital (e.g. O1 or O2) to be more compliant with AASM. Also there is room for additional channels also in the 8 channel setup.
8-channel setup: Main board (no daisy)
|Channel||# Electrodes||Pins to use||Electrode label (cable color)||Type/Function||Location||Comment|
|SRB||1||N(bottom) alias SRB2||Ref (white)||Reference||vertex (~center of head viewed from top) (Cz)|
|BIAS(2)||1||(2 is the bottom pin)||Ground||Ground/Bias||forehead (Fpz)|
|EOG||1 cm left of left eye cantus and a little down,
1 cm above right eye center
|N3P*||1||N(bottom)||A1||EEG||A1 (bony part behind left ear)|
|N4P*||1||N(bottom)||A2||EEG||A2 (bony part behind right ear)|
|N5P*||1||N(bottom)||C3||EEG||C3 (6-8 cm left of vertex towards left ear)|
|N6P*||1||N(bottom)||C4||EEG||C4 (6-8 cm right of vertex towards right ear)|
|N7P||[not plugged]||– (unused)||e.g. Fz or bipolar ECG, Trigger signal (red/positive in top P pin)|
|N8P||[not plugged]||– (unused)||e.g. Pz or bipolar ECG, feedback channel from stimulation|
16 channel setup: Main board + Daisy module.
- Connect the device’s SRB2 to daisy’s SRB2 and then connect with Reference using a Y cable/bridge (typically provided in the OpenBCI package with the daisy module, but can be build by yourself as well).
- Choose BIAS pin (for Ground electorde) of either daisy module or device, taking one of any of the two is enough, they do not need to be connected.
- Additional 10 electrodes (2×10 connectors) are needed.
- RECOMMEND: You can remove the black and white cable from this connector resulting in 8 additional EEG channels. This avoids confusion them with the Reference (white, connected with a Y cable/bridge) and Ground (black, BIAS) of the first connector the of the setup below.
- RECOMMEND: You can also use these two extra cables for an ECG (e.g. in the free NP8 channel).
|Device||Channel||# Electrodes||Pins to use||Electrode label (cable color)||Type/Function||Location||Comment|
|main||SRB||1||N(bottom) alias SRB2||Ref (white)||Reference||vertex (~center of head viewed from top) (Cz)||connected/linked to daisy module SRB Bottom pin with “Y-bridge”|
|main||BIAS(2)||1||(2 is the bottom pin)||Ground||Ground/Bias||forehead (Fpz)|
|EOG||1 cm left of left eye cantus and a little down,
1 cm above right eye center
|main||N3P*||1||N(bottom)||A1||EEG||A1 (bony part behind left ear)|
|main||N4P*||1||N(bottom)||A2||EEG||A2 (bony part behind right ear)|
|main||N5P*||1||N(bottom)||C3||EEG||C3 (6-8 cm left of vertex towards left ear)|
|main||N6P*||1||N(bottom)||C4||EEG||C4 (6-8 cm right of vertex towards right ear)|
|Negative pole, Positive pole||Trigger||On/OFF Trigger 1000 µV/0µV potential, see below.|
|main||N8P||1||N(bottom)||ECG, reserved, e.g. noise||ECG,Trigger2(EEG) …||another bipolar channel.|
|daisy||SRB||1||N(bottom) alias SRB2||Ref (white)||Reference||vertex (~center of head viewed from top) (Cz)||connected/linked to main module SRB Bottom pin with “Y-bridge”|
|daisy||N1P*||1||N(bottom)||EEG1/F3||EEG||F3 (6-8 cm to wards nose from vertex, then perpendicular 6-8 cm towards left side, and 6-8 cm away from C3)|
|daisy||N2P*||1||N(bottom)||EEG2/Fz||EEG||Fz (6-8 cm to wards nose from vertex)|
|daisy||N3P*||1||N(bottom)||EEG3/F4||EEG||F4 (6-8 cm to wards face from vertex, then perpendicular 6-8 cm towards the right, and about 6-8 cm away from C4)|
|daisy||N4P*||1||N(bottom)||EEG4/P3||EEG||P3 (6-8 cm to wards back from vertex, then perpendicular 6-8 cm towards left side, and 6-8 cm away from C3)|
|daisy||N5P*||1||N(bottom)||EEG5/Pz||EEG||Pz (6-8 cm to wards the back from vertex)|
|daisy||N6P*||1||N(bottom)||EEG6/P4||EEG||P4 (6-8 cm to wards back from vertex, then perpendicular 6-8 cm towards right side, and 6-8 cm away from C4)|
|daisy||N7P*||1||N(bottom)||EEG7/O1||EEG||O1 (12-16 cm to wards back from vertex, then perpendicular 1.5-2 cm towards left side, and 3-4 cm away from O2)|
|daisy||N8P*||1||N(bottom)||EEG8/O2||EEG||O2 (12-16 cm to wards back from vertex, then perpendicular 1.5-2 cm towards right side, and 3-4 cm away from O1)|
(*) Output of these channels have inverted polarity since referenced to the SRB2 pin
Overview of the setup and suggested electrode positions on the head
- Sound buffer. If you do a Stimulation protocol, make sure to not choose a too short sound buffer. The default is 4096 audio samples at 44.1 kHz corresponding to about 93 ms delay of the sound. Though this delay is considered for the playing of the sounds. For example, at default setting, if a delay of 0.2 s after threshold determination is chosen for closed-loop stimulation, this 0.2 seconds corresponds to 0.107 s + 0.93 s = 0.2 s, where at 0.107 s the conditions for playing the sound are checked The accuracy of timing is the duration of a sample of the signal. The sound buffer can typically reduced to 1024 audio samples (about 23 ms delay), but at lower than this distortions of the sound or cracking noise can be the result. In the log files of the terminal output there are typically “alsa … underun…” messages, that indicate hard- or software could not keep up with accurate presentation of stimuli. With good hardware 256 a delay samples are realistic, but please check if it works. If accuracy of sound is not your issue, but delay is, choose lower delays.
- Filtering for the stimulation algorithm (equivalent as the signals viewed in the GUI). The filter is by default a high-pass filter of 0.16 Hz and a low-pass filter of 30.0 Hz for EEG and EOG, and a high-pass filter of 10 Hz for EMG. The filter is a one-pass Butterworth filter that can distort the signals and shift samples by on average half of a sample length multiplied by the filter order it. The shift is depending on the frequency component of the signal. The signal delay is mainly dependent on the low-frequency high-pass filter:
- At 125 Hz the filter order is 1 sample. Thus signal is approximately delayed by 0.5 samples (= 0.5*8 ms = 4 ms)
- At 250 Hz the filter order is increased to 2 samples. Thus signal is approximately delayed by 1 sample (= 4 ms)
- Performance improvements to run the frontend GUI and the backend algorithm. The backend algorithm typicall runs very smooth an a modern PC/laptop/notebook with no need for limitations. The frontend can be more of a slow thing and depends on your hardware much more. Here are some things you can do to improve performance:
- Choose better PC hardware: more CPU power is better, for GUI processing also a good GPU that is supported by your linux distribution or has a good driver installed can speed up things. Also a good hard drive like a modern SSD goes a long way and avoids bottlenecks for writing the data on the hard drive
- Configure the startup of COsleep, make sure you choose “Details” instead of “Default”option:
- Choose the non-default “No anti-aliasing” option in the opening dialog, that makes the signal in the GUI look worse but sufficient. This mainly makes the GUI frontend faster, but can save some CPU power for the backend as well.
- Choose the non-default “OpenGL”in the opening dialog for view processing in the GUI, that makes use of your hardware better. This mainly makes the GUI frontend faster, but can save some CPU power for the backend as well.
- When using a 8 channel recording then use the non-default “125 Hz (odd)” instead of the default “250 Hz (all)”, that uses only 125 Hz even though the 250 are available. On the SD card there is always 250 Hz sampling rate stored. 125 Hz is typically enough for standard EEG, EOG and ECG (and sufficient for the vast majority of sleep analyses and beyond), also EMG signals are is typically good enough displayed. You need a lot of good ERP signals grouped together to really start talking about more than 40 Hz signals and their shape. This makes the GUI frontend and the backend faster.
- Do not use the Extended Signal view for a second window of signals and choose “Only Recording View (fast refresh rate)” but if you must you can make a Montage with only the most necessary channels to view there extra to the Main signal view window, just place a “no” without the quotes in the montage .tsv file in the column called GUI_signalviewer_order. This makes the Main GUI frontend faster, and the backend a little bit too.
- Disable the default “Highlight spindles” optioin to “OFF”, who needs aid in finding spindles anyway. This makes the GUI frontend faster.
- Do not write in EDF or BDF. Though this saves very little backend performance, it can be critical on slow hard drives.
- Consider what you really need for your purpose, are 8 channels with 125 Hz recording enough, and you do not need so much functionality to improve your outcomes in a relevant way…then go for that simple way.
- (on a standard 2012 subnotebook with i5 dual processor, Lenovo Thinkpad X220, stable refresh rates of 0.3 s and below could easily be achieved in any setting or startup option.)