Skip to content

Instantly share code, notes, and snippets.

@miki998
Created January 14, 2022 10:36
Show Gist options
  • Save miki998/568e36a2067fef6ef28dcc82bacd28f9 to your computer and use it in GitHub Desktop.
Save miki998/568e36a2067fef6ef28dcc82bacd28f9 to your computer and use it in GitHub Desktop.
import pyxdf
import sys
import numpy as np
import os
import matplotlib.pyplot as plt
from scipy.io.wavfile import write
# Quick script to check streams in XDF file
def plot_channel(position, channel, eeg):
plt.subplot(position)
plt.plot(eeg[:,channel])
def plot_eeg(streams):
for ix, stream in enumerate(streams):
for i in stream:
if i == "info":
if stream[i]["name"] == ["Headset-EEG"]:
values = np.array(stream["time_series"])
eeg = values[:,:-1]
times = values[:,-1]
plt.figure()
plot_channel(421, 0, eeg)
plot_channel(422, 1, eeg)
plot_channel(423, 2, eeg)
plot_channel(424, 3, eeg)
plot_channel(425, 4, eeg)
plot_channel(426, 5, eeg)
plot_channel(427, 6, eeg)
plot_channel(428, 7, eeg)
plt.show()
def plot_ecg(streams):
for ix, stream in enumerate(streams):
for i in stream:
if i == "info":
if stream[i]["name"] == ["Polar_ECG"]:
ecg = np.array(stream["time_series"])
plt.plot(ecg)
plt.show()
def plot_audio(streams):
for ix, stream in enumerate(streams):
for i in stream:
if i == "info":
if stream[i]["name"] == ["AudioMic"]:
audio = np.array(stream["time_series"])
plt.plot(audio)
plt.show()
write("audio.wav", 16000, audio)
def print_all(streams):
for ix, stream in enumerate(streams):
name = stream["info"]["name"][0]
for i in stream:
print('Key: ' + str(i))
print(stream[i])
print()
if __name__ == '__main__':
#np.set_printoptions(threshold=sys.maxsize)
streams, fileheader = pyxdf.load_xdf("tmp.xdf")
print_all(streams)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment