private MotorImageryEvent ProcessConsecutiveThreshold(float confidence) { MotorImageryEvent newClassification = MotorImageryEvent.Rest; // If our confidence value is higher than the threshold, add a 1 to the buffer. if (confidence > classificationThreshold) { consecThresholdBuffer[consecThresholdIndex] = 1; consecThresholdBufferVal[consecThresholdIndex] = confidence; } else { consecThresholdBuffer[consecThresholdIndex] = 0; consecThresholdBufferVal[consecThresholdIndex] = confidence; } // if all positions in the buffer carry a 1, we have motor imagery. if (consecThresholdBuffer.Sum() == consecutiveBufferSize) { newClassification = MotorImageryEvent.MotorImagery; } // Increment our buffer index. if (consecThresholdIndex < consecutiveBufferSize - 1) { consecThresholdIndex++; } else { consecThresholdIndex = 0; } return(newClassification); }
private IEnumerator showMI(MotorImageryEvent value) { miText.text = Enum.GetName(typeof(MotorImageryEvent), value); yield return(new WaitForSeconds(0.15f)); //miText.text = ""; yield return(null); }
private MotorImageryEvent ProcessSingleThreshold(float confidence) { MotorImageryEvent newClassification = MotorImageryEvent.Rest; if (confidence > classificationThreshold) { newClassification = MotorImageryEvent.MotorImagery; } return(newClassification); }
public void LogEvent(String myevent = "", MotorImageryEvent miEvent = MotorImageryEvent.Rest, float miConfidence = -1f, float restConfidence = -1f) { BCILogs["Date"].Add(System.DateTime.Now.ToString("yyyy-MM-dd")); BCILogs["Timestamp"].Add(System.DateTime.Now.ToString("HH:mm:ss.ffff")); BCILogs["Event"].Add(myevent); BCILogs["MIEvent"].Add(Enum.GetName(typeof(MotorImageryEvent), miEvent)); // TRUE, FALSE BCILogs["MIConfidence"].Add(miConfidence.ToString()); // fx 0.43 BCILogs["RestConfidence"].Add(restConfidence.ToString()); // fx 0.51 BCILogs["BCIState"].Add(Enum.GetName(typeof(BCIState), bciState)); }
void Update() { if (bciState == BCIState.Disconnected) { return; } confidence = ((float)ReadSocket()); if (confidence == -1f) { // No Stream available. return; } // Update() runs faster (1/60) than our input data (1/16) arrives. // The code below is only run whenever a new value comes in from the BCI side. LogSample("Sample"); InputData inputData = new InputData(); inputData.confidence = 1 - confidence; inputData.type = InputType.MotorImagery; MotorImageryEvent newClassification = MotorImageryEvent.Rest; inputData.validity = InputValidity.Rejected; if (bciProcessingMode == BCIProcessingMode.SingleThreshold) { newClassification = ProcessSingleThreshold(confidence); } else if (bciProcessingMode == BCIProcessingMode.ConsecutiveThreshold) { newClassification = ProcessConsecutiveThreshold(confidence); } if (newClassification != classification) { if (newClassification == MotorImageryEvent.MotorImagery) { inputData.validity = InputValidity.Accepted; inputNumber++; } inputData.inputNumber = inputNumber; LogMotorImageryEvent(newClassification, confidence); onBCIMotorImagery.Invoke(newClassification); onInputFinished.Invoke(inputData); classification = newClassification; } if (confidence != 0f) { onBCIEvent.Invoke(confidence); } }
private void LogMotorImageryEvent(MotorImageryEvent miEvent = MotorImageryEvent.Rest, float lastConfidence = -1f) { Dictionary <string, object> gameLog = new Dictionary <string, object>() { { "Event", Enum.GetName(typeof(MotorImageryEvent), miEvent) }, { "BCIConfidence", lastConfidence }, { "BCIState", Enum.GetName(typeof(BCIState), bciState) }, { "InputNumber", inputNumber }, }; loggingManager.Log("Game", gameLog); if (bciProcessingMode == BCIProcessingMode.ConsecutiveThreshold) { string buffer = "("; foreach (float t in consecThresholdBufferVal) { buffer += t.ToString("0.000", System.Globalization.CultureInfo.InvariantCulture) + " "; } buffer += ")"; loggingManager.Log("Game", "BCIThresholdBuffer", buffer); } }
void FixedUpdate() { if (bciState == BCIState.Disconnected) { return; } float confidence = ((float)ReadSocket()); if (confidence == -1f) { // No Stream available. return; } InputData inputData = new InputData(); inputData.confidence = 1 - confidence; inputData.type = InputType.MotorImagery; MotorImageryEvent newClassification = MotorImageryEvent.Rest; inputData.validity = InputValidity.Rejected; if (confidence > classificationThreshold) { newClassification = MotorImageryEvent.MotorImagery; inputData.validity = InputValidity.Accepted; } if (newClassification != classification) { inputNumber++; inputData.inputNumber = inputNumber; onBCIMotorImagery.Invoke(newClassification); onInputFinished.Invoke(inputData); classification = newClassification; } if (classification != 0f) { onBCIEvent.Invoke(confidence); } }
public void OnMotorImageryDetected(MotorImageryEvent value) { StartCoroutine("showMI", value); }