Page 1 of 1

Data from muselab to matlab

Posted: Tue Apr 20, 2021 10:28 am
by sarahM
Hey,
We are trying to transfer live data from muselab to matlab, and cant figure out how to do it yet.
Anyone did it before and can help us?

Thanks :)

Re: Data from muselab to matlab

Posted: Sun Apr 25, 2021 9:34 am
by Peter Gamma
I am also in trouble with a live stream from the Mind Monitor to an application. Since Matlab supporter Adam Danz deleted all my Matlab questions for reasons I cannot follow, I will use Python instead of Matlab. What I miss is a bridge from Mind Monitor OSC to Python OSC to the Influx Database client for Python. With the InfluxDB, you can do what you want with your data in Python. Is this path not of general interest to access sensor data from the Mind Monitor app? I am promoting this path as much as I can.

Re: Data from muselab to matlab

Posted: Sun Apr 25, 2021 11:38 am
by James
I'm not super familiar with Python, but here's a simple script to get you started.
This will just print the RAW EEG to the screen, but from here you can do anything now that you have the data:

Code: Select all

"""
Mind Monitor - Minimal EEG OSC Receiver
Coded: James Clutterbuck (2021)
Requires: pip install python-osc
"""
from datetime import datetime
from pythonosc import dispatcher
from pythonosc import osc_server

ip = "0.0.0.0"
port = 5000

def eeg_handler(address: str,*args):
    dateTimeObj = datetime.now()
    printStr = dateTimeObj.strftime("%Y-%m-%d %H:%M:%S.%f")
    for arg in args:
        printStr += ","+str(arg)
    print(printStr)
    
if __name__ == "__main__":
    dispatcher = dispatcher.Dispatcher()
    dispatcher.map("/muse/eeg", eeg_handler)

    server = osc_server.ThreadingOSCUDPServer((ip, port), dispatcher)
    print("Listening on UDP port "+str(port))
    server.serve_forever()
Here's a slightly more complex example that will start and stop recording to a CSV file when you send markers 1 and 2:

Code: Select all

"""
Mind Monitor - EEG OSC Receiver
Coded: James Clutterbuck (2021)
Requires: pip install python-osc
"""
from datetime import datetime
from pythonosc import dispatcher
from pythonosc import osc_server

ip = "0.0.0.0"
port = 5000
filePath = 'OSC-Python-Recording.csv'
recording = False
f = open (filePath,'w+')
f.write('TimeStamp,RAW_TP9,RAW_AF7,RAW_AF8,RAW_TP10,AUX,Marker\n')

def eeg_handler(address: str,*args):
    global recording
    if recording:
        dateTimeObj = datetime.now()
        timestampStr = dateTimeObj.strftime("%Y-%m-%d %H:%M:%S.%f")
        f.write(timestampStr)
        for arg in args:
            f.write(","+str(arg))
        f.write("\n")
    
def marker_handler(address: str,i):
    global recording
    dateTimeObj = datetime.now()
    timestampStr = dateTimeObj.strftime("%Y-%m-%d %H:%M:%S.%f")
    markerNum = address[-1]
    f.write(timestampStr+",,,,/Marker/"+markerNum+"\n")
    if (markerNum=="1"):        
        recording = True
        print("Recording Started.")
    if (markerNum=="2"):
        f.close()
        server.shutdown()
        print("Recording Stopped.")    

if __name__ == "__main__":
    dispatcher = dispatcher.Dispatcher()
    dispatcher.map("/muse/eeg", eeg_handler)
    dispatcher.map("/Marker/*", marker_handler)

    server = osc_server.ThreadingOSCUDPServer((ip, port), dispatcher)
    print("Listening on UDP port "+str(port)+"\nSend Marker 1 to Start recording and Marker 2 to Stop Recording.")
    server.serve_forever()

Re: Data from muselab to matlab

Posted: Sun Apr 25, 2021 12:56 pm
by Peter Gamma
Thanks, James for these wonderful scripts.