public static Dictionary<int, long> ProcessZeroCrossings(
     SampleValue[] samples,
     bool positiveTrigger = false,
     int offset = 0,
     int? crossingsCount = null,
     int averageCount = 4)
 {
     AverageValue averageValue = new AverageValue(averageCount);
     var crossings = new Dictionary<int, long>();
     bool crossSet = false;
     int sampleSize = samples.Length;
     for (int i = 0; i < sampleSize; i++)
     {
         averageValue.Value = samples[i].Value;
         if (i > averageValue.SampleSize)
         {
             var fvalue = averageValue.Value;
             var averageIndex = i - averageValue.SampleSize / 2;
             samples[averageIndex].Value = (int)fvalue;
             if (crossingsCount.HasValue && crossings.Count < crossingsCount.Value)
             {
                 if (!crossSet && ((!positiveTrigger && (fvalue > offset)) || (positiveTrigger && (fvalue < offset))))
                 {
                     crossSet = true;
                 }
                 if (crossSet && ((!positiveTrigger && (fvalue < offset)) || (positiveTrigger && (fvalue > offset))))
                 {
                     crossings.Add(averageIndex, samples[i].Tick);
                     crossSet = false;
                 }
             }
         }
     }
     return crossings;
 }
Ejemplo n.º 2
0
        public static Dictionary <int, long> ProcessZeroCrossings(
            SampleValue[] samples,
            bool positiveTrigger = false,
            int offset           = 0,
            int?crossingsCount   = null,
            int averageCount     = 4)
        {
            AverageValue averageValue = new AverageValue(averageCount);
            var          crossings    = new Dictionary <int, long>();
            bool         crossSet     = false;
            int          sampleSize   = samples.Length;

            for (int i = 0; i < sampleSize; i++)
            {
                averageValue.Value = samples[i].Value;
                if (i > averageValue.SampleSize)
                {
                    var fvalue       = averageValue.Value;
                    var averageIndex = i - averageValue.SampleSize / 2;
                    samples[averageIndex].Value = (int)fvalue;
                    if (crossingsCount.HasValue && crossings.Count < crossingsCount.Value)
                    {
                        if (!crossSet && ((!positiveTrigger && (fvalue > offset)) || (positiveTrigger && (fvalue < offset))))
                        {
                            crossSet = true;
                        }
                        if (crossSet && ((!positiveTrigger && (fvalue < offset)) || (positiveTrigger && (fvalue > offset))))
                        {
                            crossings.Add(averageIndex, samples[i].Tick);
                            crossSet = false;
                        }
                    }
                }
            }
            return(crossings);
        }