Пример #1
0
    void GetData()
    {
        while(!finished)
        {
            if (inlet != null)
            {
                inlet.pull_sample(sample, 0.5f);

                numberOfScore++;
                if (numberOfScore == 1)
                {
                    Score = sample[0];
                }
                else
                {
                    Score = (numberOfScore-1)/numberOfScore*Score + sample[0]/numberOfScore;
                }
                //Score = Score * sample[0];

            }
            else
            {
                // wait until an EEG stream shows up
                liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "score", 1, 0.5f);

                // open an inlet and print some interesting info about the stream (meta-data, etc.)
                inlet = new liblsl.StreamInlet(results[0]);
                Debug.Log(inlet.info().as_xml());
            }
        }
    }
Пример #2
0
	public void PullQuality() {
		if (sendTCP.monitoring) {
			liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "Quality");
			liblsl.StreamInlet inlet2 = new liblsl.StreamInlet(results[0]);
			float[] sample = new float[num_channels];
			
			inlet2.pull_sample(sample);
			Debug.Log ("Quality: ");
			for (int i = 0; i < sample.Length; ++i)
				Debug.Log("# Ch" + (i+1) + ": " + sample[i]);
			
			if (sample.Length > 0) {
				if (sample[0] <= 0.5F)
					b_quality.GetComponent<Image>().color  = Color.red;	
				else if (sample[0] <= 0.8F)
					b_quality.GetComponent<Image>().color = new Color(1.0F, 0.5F, 0.0F);
				else 
					b_quality.GetComponent<Image>().color = Color.green;
				//button_quality.GetComponent<UIButton>().isEnabled = true;
			}
		}
		else {
			Debug.Log("Need to start monitoring EEG");
			//button_quality.GetComponent<UIWidget>().color = Color.gray;
		}
	}
Пример #3
0
    void GetData()
    {
        while(!finished)
        {
            if (inlet != null)
            {
                inlet.pull_sample(sample, 0.5f);
                //Breathe = sample[];
                if (sample[0] > 0)
                {
                    Debug.Log("Beat");
                    if (LastHeartbeat == false)
                    {
                        Heartbeat = true;
                    }
                    LastHeartbeat = true;
                }
                else
                {
                    LastHeartbeat = false;
                }
            }
            else
            {
                // wait until an EEG stream shows up
                liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "heart", 1, 0.5f);

                // open an inlet and print some interesting info about the stream (meta-data, etc.)
                inlet = new liblsl.StreamInlet(results[0]);
                Debug.Log(inlet.info().as_xml());
            }
        }
    }
Пример #4
0
    // look-up stream and fetch first value
    private void connect()
    {
        log ("Connect to LSL stream type: " + streamType);
        // wait until the correct type shows up
        liblsl.StreamInfo[] results = liblsl.resolve_stream ("type", streamType, 1, 0.5f);
        if (results.Length <= 0) {
            log ("No streams found");
            return;
        } else {
            log ("Found " + results.Length + " streams, looking for name: " + streamName);
        }
        liblsl.StreamInlet tmpInlet;
        for (int i=0; i < results.Length; i++) {
            // open an inlet and print some interesting info about the stream (meta-data, etc.)
            tmpInlet = new liblsl.StreamInlet (results [i]);
            try {
                liblsl.StreamInfo info = tmpInlet.info ();
                log ("Stream number: " + i + ", name: " + info.name ());
                if (info.name ().Equals (streamName)) {
                    nbChannels = info.channel_count();
                    log ("Stream found with " + nbChannels + " channels");
                    if (nbChannels < 1) {
                        log ("Error, no channels found, skip.");
                    }
                    else {
                        inlet = tmpInlet;
                        sample = new float[nbChannels];
                        break;
                    }
                }
            }
            // could lost stream while looping
            catch (TimeoutException) {
                log ("Timeout while fetching info.");
                continue;
            } catch (liblsl.LostException) {
                log ("Connection lost while fetching info.");
                continue;
            }
        }

        if (isConnected () && !init) {
            float firstValue = readRawValue();
            // may *again* disconnect while reading value
            if (isConnected ()) {
                listMax [0] = firstValue;
                listMax [0] = firstValue;
                init = true;
            }
        } else {
            log ("Stream not found.");
        }
    }
        static void Main(string[] args)
        {
            // wait until an EEG stream shows up
            liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "Markers");

            // open an inlet and print meta-data
            liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
            System.Console.Write(inlet.info().as_xml());

            // read samples
            string[] sample = new string[1];
            while (true)
            {
                inlet.pull_sample(sample);
                System.Console.WriteLine(sample[0]);
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            // wait until an EEG stream shows up
            liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");

            // open an inlet and print some interesting info about the stream (meta-data, etc.)
            liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
            System.Console.Write(inlet.info().as_xml());

            // read samples
            float[] sample = new float[8];
            while (true)
            {
                inlet.pull_sample(sample);
                foreach (float f in sample)
                    System.Console.Write("\t{0}",f);
                System.Console.WriteLine();
            }

            System.Console.ReadKey();
        }
Пример #7
0
        static void Main(string[] args)
        {
            // create a new StreamInfo and declare some meta-data (in accordance with XDF format)
            liblsl.StreamInfo info = new liblsl.StreamInfo("MetaTester","EEG",8,100,liblsl.channel_format_t.cf_float32,"myuid323457");
            liblsl.XMLElement chns = info.desc().append_child("channels");
            String[] labels = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"};
            for (int k=0;k<labels.Length;k++)
                chns.append_child("channel")
                    .append_child_value("label", labels[k])
                    .append_child_value("unit", "microvolts")
                    .append_child_value("type","EEG");
            info.desc().append_child_value("manufacturer","SCCN");
            info.desc().append_child("cap")
                .append_child_value("name","EasyCap")
                .append_child_value("size","54")
                .append_child_value("labelscheme","10-20");

            // create outlet for the stream
            liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);

            // === the following could run on another computer ===

            // resolve the stream and open an inlet
            liblsl.StreamInfo[] results = liblsl.resolve_stream("name","MetaTester");
            liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
            // get the full stream info (including custom meta-data) and dissect it
            liblsl.StreamInfo inf = inlet.info();
            Console.WriteLine("The stream's XML meta-data is: ");
            Console.WriteLine(inf.as_xml());
            Console.WriteLine("The manufacturer is: " + inf.desc().child_value("manufacturer"));
            Console.WriteLine("The cap circumference is: " + inf.desc().child("cap").child_value("size"));
            Console.WriteLine("The channel labels are as follows:");
            liblsl.XMLElement ch = inf.desc().child("channels").child("channel");
            for (int k=0;k<info.channel_count();k++) {
                Console.WriteLine("  " + ch.child_value("label"));
                ch = ch.next_sibling();
            }
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // wait until an EEG stream shows up
            liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");

            // open an inlet and print meta-data
            liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
            System.Console.Write(inlet.info().as_xml());

            // read samples
            float[,] buffer = new float[512, 8];
            double[] timestamps = new double[512];
            while (true)
            {
                int num = inlet.pull_chunk(buffer,timestamps);
                for (int s = 0; s < num; s++)
                {
                    for (int c = 0; c < 8; c++)
                        Console.Write("\t{0}", buffer[s, c]);
                    Console.WriteLine();
                }
            }
        }
Пример #9
0
    void Update()
    {
        if(FoundNIC == true && NICLaunched == true) // If ConnectNIC method is implemented and NIC is launched then connect() method is implemented with a delay of 2 seconds to avoid server based exceptions
        {
            Invoke("connect", 2f); 
            NICLaunched = false; // declared as false so that connect() method is not updated every time
        }
        byte status = queryStatus(); // regular status calls for proper functioning of interface
        if (LogText.text == "EEG monitoring started")
        {
            switch (status)
            {
                case (244): // if Enobio disconnects while the interface is on then display the following error on the interface
                    LogText.text = "Device Not Present. Restart your Enobio and Launch the application again.";
                    break;
            }
        }
        //print("0");
        //print(System.DateTime.Now.Hour + "-"+ System.DateTime.Now.Minute + "-" + System.DateTime.Now.Second + "-" + System.DateTime.Now.Millisecond);

        if (monitoring == true && Acquisition == true) // after the connection to enobio is established the startEEG() method is invoked within the connect() method and EEG monitoring is started
        {
            results = liblsl.resolve_stream("type", "EEG");
            inlet = new liblsl.StreamInlet(results[0]); // create inlet for EEG acquisition
            Acquisition = false; // declared false to prevent inlet to be repetitively created
            inletcreated = true;
        }
        if (monitoring == true && inletcreated == true) // after inlet is created
        {
            
            chunksize = inlet.pull_chunk(buffer, timestamps);

            for (int j = 0; j < num_electrodes; j++) // amount of new data per electrode
            {
                for (int i = 0; i < chunksize; i++) // size of queue array
                {
                    dataq[j].Dequeue();  // Dequeuing the first value
                    dataq[j].Enqueue(buffer[i, j]); // Enqueuing to the end (FIFO concept)
                }

            }

            for (int j = 0; j < num_electrodes; j++)
            {

                arrayofarrays[j] = dataq[j].ToArray(); // Coneverting array of queues to an array of arrays of object datatype
                floatarrayofarrays[j] = new double[num_samples]; 
                for (int i = 0; i < num_samples; i++)
                {
                    floatarrayofarrays[j][i] = System.Convert.ToDouble(arrayofarrays[j][i]); // converting object arrayofarrays to double arrayofarrays
                }

                mean[j] = floatarrayofarrays[j].Sum() / floatarrayofarrays[j].Length; // computing mean for indvidual electrodes 
            }
            
            for (int k = 0; k < num_electrodes; k++) // num_electrodes = 20
            {
                for (int i = 0; i < num_samples; i++) // num of eeg samples = 15000
                {
                    DynamicValue = Math.Pow((floatarrayofarrays[k][i] - mean[k]), 2); // Dynamic Value is the variable which = EEG data stored in an element of a matrix

                }
                Sum = Sum + DynamicValue; // Sigma component


                std[k] = Math.Sqrt(Sum / (floatarrayofarrays[k].Length - 1)); // standard deviation of data
            }
            
            for (int i = 0; i < num_electrodes; i++)
            {
                for (int k = 0; k < 1500; k++)
                {
                    EEGDisplay[k, i] = floatarrayofarrays[i][floatarrayofarrays[i].Length - (1500 - k)]; // creating a matrix of the most recent 3 second of data
                    normalizedvalues[i,k] = (EEGDisplay[k, i] - mean[i]) / (std[i]); // computing Z tranform on the 3 second matrix and storing it in normalizedvalues (matrix)
                }
                //  UnityEngine.Debug.Log(normalizedvalues[i]);

            }         


            if (monitoring == true && inletcreated == true && inlet2created == false) // Creating separate inlet2 for pulling Impedence data only if monitoring is on and the previous inlet for pulling EEG values is created
            {

                results2 = liblsl.resolve_stream("type", "Quality");
                inlet2 = new liblsl.StreamInlet(results2[0]);
                Acquisition2 = false;
                inlet2created = true;
            }

            if (inlet2created == true) // if inlet2 for pulling impedence values created then carry out impedence checks
            {
                ImpedenceChecks(); 

            }


        }

    }
Пример #10
0
 // @return value fetch from LSL stream, should check that still connected after call to be sure that a new value were read
 private float readRawValue()
 {
     if (isConnected ()) {
         // 1s timeout, if no sample by then, drop
         double timestamp = 0; // return value for no sample
         try {
             timestamp = inlet.pull_sample (sample, 1);
         } catch (TimeoutException) {
             log ("Timeout");
         } catch (liblsl.LostException) {
             log ("Connection lost");
         }
         if (timestamp == 0) {
             log ("No sample, drop connection");
             inlet = null;
         }
         // got sample, let's process it
         else {
             return sample [0];
         }
     }
     // poor default
     return defaultValue;
 }
Пример #11
0
    void GetData()
    {
        while(!finished)
        {
            if (inlet != null)
            {
                inlet.pull_sample(sample, 0.5f);

                if (listMax.Count < maxWindowSize)
                {
                    if (listMax.Count < (realTime - lastTime))
                    {
                        listMax.Add(float.MinValue);
                    }
                    if (listMin.Count < (realTime - lastTime))
                    {
                        listMin.Add(float.MaxValue);
                    }
                }
                else
                {
                    if (lastTime < (realTime - 1.0f))
                    {
                        lastTime = realTime;
                        listMax.RemoveAt(0);
                        listMin.RemoveAt(0);
                        listMax.Add(float.MinValue);
                        listMin.Add(float.MaxValue);
                    }
                }

                int currentItem = listMax.Count;
                Debug.Log(currentItem);
                if (sample[0] > listMax[currentItem-1])
                {
                    listMax[currentItem-1] = sample[0];
                }
                if (sample[0] < listMin[currentItem-1])
                {
                    listMin[currentItem-1] = sample[0];
                }

                float min = float.MaxValue;
                float max = float.MinValue;
                foreach(float element in listMin)
                {
                    if (element < min)
                    {
                        min = element;
                    }
                }
                foreach(float element in listMax)
                {
                    if (element > max)
                    {
                        max = element;
                    }
                }

                Breathe = (sample[0]-min) / (max-min);
                //Debug.Log (Breathe);
            }
            else
            {
                // wait until an EEG stream shows up
                liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "breath", 1, 0.5f);

                // open an inlet and print some interesting info about the stream (meta-data, etc.)
                inlet = new liblsl.StreamInlet(results[0]);
                Debug.Log(inlet.info().as_xml());

                inlet.pull_sample(sample, 0.5f);

                listMax[0] = sample[0];
                listMin[0] = sample[0];
            }
        }
    }