// create electrode instance for each electrode name in list public static void CreateElectrodes() { foreach (var name in ElectrodeNames) { var electrode = new Electrode(name); Electrodes[name] = electrode; } }
public static void BandPeakDetection(ArrayList bandData, string trainingFreq) { bandData.RemoveAt(0); var voteCount = 0; for (int i = 0; i < FreqBandNames.Count; i++) { // band data header is output in the following format: (electrode name)/(band type) var dataIndex = i; var nameParts = FreqBandNames[i].Split('/'); var currElectrode = GetElectrodeByName(nameParts[0]); var bandName = nameParts[1]; var currBand = GetBandByName(bandName, currElectrode); var dataChunk = bandData[dataIndex].ToString().Trim(); var dataHasPeak = "false"; var stdDev = currBand.MovingStd; if (Electrode.hasPeak(currBand, Convert.ToDouble(bandData[dataIndex]), isBand: true)) { dataHasPeak = "true"; voteCount += 1; // uncoment to indicate which electrode band fired /* Console.WriteLine(currElectrode.Name); * Console.WriteLine("!!! BANDDD");*/ } // add current electrode's moving standard dev. to file output. Mark preload w/ -1. if (Electrode.IsBandPreload) { dataChunk += $"/null/{dataHasPeak}/null/null/null/{trainingFreq}"; bandData[i] = dataChunk; } else { dataChunk += $"/{stdDev}/{dataHasPeak}/{currBand.MovingAvg}/{currBand.UpperBound}/{currBand.LowerBound}/{trainingFreq}"; bandData[i] = dataChunk; } } if (voteCount >= 35) { Console.WriteLine($"Hnadle Blink BAND: {voteCount} Votes"); } }
// helper function that returns current electrode public static EEGData GetBandByName(string bandName, Electrode currElectrode) { // grab relevant eeg data switch (bandName.Trim()) { case "theta": return(currElectrode.Theta); case "alpha": return(currElectrode.Alpha); case "betaL": return(currElectrode.BetaL); case "betaH": return(currElectrode.BetaH); case "gamma": return(currElectrode.Gamma); } // if band matches none of the above types return(null); }
public static void EEGPeakDetection(ArrayList eegData, string trainingFreq) { //copy current data feed so loop isn't messed up when adding calculations to eegData var loopEEGData = eegData; //vote count for blink decisions var voteCount = 0; for (int i = 0; i < NumberElectrodes; i++) { var currElectrode = GetElectrodeByName(ElectrodeNames[i]); // i+3... because 2 is index where electrode data starts var dataIndex = i + 3; var dataChunk = loopEEGData[dataIndex].ToString().Trim(); var dataHasPeak = "false"; var stdDev = currElectrode.EEGRaw.MovingStd; if (Electrode.hasPeak(currElectrode.EEGRaw, Convert.ToDouble(loopEEGData[dataIndex]))) { dataHasPeak = "true"; voteCount += 1; // uncomment to indicate which electrode fired /* Console.WriteLine(ElectrodeNames[i]); * Console.WriteLine("!!!");*/ } // add current electrode's moving standard dev. to file output. Mark preload w/ 0. if (Electrode.IsEEGPreLoad) { dataChunk += $"/null/{dataHasPeak}/null/null/null/{trainingFreq}"; } else { dataChunk += $"/{stdDev}/{dataHasPeak}/{currElectrode.EEGRaw.MovingAvg}/{currElectrode.EEGRaw.UpperBound}/{currElectrode.EEGRaw.LowerBound}/{trainingFreq}"; } eegData[dataIndex] = dataChunk; } var isPeak = voteCount >= ArtifactThresholdEEG; /* if (isPeak) Console.WriteLine("Blinkkkkkkkkkkkk!"); * // collect votes across electrodes and time * var isArtifact = ArtifactManager.IsArtifact(CurrPeak: isPeak); * if (isArtifact) * { * Console.WriteLine($"--------- Artifact Detected. Last Votecout: {voteCount} -------------"); * }*/ // extend to multiple blinks var isCtrlZ = ArtifactManager.IsArtifactCtrlZBinned(isPeak); if (isCtrlZ) { Console.WriteLine("Ctrl-z Initiated."); } if (isCtrlZ && Classification.IsTyping) { Console.WriteLine("Ctrl-z Initiated."); } }