chanHist = [[0 for x in range(0)] for x in range(6)] N = 128 #We always take 128 chunks so we get to slighly above 60hz T = 1.0 / (N * 1 ) # We know that the emotive delivers 128 samples persecond count = 0 try: while True: packet = headset.dequeue() cCount = 0 for k, v in packet.sensors.iteritems(): if ((k in SENSOR_LIST) and ('value' in v) and ('quality' in v)): chanHist[cCount].append(v['value']) cCount += 1 mOscMessage.clear("/emokit/" + k + "/") mOscMessage.append(v['value']) mOscMessage.append(v['quality']) mOscClient.send(mOscMessage) count += 1 if count >= N: for i in range(0, len(chanHist)): output = [1 for x in range(8)] norm = [1 for x in range(8)] yf = np.abs(scipy.fftpack.fft(chanHist[i])) n = len(chanHist[i]) freq = np.fft.fftfreq(n, T) xf = np.linspace(0.0, 1.0 / (2.0 * T), N / 2) j = 2 while freq[j + 1] > freq[j]: # delta 0.5 - 3 hz
import gevent OSC_OUT_HOST = "localhost" OSC_OUT_PORT = 8444 SENSOR_LIST = 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4' if __name__ == "__main__": mOscClient = OSCClient() mOscClient.connect( (OSC_OUT_HOST,OSC_OUT_PORT) ) mOscMessage = OSCMessage() headset = Emotiv(serial_number="SN201405232628GM", vendor_id=8609, product_id=1) gevent.spawn(headset.setup) gevent.sleep(0) try: while True: packet = headset.dequeue() for k,v in packet.sensors.iteritems(): if ((k in SENSOR_LIST) and ('value' in v) and ('quality' in v)): mOscMessage.clear("/emokit/"+k+"/") mOscMessage.append(v['value']) mOscMessage.append(v['quality']) mOscClient.send(mOscMessage) gevent.sleep(0) except KeyboardInterrupt: headset.close() finally: headset.close()
gevent.spawn(headset.setup) gevent.sleep(0) chanHist = [[0 for x in range(0)] for x in range(6)] N = 128 #We always take 128 chunks so we get to slighly above 60hz T = 1.0 / (N*1) # We know that the emotive delivers 128 samples persecond count=0 try: while True: packet = headset.dequeue() cCount=0 for k,v in packet.sensors.iteritems(): if ((k in SENSOR_LIST) and ('value' in v) and ('quality' in v)): chanHist[cCount].append(v['value']) cCount += 1 mOscMessage.clear("/emokit/"+k+"/") mOscMessage.append(v['value']) mOscMessage.append(v['quality']) mOscClient.send(mOscMessage) count += 1 if count >=N: for i in range(0,len(chanHist)): output=[1 for x in range(4)] norm=[1 for x in range(4)] yf = np.abs(scipy.fftpack.fft(chanHist[i])) n = len(chanHist[i]) freq = np.fft.fftfreq(n, T) xf = np.linspace(0.0, 1.0/(2.0*T), N/2) j=2 while freq[j+1]>freq[j] : if round(freq[j])>4 and round(freq[j])<7 :
print('concentrated') else: print('distracted') if (b == [1.]): print('lda concentrated') else: print('lda distracted') k = OSCMessage('/vol') l = OSCMessage('/lda') print(int(a[0])) if (a == [1.]): k.append(1) else: k.append(2) client.send(k) k.clear() time.sleep(3) #client.send( OSCMessage("/vol", a) ) #client.send_message("/third", ok[i]) #client.send_message("/rev", ok[i]) #print(pfds) #print(dfas) #print(hursts) print(bins)