Daag je geheugen uit! Speel de nieuwe N-Back-game in de Emotiv App

  • Daag je geheugen uit! Speel de nieuwe N-Back-game in de Emotiv App

  • Daag je geheugen uit! Speel de nieuwe N-Back-game in de Emotiv App

Lab Streaming Layer (LSL) voor het synchroniseren van meerdere gegevensstromen

Roshini Randeniya

-

Delen:

door Roshini Randeniya en Lucas Kleine

Werking:
Zodra dit script in de opdrachtregel wordt uitgevoerd, start het onmiddellijk een LSL-stream. Wanneer op de 'Enter'-toets wordt gedrukt, verstuurt het een trigger en speelt het een audiobestand af."""

import sounddevice as sd
import soundfile as sf
from pylsl import StreamInfo, StreamOutlet

def wait_for_keypress():
print("Druk op ENTER om audioweergave te starten en een LSL-marker te verzenden.")

while True: # This loop waits for a keyboard input
    input_str = input()  # Wait for input from the terminal
    if input_str == "":  # If the enter key is pressed, proceed
        break

def AudioMarker(audio_file, outlet): # functie voor het afspelen van audio en het verzenden van een marker
data, fs = sf.read(audio_file) # Laad het audiobestand

print("Playing audio and sending LSL marker...")
marker_val = [1]
outlet.push_sample(marker_val) # Send marker indicating the start of audio playback
sd.play(data, fs) # play the audio
sd.wait()  # Wait until audio is done playing
print("Audio playback finished.")

if name == "main": # HOOFDLUS
# LSL-stream instellen voor markers
stream_name = 'AudioMarkers'
stream_type = 'Markers'
n_chans = 1
sr = 0 # Stel de samplefrequentie in op 0 omdat markers onregelmatig zijn
chan_format = 'int32'
marker_id = 'uniqueMarkerID12345'

info = StreamInfo(stream_name, stream_type, n_chans, sr, chan_format, marker_id)
outlet = StreamOutlet(info) # create LSL outlet

# Keep the script running and wait for ENTER key to play audio and send marker
while True:
    wait_for_keypress()
    audio_filepath = "/path/to/your/audio_file.wav"  # replace with correct path to your audio file
    AudioMarker(audio_filepath, outlet)
    # After playing audio and sending a marker, the script goes back to waiting for the next keypress</code></pre><p><em><strong>**By running this file (even before playing the audio), you've initiated an LSL stream through an outlet</strong></em><strong>. Now we'll view that stream in LabRecorder</strong></p><p><strong>STEP 5 - Use LabRecorder to view and save all LSL streams</strong></p><ol><li data-preset-tag="p"><p>Open LabRecorder</p></li><li data-preset-tag="p"><p>Press <em><strong>Update</strong></em>. The available LSL streams should be visible in the stream list<br> • You should be able to see streams from both EmotivPROs (usually called "EmotivDataStream") and the marker stream (called "AudioMarkers")</p></li><li data-preset-tag="p"><p>Click <em><strong>Browse</strong></em> to select a location to store data (and set other parameters)</p></li><li data-preset-tag="p"><p>Select all streams and press <em><strong>Record</strong></em> to start recording</p></li><li data-preset-tag="p"><p>Click Stop when you want to end the recording</p></li></ol><p><br></p><img alt="" src="https://framerusercontent.com/images/HFGuJF9ErVu2Jxrgtqt11tl0No.jpg"><h2><strong>Working with the data</strong></h2><p><strong>LabRecorder outputs an XDF file (Extensible Data Format) that contains data from all the streams. XDF files are structured into, </strong><em><strong>streams</strong></em><strong>, each with a different </strong><em><strong>header</strong></em><strong> that describes what it contains (device name, data type, sampling rate, channels, and more). You can use the below codeblock to open your XDF file and display some basic information.</strong></p><pre data-language="JSX"><code>

Dit voorbeeldscript demonstreert een paar basisfuncties om EEG-gegevens die zijn verzameld met EmotivPRO-software te importeren en te annoteren. Het gebruikt MNE om een XDF-bestand te laden, enkele basis-metadata af te drukken, een info-object te maken en het vermogensspectrum te plotten."""

import pyxdf
import mne
import matplotlib.pyplot as plt
import numpy as np

Pad naar je XDF-bestand

data_path = '/path/to/your/xdf_file.xdf'

Laad het XDF-bestand

streams, fileheader = pyxdf.load_xdf(data_path)
print("XDF-bestandsheader:", fileheader)
print("Aantal gevonden streams:", len(streams))

for i, stream in enumerate(streams):
print("\nStream", i + 1)
print("Streamnaam:", stream['info']['name'][0])
print("Streamtype:", stream['info']['type'][0])
print("Aantal kanalen:", stream['info']['channel_count'][0])
sfreq = float(stream['info']['nominal_srate'][0])
print("Samplefrequentie:", sfreq)
print("Aantal samples:", len(stream['time_series']))
print("Print de eerste 5 datapunten:", stream['time_series'][:5])

channel_names = [chan['label'][0] for chan in stream['info']['desc'][0]['channels'][0]['channel']]
print("Channel Names:", channel_names)
channel_types = 'eeg'
Maak MNE-info-object

info = mne.create_info(channel_names, sfreq, channel_types)
data = np.array(stream['time_series']).T # Gegevens moeten worden getransponeerd: kanalen x samples
raw = mne.io.RawArray(data, info)
raw.plot_psd(fmax=50) # plot een eenvoudig spectrogram (vermogensspectrale dichtheid)Aanvullende bronnenDownload deze tutorial als een Jupyter-notebook van EMOTIV GitHubBekijk de online LSL-documentatie, inclusief het officiële README-bestand op GitHubJe hebt een of meer ondersteunde gegevensverzamelingsapparaten nodig om gegevens te verzamelenAlle brainware-apparaten van EMOTIV maken verbinding met EmotivPRO-software, die ingebouwde LSL-mogelijkheden heeft voor het verzenden en ontvangen van datastreamsAanvullende bronnen:Code om LSL uit te voeren met apparaten van Emotiv, met voorbeeldscriptsNuttige LSL-demo op YouTubeSCCN LSL GitHub-repository voor alle bijbehorende bibliothekenGitHub-repository voor een verzameling submodules en appsHyPyP-analysepijplijn voor hyperscanningstudies

door Roshini Randeniya en Lucas Kleine

Werking:
Zodra dit script in de opdrachtregel wordt uitgevoerd, start het onmiddellijk een LSL-stream. Wanneer op de 'Enter'-toets wordt gedrukt, verstuurt het een trigger en speelt het een audiobestand af."""

import sounddevice as sd
import soundfile as sf
from pylsl import StreamInfo, StreamOutlet

def wait_for_keypress():
print("Druk op ENTER om audioweergave te starten en een LSL-marker te verzenden.")

while True: # This loop waits for a keyboard input
    input_str = input()  # Wait for input from the terminal
    if input_str == "":  # If the enter key is pressed, proceed
        break

def AudioMarker(audio_file, outlet): # functie voor het afspelen van audio en het verzenden van een marker
data, fs = sf.read(audio_file) # Laad het audiobestand

print("Playing audio and sending LSL marker...")
marker_val = [1]
outlet.push_sample(marker_val) # Send marker indicating the start of audio playback
sd.play(data, fs) # play the audio
sd.wait()  # Wait until audio is done playing
print("Audio playback finished.")

if name == "main": # HOOFDLUS
# LSL-stream instellen voor markers
stream_name = 'AudioMarkers'
stream_type = 'Markers'
n_chans = 1
sr = 0 # Stel de samplefrequentie in op 0 omdat markers onregelmatig zijn
chan_format = 'int32'
marker_id = 'uniqueMarkerID12345'

info = StreamInfo(stream_name, stream_type, n_chans, sr, chan_format, marker_id)
outlet = StreamOutlet(info) # create LSL outlet

# Keep the script running and wait for ENTER key to play audio and send marker
while True:
    wait_for_keypress()
    audio_filepath = "/path/to/your/audio_file.wav"  # replace with correct path to your audio file
    AudioMarker(audio_filepath, outlet)
    # After playing audio and sending a marker, the script goes back to waiting for the next keypress</code></pre><p><em><strong>**By running this file (even before playing the audio), you've initiated an LSL stream through an outlet</strong></em><strong>. Now we'll view that stream in LabRecorder</strong></p><p><strong>STEP 5 - Use LabRecorder to view and save all LSL streams</strong></p><ol><li data-preset-tag="p"><p>Open LabRecorder</p></li><li data-preset-tag="p"><p>Press <em><strong>Update</strong></em>. The available LSL streams should be visible in the stream list<br> • You should be able to see streams from both EmotivPROs (usually called "EmotivDataStream") and the marker stream (called "AudioMarkers")</p></li><li data-preset-tag="p"><p>Click <em><strong>Browse</strong></em> to select a location to store data (and set other parameters)</p></li><li data-preset-tag="p"><p>Select all streams and press <em><strong>Record</strong></em> to start recording</p></li><li data-preset-tag="p"><p>Click Stop when you want to end the recording</p></li></ol><p><br></p><img alt="" src="https://framerusercontent.com/images/HFGuJF9ErVu2Jxrgtqt11tl0No.jpg"><h2><strong>Working with the data</strong></h2><p><strong>LabRecorder outputs an XDF file (Extensible Data Format) that contains data from all the streams. XDF files are structured into, </strong><em><strong>streams</strong></em><strong>, each with a different </strong><em><strong>header</strong></em><strong> that describes what it contains (device name, data type, sampling rate, channels, and more). You can use the below codeblock to open your XDF file and display some basic information.</strong></p><pre data-language="JSX"><code>

Dit voorbeeldscript demonstreert een paar basisfuncties om EEG-gegevens die zijn verzameld met EmotivPRO-software te importeren en te annoteren. Het gebruikt MNE om een XDF-bestand te laden, enkele basis-metadata af te drukken, een info-object te maken en het vermogensspectrum te plotten."""

import pyxdf
import mne
import matplotlib.pyplot as plt
import numpy as np

Pad naar je XDF-bestand

data_path = '/path/to/your/xdf_file.xdf'

Laad het XDF-bestand

streams, fileheader = pyxdf.load_xdf(data_path)
print("XDF-bestandsheader:", fileheader)
print("Aantal gevonden streams:", len(streams))

for i, stream in enumerate(streams):
print("\nStream", i + 1)
print("Streamnaam:", stream['info']['name'][0])
print("Streamtype:", stream['info']['type'][0])
print("Aantal kanalen:", stream['info']['channel_count'][0])
sfreq = float(stream['info']['nominal_srate'][0])
print("Samplefrequentie:", sfreq)
print("Aantal samples:", len(stream['time_series']))
print("Print de eerste 5 datapunten:", stream['time_series'][:5])

channel_names = [chan['label'][0] for chan in stream['info']['desc'][0]['channels'][0]['channel']]
print("Channel Names:", channel_names)
channel_types = 'eeg'
Maak MNE-info-object

info = mne.create_info(channel_names, sfreq, channel_types)
data = np.array(stream['time_series']).T # Gegevens moeten worden getransponeerd: kanalen x samples
raw = mne.io.RawArray(data, info)
raw.plot_psd(fmax=50) # plot een eenvoudig spectrogram (vermogensspectrale dichtheid)Aanvullende bronnenDownload deze tutorial als een Jupyter-notebook van EMOTIV GitHubBekijk de online LSL-documentatie, inclusief het officiële README-bestand op GitHubJe hebt een of meer ondersteunde gegevensverzamelingsapparaten nodig om gegevens te verzamelenAlle brainware-apparaten van EMOTIV maken verbinding met EmotivPRO-software, die ingebouwde LSL-mogelijkheden heeft voor het verzenden en ontvangen van datastreamsAanvullende bronnen:Code om LSL uit te voeren met apparaten van Emotiv, met voorbeeldscriptsNuttige LSL-demo op YouTubeSCCN LSL GitHub-repository voor alle bijbehorende bibliothekenGitHub-repository voor een verzameling submodules en appsHyPyP-analysepijplijn voor hyperscanningstudies

door Roshini Randeniya en Lucas Kleine

Werking:
Zodra dit script in de opdrachtregel wordt uitgevoerd, start het onmiddellijk een LSL-stream. Wanneer op de 'Enter'-toets wordt gedrukt, verstuurt het een trigger en speelt het een audiobestand af."""

import sounddevice as sd
import soundfile as sf
from pylsl import StreamInfo, StreamOutlet

def wait_for_keypress():
print("Druk op ENTER om audioweergave te starten en een LSL-marker te verzenden.")

while True: # This loop waits for a keyboard input
    input_str = input()  # Wait for input from the terminal
    if input_str == "":  # If the enter key is pressed, proceed
        break

def AudioMarker(audio_file, outlet): # functie voor het afspelen van audio en het verzenden van een marker
data, fs = sf.read(audio_file) # Laad het audiobestand

print("Playing audio and sending LSL marker...")
marker_val = [1]
outlet.push_sample(marker_val) # Send marker indicating the start of audio playback
sd.play(data, fs) # play the audio
sd.wait()  # Wait until audio is done playing
print("Audio playback finished.")

if name == "main": # HOOFDLUS
# LSL-stream instellen voor markers
stream_name = 'AudioMarkers'
stream_type = 'Markers'
n_chans = 1
sr = 0 # Stel de samplefrequentie in op 0 omdat markers onregelmatig zijn
chan_format = 'int32'
marker_id = 'uniqueMarkerID12345'

info = StreamInfo(stream_name, stream_type, n_chans, sr, chan_format, marker_id)
outlet = StreamOutlet(info) # create LSL outlet

# Keep the script running and wait for ENTER key to play audio and send marker
while True:
    wait_for_keypress()
    audio_filepath = "/path/to/your/audio_file.wav"  # replace with correct path to your audio file
    AudioMarker(audio_filepath, outlet)
    # After playing audio and sending a marker, the script goes back to waiting for the next keypress</code></pre><p><em><strong>**By running this file (even before playing the audio), you've initiated an LSL stream through an outlet</strong></em><strong>. Now we'll view that stream in LabRecorder</strong></p><p><strong>STEP 5 - Use LabRecorder to view and save all LSL streams</strong></p><ol><li data-preset-tag="p"><p>Open LabRecorder</p></li><li data-preset-tag="p"><p>Press <em><strong>Update</strong></em>. The available LSL streams should be visible in the stream list<br> • You should be able to see streams from both EmotivPROs (usually called "EmotivDataStream") and the marker stream (called "AudioMarkers")</p></li><li data-preset-tag="p"><p>Click <em><strong>Browse</strong></em> to select a location to store data (and set other parameters)</p></li><li data-preset-tag="p"><p>Select all streams and press <em><strong>Record</strong></em> to start recording</p></li><li data-preset-tag="p"><p>Click Stop when you want to end the recording</p></li></ol><p><br></p><img alt="" src="https://framerusercontent.com/images/HFGuJF9ErVu2Jxrgtqt11tl0No.jpg"><h2><strong>Working with the data</strong></h2><p><strong>LabRecorder outputs an XDF file (Extensible Data Format) that contains data from all the streams. XDF files are structured into, </strong><em><strong>streams</strong></em><strong>, each with a different </strong><em><strong>header</strong></em><strong> that describes what it contains (device name, data type, sampling rate, channels, and more). You can use the below codeblock to open your XDF file and display some basic information.</strong></p><pre data-language="JSX"><code>

Dit voorbeeldscript demonstreert een paar basisfuncties om EEG-gegevens die zijn verzameld met EmotivPRO-software te importeren en te annoteren. Het gebruikt MNE om een XDF-bestand te laden, enkele basis-metadata af te drukken, een info-object te maken en het vermogensspectrum te plotten."""

import pyxdf
import mne
import matplotlib.pyplot as plt
import numpy as np

Pad naar je XDF-bestand

data_path = '/path/to/your/xdf_file.xdf'

Laad het XDF-bestand

streams, fileheader = pyxdf.load_xdf(data_path)
print("XDF-bestandsheader:", fileheader)
print("Aantal gevonden streams:", len(streams))

for i, stream in enumerate(streams):
print("\nStream", i + 1)
print("Streamnaam:", stream['info']['name'][0])
print("Streamtype:", stream['info']['type'][0])
print("Aantal kanalen:", stream['info']['channel_count'][0])
sfreq = float(stream['info']['nominal_srate'][0])
print("Samplefrequentie:", sfreq)
print("Aantal samples:", len(stream['time_series']))
print("Print de eerste 5 datapunten:", stream['time_series'][:5])

channel_names = [chan['label'][0] for chan in stream['info']['desc'][0]['channels'][0]['channel']]
print("Channel Names:", channel_names)
channel_types = 'eeg'
Maak MNE-info-object

info = mne.create_info(channel_names, sfreq, channel_types)
data = np.array(stream['time_series']).T # Gegevens moeten worden getransponeerd: kanalen x samples
raw = mne.io.RawArray(data, info)
raw.plot_psd(fmax=50) # plot een eenvoudig spectrogram (vermogensspectrale dichtheid)Aanvullende bronnenDownload deze tutorial als een Jupyter-notebook van EMOTIV GitHubBekijk de online LSL-documentatie, inclusief het officiële README-bestand op GitHubJe hebt een of meer ondersteunde gegevensverzamelingsapparaten nodig om gegevens te verzamelenAlle brainware-apparaten van EMOTIV maken verbinding met EmotivPRO-software, die ingebouwde LSL-mogelijkheden heeft voor het verzenden en ontvangen van datastreamsAanvullende bronnen:Code om LSL uit te voeren met apparaten van Emotiv, met voorbeeldscriptsNuttige LSL-demo op YouTubeSCCN LSL GitHub-repository voor alle bijbehorende bibliothekenGitHub-repository voor een verzameling submodules en appsHyPyP-analysepijplijn voor hyperscanningstudies

Lees verder

Basisprincipes van neurale oscillaties