Recording EEG data in a text file ? (Complete sample rate)


Hi everyone,

I am developing a muse unity app for an Android phone and I need to record the EEG raw data in a text file. However, I am having a problem to record the complete sample rate (220Hz). My code is only recording about 60 samples per second. I am using the Muselab Unity Sample provided in Muse’s web page and just included some code to get the JSON String DataPacket, extract the EEG raw data and save it in a CSV file. See below my code.

I would really appreciate if somebody can tell me what is wrong in my code or if there is a better/efficient/reliable way to save the data completely. If there is another way, I would appreciate fi you provide an example as well.

Thank you in advance.

CODE - SampleApp.cs - Update function
’log’ is a StreamWriter variable.

void Update () {
    // Display the data in the UI Text field
    dataText.text = dataBuffer;
    connectionText.text = connectionBuffer;

	if (dataBuffer != null && dataBuffer != ""){
		string time = System.DateTime.Now.Hour+"-"+System.DateTime.Now.Minute+"-"+System.DateTime.Now.Second+"-"+System.DateTime.Now.Ticks;
		string date = System.DateTime.Now.Year+"\t"+System.DateTime.Now.Month+"\t"+System.DateTime.Now.Day;

		JsonData eegd = JsonMapper.ToObject (dataBuffer.ToString());

		log = File.AppendText (finalPath);
		log.WriteLine (date + "\t" + time + "\t" + eegd["DataPacketValue"][0] + "\t" + eegd["DataPacketValue"][1] + "\t" + eegd["DataPacketValue"][2] + "\t" + eegd["DataPacketValue"][3] );


Hi @igh,

The EEG data comes in at a much faster rate than the Update() method gets invoked, which is on every frame I believe. The Update() method is generally used to update UI elements. In order to capture all the EEG data to a file, you should spawn off another thread to write the data out to file in the receiveDataPackets(string data) method instead.

Hope this helps.


It helped.
Thank you, Jack!


Any chance you could share the code you used to solve this issue?