Пример #1
0
 public Electrode(string name, int windowSizeEEG = 180, double influenceEEG = .2, double zThresholdEEG = 3.5, int windowSizeBand = 10, double influenceBand = 0, double zThresholdBand = 3.5)
 {
     Name = name;
     // set electrode parameters
     WindowSizeEEG = windowSizeEEG;
     InfluenceEEG  = influenceEEG;
     ZThresholdEEG = zThresholdEEG;
     // band data parameters
     WindowSizeBand = windowSizeBand;
     InfluenceBand  = influenceBand;
     ZThresholdBand = zThresholdBand;
     // initialize eeg data containers
     EEGRaw = new EEGData();
     Theta  = new EEGData();
     Alpha  = new EEGData();
     BetaL  = new EEGData();
     BetaH  = new EEGData();
     Gamma  = new EEGData();
 }
Пример #2
0
        // recieves historical data and current data point (cld. be band or raw signal) as input
        // indicates whether current data point represents a peak as output
        public static bool hasPeak(EEGData eegData, double currSignal, bool isBand = false)
        {
            int    windowSizePeak = new int();
            double influencePeak  = new double();
            double zThresholdPeak = new double();

            // change parameters based on whether band or raw eeg
            if (isBand)
            {
                windowSizePeak = WindowSizeBand;
                influencePeak  = InfluenceBand;
                zThresholdPeak = ZThresholdBand;
            }
            else
            {
                windowSizePeak = WindowSizeEEG;
                influencePeak  = InfluenceEEG;
                zThresholdPeak = ZThresholdEEG;
            }

            var isPeak = false;

            // if preload still needs to occur
            if (eegData.WindowValues.Count < windowSizePeak)
            {
                eegData.WindowValues.Add(currSignal);
                // calculate window average
                eegData.MovingAvg = eegData.WindowValues.Average();
                // calculate window standard deviation
                eegData.MovingStd = Math.Sqrt(eegData.WindowValues.Average(v => Math.Pow(v - eegData.MovingAvg, 2)));
                return(false);
            }
            // indicate preload is done
            else
            {
                if (isBand)
                {
                    IsBandPreload = false;
                }
                else
                {
                    IsEEGPreLoad = false;
                }
            }
            // set decision boundaries for file write
            eegData.UpperBound = eegData.MovingAvg + (zThresholdPeak * eegData.MovingStd);
            eegData.LowerBound = eegData.MovingAvg - (zThresholdPeak * eegData.MovingStd);
            // if extreme
            if (Math.Abs(currSignal - eegData.MovingAvg) > zThresholdPeak * eegData.MovingStd)
            {
                // if peak
                if (currSignal > eegData.MovingAvg)
                {
                    // set last value of window equal to current value
                    currSignal = influencePeak * currSignal + (1 - influencePeak) * currSignal;
                    isPeak     = true;
                }
            }
            // set last value of window equal to current value after removing old data
            eegData.WindowValues.RemoveAt(0);
            eegData.WindowValues.Add(currSignal);
            // calculate window average
            eegData.MovingAvg = eegData.WindowValues.Average();
            // calculate window standard deviation
            eegData.MovingStd = Math.Sqrt(eegData.WindowValues.Average(v => Math.Pow(v - eegData.MovingAvg, 2)));
            return(isPeak);
        }