/// <summary>
        /// 显示数据
        /// </summary>
        /// <param name="data">数据</param>
        private void ShowEdgeData(double[] data, List <int> edgeIndexs, DigitEdgeType digitEdgeType)
        {
            int SampleInterval = 1;

            var collection = new ObservableCollection <Data>();

            for (int i = 0; i < data.Length / SampleInterval; i++)
            {
                collection.Add(new Data()
                {
                    Value1 = data[i * SampleInterval], Value = i * 1000.0 / ((int)Scope.SampleRate) * SampleInterval
                });
            }
            var collection2 = new ObservableCollection <Data>();

            if ((digitEdgeType == DigitEdgeType.FirstFillingEdge) || (digitEdgeType == DigitEdgeType.FirstRisingEdge))
            {
                foreach (var item in edgeIndexs)
                {
                    //collection.Add(new Data() { Value1 = ScopeCHACollection[item / SampleInterval].Value1, Value = item * 1000.0 / ((int)Scope.SampleRate) * SampleInterval });
                    collection2.Add(new Data()
                    {
                        Value1 = collection[item / SampleInterval].Value1, Value = collection[item / SampleInterval].Value
                    });
                }
            }

            ScopeCHACollection     = collection;
            ScopeCHAEdgeCollection = collection2;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 分析脉冲数据
        /// </summary>
        /// <param name="edgeIndexs">边沿索引</param>
        /// <param name="isRisingFirst">首边沿为上升沿标志位</param>
        /// <param name="sampleRate"></param>
        /// <param name="frequencies"></param>
        /// <param name="dutyRatios"></param>
        public static void AnalysePulseData(List <int> edgeIndexs, DigitEdgeType digitEdgeType, int sampleRate, out List <double> frequencies, out List <double> dutyRatios)
        {
            frequencies = new List <double>();
            dutyRatios  = new List <double>();

            if ((edgeIndexs == null) ||
                (edgeIndexs.Count == 0) ||
                (digitEdgeType == DigitEdgeType.CriticalLevel) ||
                (digitEdgeType == DigitEdgeType.HeightLevel) ||
                (digitEdgeType == DigitEdgeType.LowLevel))
            {
                return;
            }

            int firstRisingIndex = (digitEdgeType == DigitEdgeType.FirstRisingEdge) ? 0 : 1;
            int tempCount1       = 0;
            int tempCount2       = 0;

            //当前脉冲的频率及占空比分析
            while (firstRisingIndex + 2 < edgeIndexs.Count)
            {
                tempCount1 = edgeIndexs[firstRisingIndex + 2] - edgeIndexs[firstRisingIndex];
                tempCount2 = edgeIndexs[firstRisingIndex + 1] - edgeIndexs[firstRisingIndex];
                frequencies.Add((double)sampleRate / (double)tempCount1);
                dutyRatios.Add((double)(tempCount2) / (double)(tempCount1));
                firstRisingIndex += 2;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 只有单个下降沿
        /// </summary>
        /// <param name="edgeIndexs">边沿索引</param>
        /// <param name="isRisingFirst">首边沿为上升沿标志位</param>
        /// <returns>结果</returns>
        public static bool IsOnlyFillingEdge(List <int> edgeIndexs, DigitEdgeType digitEdgeType)
        {
            if (edgeIndexs == null || edgeIndexs.Count == 0)
            {
                throw new ArgumentException($"{nameof(edgeIndexs)}无效");
            }

            if ((digitEdgeType == DigitEdgeType.FirstFillingEdge) && (edgeIndexs.Count == 1))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 通过阈值查找边沿
        /// </summary>
        /// <param name="source">数据源</param>
        /// <param name="minThreshold">最小阈值</param>
        /// <param name="maxThreshold">最大阈值</param>
        /// <param name="edgeIndexs">边沿索引</param>
        /// <param name="isRisingFirst">首边沿为上升沿标志位</param>
        public static void FindEdgeByThreshold(double[] source, double minThreshold, double maxThreshold, out List <int> edgeIndexs, out DigitEdgeType digitEdgeType)
        {
            if (source == null || source.Length == 0)
            {
                throw new ArgumentException($"{nameof(source)}无效");
            }

            if (minThreshold > maxThreshold)
            {
                throw new ArgumentException($"{nameof(minThreshold)}({minThreshold})不得大于{nameof(maxThreshold)}({maxThreshold})");
            }

            edgeIndexs    = new List <int>();
            digitEdgeType = DigitEdgeType.CriticalLevel;

            //当前位置,0-最大阈值与最小阈值之间,-1小于最小阈值,1-大于最大阈值
            int currentLocation = 0;

            if (source[0] >= maxThreshold)
            {
                digitEdgeType   = DigitEdgeType.HeightLevel;
                currentLocation = 1;
            }
            else if (source[0] <= minThreshold)
            {
                digitEdgeType   = DigitEdgeType.LowLevel;
                currentLocation = -1;
            }
            else
            {
                digitEdgeType   = DigitEdgeType.CriticalLevel;
                currentLocation = 0;
            }

            for (int i = 1; i < source.Length; i++)
            {
                switch (currentLocation)
                {
                case 1:
                    if (digitEdgeType == DigitEdgeType.CriticalLevel)
                    {
                        digitEdgeType = DigitEdgeType.HeightLevel;
                    }

                    //当前在顶部,查找下降沿
                    if (source[i] <= minThreshold)
                    {
                        edgeIndexs.Add(i);
                        currentLocation = -1;

                        if (digitEdgeType == DigitEdgeType.HeightLevel)
                        {
                            digitEdgeType = DigitEdgeType.FirstFillingEdge;
                        }
                    }
                    break;

                case -1:
                    if (digitEdgeType == DigitEdgeType.CriticalLevel)
                    {
                        digitEdgeType = DigitEdgeType.LowLevel;
                    }

                    //当前在底部,查找上升沿
                    if (source[i] >= maxThreshold)
                    {
                        edgeIndexs.Add(i);
                        currentLocation = 1;

                        if (digitEdgeType == DigitEdgeType.LowLevel)
                        {
                            digitEdgeType = DigitEdgeType.FirstRisingEdge;
                        }
                    }
                    break;

                default:
                    //查找下降沿
                    if (source[i] <= minThreshold)
                    {
                        currentLocation = -1;
                    }

                    //查找上升沿
                    if (source[i] >= maxThreshold)
                    {
                        currentLocation = 1;
                    }
                    break;
                }
            }
        }