-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8444785
commit 07ad050
Showing
10 changed files
with
284 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Recording | ||
========= | ||
""" | ||
|
||
# Author: Nicolas Legrand <[email protected]> | ||
# Licence: GPL v3 | ||
|
||
# It can easily interface with `PsychoPy <https://www.psychopy.org/>`_ to | ||
# record PPG signal during psychological experiments, and to synchronize | ||
# stimulus deliver to e.g., systole or diastole. | ||
|
||
# For example, you can record and plot data in less than 6 lines of code: | ||
|
||
|
||
#%% | ||
# Event related cardiac deceleration | ||
# ---------------------------------- | ||
import serial | ||
from systole.recording import Oximeter | ||
ser = serial.Serial('COM4') # Add your USB port here | ||
|
||
# Open serial port, initialize and plot recording for Oximeter | ||
oxi = Oximeter(serial=ser).setup().read(duration=10) | ||
|
||
|
||
Interfacing with PsychoPy | ||
------------------------- | ||
|
||
The ``Oximeter`` class can be used together with a stimulus presentation software to record cardiac activity during psychological experiments. | ||
|
||
* The ``read()`` method | ||
|
||
will record for a predefined amount of time (specified by the ``duration`` parameter, in seconds). This 'serial mode' is the easiest and most robust method, but it does not allow the execution of other instructions in the meantime. | ||
|
||
.. code-block:: python | ||
|
||
# Code 1 {} | ||
oximeter.read(duration=10) | ||
# Code 2 {} | ||
|
||
* The ``readInWaiting()`` method | ||
|
||
will only read the bytes temporally stored in the USB buffer. For the Nonin device, this represents up to 10 seconds of recording (this procedure should be executed at least one time every 10 seconds for a continuous recording). When inserted into a while loop, it can record PPG signal in parallel with other commands. | ||
|
||
.. code-block:: python | ||
|
||
import time | ||
tstart = time.time() | ||
while time.time() - tstart < 10: | ||
oximeter.readInWaiting() | ||
# Insert code here {...} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
""" | ||
Recording PPG signal | ||
==================== | ||
""" | ||
|
||
# Author: Nicolas Legrand <[email protected]> | ||
# Licence: GPL v3 | ||
|
||
# The py:class:systole.recording.Oximeter class can be used to read incoming | ||
# PPG signal from `Nonin 3012LP Xpod USB pulse oximeter | ||
# <https://www.nonin.com/products/xpod/>`_ together with the `Nonin 8000SM | ||
# 'soft-clip' fingertip sensors <https://www.nonin.com/products/8000s/>`_. | ||
# This function can easily be integrated with other stimulus presentation | ||
# software lie `PsychoPy <https://www.psychopy.org/>`_ to record cardiac | ||
# activity during psychological experiments, or to synchronize stimulus | ||
# delivery with cardiac phases (e.g. systole or diastole). | ||
|
||
|
||
#%% | ||
# Reading | ||
# ------- | ||
# Recording and plotting your first time-series will only require 5 lines | ||
# of code: | ||
|
||
import serial | ||
from systole.recording import Oximeter | ||
ser = serial.Serial('COM4') # Add your USB port here | ||
|
||
# Open serial port, initialize and plot recording for Oximeter | ||
oxi = Oximeter(serial=ser).setup().read(duration=10) | ||
|
||
# The signal can be directly plotted using built-in functions. | ||
oxi.plot_oximeter() | ||
|
||
############################################################################## | ||
# .. figure:: https://github.com/embodied-computation-group/systole/raw/master/Images/recording.png | ||
# :align: center | ||
############################################################################## | ||
|
||
#%% | ||
# Interfacing with PsychoPy | ||
# ------------------------- | ||
|
||
# * The ``read()`` method will record for a predefined amount of time | ||
# (specified by the ``duration`` parameter, in seconds). This 'serial mode' | ||
# is the easiest and most robust method, but it does not allow the execution | ||
# of other instructions in the meantime. | ||
|
||
# Code 1 {} | ||
oximeter.read(duration=10) | ||
# Code 2 {} | ||
|
||
# * The ``readInWaiting()`` method will only read the bytes temporally stored | ||
# in the USB buffer. For the Nonin device, this represents up to 10 seconds of | ||
# recording (this procedure should be executed at least one time every 10 | ||
# seconds for a continuous recording). When inserted into a while loop, it can | ||
# record PPG signal in parallel with other commands. | ||
|
||
import time | ||
tstart = time.time() | ||
while time.time() - tstart < 10: | ||
oximeter.readInWaiting() | ||
# Insert code here {...} | ||
|
||
#%% | ||
# Online detection | ||
# ---------------- | ||
# Online heart beat detection, for cardiac-stimulus synchrony | ||
|
||
import serial | ||
import time | ||
from systole.recording import Oximeter | ||
|
||
# Open serial port | ||
ser = serial.Serial('COM4') # Change this value according to your setup | ||
|
||
# Create an Oxymeter instance and initialize recording | ||
oxi = Oximeter(serial=ser, sfreq=75, add_channels=4).setup() | ||
|
||
# Online peak detection for 10 seconds | ||
tstart = time.time() | ||
while time.time() - tstart < 10: | ||
while oxi.serial.inWaiting() >= 5: | ||
paquet = list(oxi.serial.read(5)) | ||
oxi.add_paquet(paquet[2]) # Add new data point | ||
if oxi.peaks[-1] == 1: | ||
print('Heartbeat detected') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.