public void AddVectorToMatrix(BrainWaveVector newWaveVector) { if (waveMatrix.Count() != 0) { if (EucledianDistance(waveMatrix[waveMatrix.Count() - 1].ReturnVector(), newWaveVector.ReturnVector()) != 0) { waveMatrix.Add(newWaveVector); } } else { waveMatrix.Add(newWaveVector); } }
static void OnDataReceived(object sender, EventArgs e) { BrainWaveVector waveVector = new BrainWaveVector(trainingClassNumber); //Device d = (Device)sender; form.SetStatusText("Receiving Data"); Device.DataEventArgs de = (Device.DataEventArgs)e; DataRow[] tempDataRowArray = de.DataRowArray; TGParser tgParser = new TGParser(); tgParser.Read(de.DataRowArray); // MentalEffort mentalEffort = new MentalEffort(); // mentalEffort.CalculateMentalEffort(, TGsensorType.); /* Loops through the newly parsed data of the connected headset*/ // The comments below indicate and can be used to print out the different data outputs. for (int i = 0; i < tgParser.ParsedData.Length; i++) { #region Build waveVector with ParsedData if (tgParser.ParsedData[i].ContainsKey("Raw")) { if (collectClickTrainingSample) { rawTrainingSampleArray.Add(tgParser.ParsedData[i]["Raw"]); } else if (finishedTraining) { AddData(tgParser.ParsedData[i]["Raw"]); } } #region Parse EEG Power Values if (tgParser.ParsedData[i].ContainsKey("EegPowerTheta")) { waveVector.AddValue(0, tgParser.ParsedData[i]["EegPowerTheta"]); } if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta")) { waveVector.AddValue(1, tgParser.ParsedData[i]["EegPowerDelta"]); } if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha1")) { waveVector.AddValue(2, tgParser.ParsedData[i]["EegPowerAlpha1"]); } if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha2")) { waveVector.AddValue(3, tgParser.ParsedData[i]["EegPowerAlpha2"]); } if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1")) { waveVector.AddValue(4, tgParser.ParsedData[i]["EegPowerBeta1"]); } if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2")) { waveVector.AddValue(5, tgParser.ParsedData[i]["EegPowerBeta2"]); } if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma1")) { waveVector.AddValue(6, tgParser.ParsedData[i]["EegPowerGamma1"]); } if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma2")) { waveVector.AddValue(7, tgParser.ParsedData[i]["EegPowerGamma2"]); } #endregion #endregion #region ParsedData if statements from sample - kept for reference if (tgParser.ParsedData[i].ContainsKey("Raw")) { //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]); // form.SetDataText((tgParser.ParsedData[i]["Raw"]) +"\t"); // AddData(tgParser.ParsedData[i]["Raw"]); } if (tgParser.ParsedData[i].ContainsKey("PoorSignal")) { //The following line prints the Time associated with the parsed data //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]); //A Poor Signal value of 0 indicates that your headset is fitting properly // Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]); // poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"]; } if (tgParser.ParsedData[i].ContainsKey("Attention")) { //Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]); } if (tgParser.ParsedData[i].ContainsKey("Meditation")) { //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]); } if (tgParser.ParsedData[i].ContainsKey("BlinkStrength")) { //Console.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]); } /* if (tgParser.ParsedData[i].ContainsKey("MentalEffort")) * { * * form.SetDataText((tgParser.ParsedData[i]["MentalEffort"]) + "\t"); * AddData(tgParser.ParsedData[i]["MentalEffort"]); * } */ /* foreach(string key in tgParser.ParsedData[i].Keys.ToArray()) * { * form.SetDataText(key + "\t"); * } */ // CalculateAndDisplayAverage(); #endregion if (finishedTraining) { if (waveVector.HasValue()) { //Check if correspondes to ClickTrainingSample // form.SetClickAverageText(CheckForEvent(clickTrainingSample, waveVector).ToString()); // form.SetDataText(waveVector.ReturnVector()[1].ToString() + '\t'); } bool sampleMatch = CheckForEvent(dataBuffer, rawTrainingSampleAverage, out rawDataAverage); bool complexSampleMatch = CheckForEvent(sampleMagnitudeAverage, dataComplex, out rawDataMagnitudeAverage); form.SetRelaxAverageText(sampleMatch.ToString()); form.SetClickAverageText(rawTrainingSampleAverage.ToString()); //form.SetDataText(rawDataAverage.ToString() + '\t'); form.SetDataText(rawDataMagnitudeAverage.ToString() + '\t'); form.SetMagnitudeEventText(complexSampleMatch.ToString()); if (sampleMatch) { if (matchCounter >= numberOfConsecutiveMatchesRequired && allowKeyEvent) { // TieIntoWindow(); // allowKeyEvent = false; matchCounter = 0; } matchCounter++; } else { matchCounter = 0; } if (complexSampleMatch) { if (transformedMatchCounter >= numberOfConsecutiveMatchesRequired && allowKeyEvent) { TieIntoWindow(); allowKeyEvent = false; ResetDataBuffer(); //timer ensures event cannot be read for 1 second // form.StartEventRestTimer(); transformedMatchCounter = 0; } transformedMatchCounter++; } else { transformedMatchCounter = 0; allowKeyEvent = true; } } else if (collectClickTrainingSample && waveVector.HasValue()) { clickTrainingSample.AddVectorToMatrix(waveVector); jointTrainingSample.AddVectorToMatrix(waveVector); } else if (collectRelaxTrainingSample && waveVector.HasValue()) { relaxTrainingSample.AddVectorToMatrix(waveVector); jointTrainingSample.AddVectorToMatrix(waveVector); } } }
public static bool CheckForEvent(BrainWaveMatrix trainedSampleMatrix, BrainWaveVector collectedVector) { return(trainedSampleMatrix.CheckForMatch(collectedVector.ReturnVector(), out distance)); }