forked from faturita/python-mindwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelaxMindwave.py
More file actions
107 lines (75 loc) · 2.56 KB
/
Copy pathRelaxMindwave.py
File metadata and controls
107 lines (75 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#coding: latin-1
#
# Run me with frameworkpython inside a virtual environment.
# Or install the environment.yml for Anaconda.
# This program uses Mindawave object to connect using bluetooth to Mindwave
# and get the raw eeg signals from there.
#
# It also plot the signal using matplotlib.
#
# Fs = 128
import socket,select
import json
import time, datetime, sys
import matplotlib.pyplot as plt
import sys
lamdalength = 10
Fs=128
show=False
# Please provide the number of sample points to take
if (len(sys.argv) > 1):
samplepoints = int(sys.argv[1])
else:
samplepoints = Fs*lamdalength
# def windowing(window, N):
# if len(window)>=N:
# if not False:
# awindow = np.asarray( window )
# fullsignal = fullsignal + window
# afullsignal = np.asarray( fullsignal )
# if (len(fullsignal) > 0):
# awindow = awindow - afullsignal.mean(0)
# o1 = psd(awindow[:,0])
# o2 = psd(awindow[:,1])
# print (o1, o2)
# features.append( [o1, o2] )
# # Slide window
# window = window[N/2:N]
# #window = window[1:N]
print ('Please remove the VGA connection that sometimes interfere with Mindwave')
import numpy as np
import mindwave, time
#headset = mindwave.Headset('/dev/tty.MindWaveMobile-DevA','ef47')
headset = mindwave.OfflineHeadset()
time.sleep(2)
plotter = Plotter(500,-500,5000)
attention = 0
meditation = 0
eeg = 0
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d-%H-%M-%S')
filename = './data/eeg.'+st+'.dat'
f = open(filename, 'w')
window = []
N = 128
try:
while (headset.poor_signal > 5):
print ("Headset signal noisy %d. Adjust the headset to fit better to your forehead and check earclip." % (headset.poor_signal))
print ("Writing %d seconds output to %s" % (lamdalength,filename))
for i in range(0,samplepoints):
#time.sleep(.01)
headset.dequeue()
(count,eeg, attention, meditation, blink) = (headset.count, headset.raw_value, headset.attention, headset.meditation, headset.blink)
window.append( int(eeg) )
if len(window) > N:
window = window[N/2:N]
awindow = np.asarray(window)
blink = np.sum(np.abs(awindow[0:N/2]))
plotter.plotdata( [eeg, 0, 0, blink])
#plotter.plotdata( [eeg, 0, 0])
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d-%H-%M-%S.%f')
f.write( str(st) + ' ' + str(eeg) + ' ' + str(attention) + ' ' + str(meditation) + ' ' + str(blink) + '\n')
finally:
headset.stop()
f.close()