Exemple #1
0
 /**
  * Create an EEGEvent with additional extra data
  */
 public EEGEvent(DateTime timestamp, EEGDataType type, double[] data, object extra)
 {
     this.timestamp = timestamp;
     this.type      = type;
     this.data      = data;
     this.extra     = extra;
 }
Exemple #2
0
 /**
  * Use this function to add a handler function that is called for each EEGEvent of the specified EEGDataType
  */
 public void AddHandler(EEGDataType type, DataHandler handler)
 {
     Logger.Log("AddHandler type=" + type);
     if (!handlers.ContainsKey(type))
     {
         handlers.Add(type, new List <DataHandler>());
     }
     handlers[type].Add(handler);
 }
Exemple #3
0
 double[] GetBandList(Dictionary <EEGDataType, double[]> dict, EEGDataType type)
 {
     if (dict.ContainsKey(type))
     {
         return(dict[type]);
     }
     else
     {
         double[] val = new double[channels];
         dict[type] = val;
         return(val);
     }
 }
Exemple #4
0
        /**
         * Use this function to remove a handler that has been added with the AddHandler function
         */
        public void RemoveHandler(EEGDataType type, DataHandler handler)
        {
            // Debug.Log("RemoveHandler type="+type);
            if (!handlers.ContainsKey(type))
            {
                throw new Exception("Handler was not registered");
            }

            if (!handlers[type].Remove(handler))
            {
                throw new Exception("Handler was not registered");
            }
        }
Exemple #5
0
 /**
  * Add a handler for raw (i.e, anything in EEGDataType) events
  * Adding a handler does not guarantee events will actually be recieved,
  * this is dependent on the configuration of the pipeline
  * @throws ArgumentException if handler is null
  */
 public void AddRawHandler(EEGDataType type, SharpBCIRawHandler handler)
 {
     if (handler == null)
     {
         throw new ArgumentException("handler cannot be null");
     }
     lock (rawHandlers)
     {
         if (!rawHandlers.ContainsKey(type))
         {
             rawHandlers.Add(type, new List <SharpBCIRawHandler>());
         }
         rawHandlers[type].Add(handler);
     }
 }
Exemple #6
0
        /**
         * Records the raw data for the current session to the filename/filepath specified
         * @throws ArgumentException if dataType is null
         */

        public void LogRawData(EEGDataType dataType, String fileName)
        {
            if (fileName == null)
            {
                fileName = DateTime.Now.ToString("MM-dd-yyyy HH-mm-ss");
                fileName = fileName + ".csv";
            }

            if (file == null)
            {
                file = new AsyncStreamWriter(fileName, true);
                var csv = new StringBuilder();
                csv.Append("Timestamp,Data Type,Extra,Data");
                var writableCsv = csv.ToString();
                file.WriteLine(writableCsv);
            }
            this.AddRawHandler(dataType, OnRawEEGData);
        }
Exemple #7
0
 /**
  * Remove a handler for raw(i.e, anything in EEGDataType) events
  * @throws ArgumentException if handler is null
  */
 public void RemoveRawHandler(EEGDataType type, SharpBCIRawHandler handler)
 {
     if (handler == null)
     {
         throw new ArgumentException("handler cannot be null");
     }
     lock (rawHandlers)
     {
         if (!rawHandlers.ContainsKey(type))
         {
             throw new ArgumentException("No handlers registered for type: " + type);
         }
         if (!rawHandlers[type].Remove(handler))
         {
             throw new ArgumentException("Handler '" + handler + "' not registered for EEGDataType: " + type);
         }
     }
 }
Exemple #8
0
        double[] RelBandPower(Dictionary <EEGDataType, double[]> powerDict, EEGDataType band)
        {
            double[] absPowers = new double[channels];
            foreach (var channelPowers in powerDict)
            {
                //Logger.Log("Looking at " + channelPowers.Key);
                for (int i = 0; i < channels; i++)
                {
                    absPowers[i] += Math.Pow(channelPowers.Value[i], 10);
                }
            }

            double[] relPowers  = new double[channels];
            double[] bandPowers = powerDict[band];
            for (int i = 0; i < channels; i++)
            {
                relPowers[i] = Math.Pow(bandPowers[i], 10) / absPowers[i];
            }
            return(relPowers);
        }
Exemple #9
0
 /**
  * Create an EEGEvent without any extra data
  */
 public EEGEvent(DateTime timestamp, EEGDataType type, double[] data)
     : this(timestamp, type, data, null)
 {
 }
Exemple #10
0
 /**
  * Records the raw data for the current session to a newly created file
  */
 public void LogRawData(EEGDataType dataType)
 {
     this.LogRawData(dataType, null);
 }