Data from muselab to matlab

Post Reply
sarahM
Posts: 2
Joined: Fri Nov 27, 2020 4:13 am

Data from muselab to matlab

Post 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 :)
User avatar
Peter Gamma
Posts: 180
Joined: Sat Jun 29, 2019 11:02 am
Location: Switzerland
Contact:

Re: Data from muselab to matlab

Post 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.
Last edited by Peter Gamma on Thu Nov 24, 2022 3:12 pm, edited 1 time in total.
User avatar
James
Site Admin
Posts: 1109
Joined: Wed Jan 02, 2013 9:06 pm

Re: Data from muselab to matlab

Post 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()
User avatar
Peter Gamma
Posts: 180
Joined: Sat Jun 29, 2019 11:02 am
Location: Switzerland
Contact:

Re: Data from muselab to matlab

Post by Peter Gamma »

Thanks, James for these wonderful scripts.
Post Reply