Ejemplo n.º 1
0
 /// <summary>
 /// This functions should be used to calculate the relative band power, AFTER the absolute band power is calculated
 /// </summary>
 /// <param name="band">The band for which the relative power should be calculated</param>
 private void ComputeRelativeBandPower(BandFrequencyDefinition band)
 {
     if (AbsoluteBandPower.Keys.Contains <string>(band.Label))
     {
         RelativeBandPower.Add(band.Label, AbsoluteBandPower[band.Label] / totalFrequencyPower);
     }
     else
     {
         throw new Exception("The requested band [" + band.Label + "] isn't in the AbsoluteBandPower List please make sure to compute the absolute powers before using relative powers");
     }
 }
Ejemplo n.º 2
0
        public static double EEGPSD(List<DataReading> data, BandFrequencyDefinition BFD, Func<DataReading, double> valueAccesor)
        {
            List<FFT> ffts = new List<FFT>();
            for (int i = 0; i < data.Count - FFT.SAMPLING_WINDOW_LENGTH; i++)
            {
                FFT temp = new FFT(data.Skip(i).Take(FFT.SAMPLING_WINDOW_LENGTH).Select(x => valueAccesor(x)).ToList());
                if (double.IsNegativeInfinity(temp.AbsoluteBandPower[BFD.Label]))
                {
                    int j = 0;
                }
                ffts.Add(temp);

            }

            return ffts.Average(x => x.AbsoluteBandPower[BFD.Label]);
        }
Ejemplo n.º 3
0
        public static double EEGPSD(List <DataReading> data, BandFrequencyDefinition BFD, Func <DataReading, double> valueAccesor)
        {
            List <FFT> ffts = new List <FFT>();

            for (int i = 0; i < data.Count - FFT.SAMPLING_WINDOW_LENGTH; i++)
            {
                FFT temp = new FFT(data.Skip(i).Take(FFT.SAMPLING_WINDOW_LENGTH).Select(x => valueAccesor(x)).ToList());
                if (double.IsNegativeInfinity(temp.AbsoluteBandPower[BFD.Label]))
                {
                    int j = 0;
                }
                ffts.Add(temp);
            }

            return(ffts.Average(x => x.AbsoluteBandPower[BFD.Label]));
        }
Ejemplo n.º 4
0
        private void ComputeAbsoluteBandPower(BandFrequencyDefinition def)
        {
            double bandPower = 0;

            for (int i = def.LowerLimit; i <= def.UpperLimit; i++)
            {
                if (i >= rawFFTOutput.Length)
                {
                    BesterUI.Helpers.Log.LogMessage($"Not enough FFT samples {rawFFTOutput.Length} vs {def.UpperLimit}");
                    break;
                }
                complex c         = rawFFTOutput[i];
                double  magnitude = Math.Sqrt(c.real * c.real + c.imag * c.imag);
                bandPower += Math.Pow(magnitude, 2);
            }
            //Add to list of frequency bands
            AbsoluteBandPower.Add(def.Label, bandPower);
            totalFrequencyPower += bandPower;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// This functions should be used to calculate the relative band power, AFTER the absolute band power is calculated
 /// </summary>
 /// <param name="band">The band for which the relative power should be calculated</param>
 private void ComputeRelativeBandPower(BandFrequencyDefinition band)
 {
     if (AbsoluteBandPower.Keys.Contains<string>(band.Label))
     {
         RelativeBandPower.Add(band.Label, AbsoluteBandPower[band.Label] / totalFrequencyPower);
     }
     else
     {
         throw new Exception("The requested band [" + band.Label + "] isn't in the AbsoluteBandPower List please make sure to compute the absolute powers before using relative powers");
     }
 }
Ejemplo n.º 6
0
        private void ComputeAbsoluteBandPower(BandFrequencyDefinition def)
        {
            double bandPower = 0;

            for (int i = def.LowerLimit; i <= def.UpperLimit; i++)
            {
                if (i >= rawFFTOutput.Length)
                {
                    BesterUI.Helpers.Log.LogMessage($"Not enough FFT samples {rawFFTOutput.Length} vs {def.UpperLimit}");
                    break;
                }
                complex c = rawFFTOutput[i];
                double magnitude = Math.Sqrt(c.real * c.real + c.imag * c.imag);
                bandPower += Math.Pow(magnitude, 2);
            }
            //Add to list of frequency bands
            AbsoluteBandPower.Add(def.Label, bandPower);
            totalFrequencyPower += bandPower;
        }