C# 检测图表系列中的脉冲计数

C# 检测图表系列中的脉冲计数,c#,math,statistics,C#,Math,Statistics,我的图表上有一个直线系列。这类似于下图所示的方波。如何计算C#中的脉冲数 对于那些想看一些代码的人,可以看看下面。这个想法设定了一个最小值和最大值。例如,如果点位于“最小”和“最大”之间,而“下一次”不是,则我决定存在一条边。然而,我对这个想法有怀疑,尤其是在一些嘈杂的信号中 var K = new Queue<Point>(); // Point is a class that holds DateTime and double value as well as some oth

我的图表上有一个直线系列。这类似于下图所示的方波。如何计算C#中的脉冲数

对于那些想看一些代码的人,可以看看下面。这个想法设定了一个最小值和最大值。例如,如果点位于“最小”和“最大”之间,而“下一次”不是,则我决定存在一条边。然而,我对这个想法有怀疑,尤其是在一些嘈杂的信号中

var K = new Queue<Point>(); // Point is a class that holds DateTime and double value as well as some other properties.

                foreach (var Point in Source.Data.OrderBy(x => x.Timestamp))
                {
                    K.Enqueue(new Point() { Timestamp = Point.Timestamp, Value = Point.Value, InBand = (Point.Value >= Min) && (Point.Value <= Max) });
                }


var Points = new Point[3];

                foreach (var Point in K)
                {
                    if (null == Points[0])
                    {
                        Points[0] = Point;
                        continue;
                    }

                    if (null == Points[1])
                    {
                        Points[1] = Point;
                        continue;
                    }

                    if (null == Points[2])
                    {
                        Points[2] = Point;
                        continue;
                    }

                    if ((Points[0].InBand == false) && (Points[1].InBand == true) && (Points[2].InBand == true))
                    {
                        this.RunCount++;

                        Points[0] = null;
                        Points[1] = null;
                        Points[2] = null;

                        continue;
                    }

                    if ((Points[0].InBand == true) && (Points[1].InBand == false) && (Points[2].InBand == false))
                    {
                        this.StopCount++;

                        Points[0] = null;
                        Points[1] = null;
                        Points[2] = null;

                        continue;
                    }
                }
var K=new Queue();//Point是一个包含DateTime和double value以及一些其他属性的类。
foreach(Source.Data.OrderBy中的变量点(x=>x.Timestamp))
{

K.Enqueue(new Point(){Timestamp=Point.Timestamp,Value=Point.Value,InBand=(Point.Value>=Min)&&(Point.Value我将假设您的数据存储在
double[]
中。在这种情况下,您可以迭代这些值,并计算值从某个阈值以下到同一阈值以上的次数

这里是一个你应该能够适应的代码示例。我没有测试过,但它非常简单。请注意,如果你有一个非常嘈杂的信号,这可能会给你带来奇怪的结果,因此可能需要过滤。此外,该方法的名称有点错误,因为它计算了信号从下面经过的次数阈值设置为高于阈值

public int CountCrossings(double[] waveform, double threshold) {
    int count = 0;
    for (int i = 0; i < waveform.Length - 1; i++) {
        if (waveform[i + 1] >= threshold && waveform[i] < threshold)
            count++;
    }
    return count;
}
public int countcrossing(双[]波形,双阈值){
整数计数=0;
对于(int i=0;i=阈值和波形[i]<阈值)
计数++;
}
返回计数;
}

这是如何实现的?我们需要看一些代码。@gleng我已经包括了一些代码。我希望你们像Steve一样使用一个算法,而不是需要对一些代码进行评论。谢谢@Steve。这给了我一些改进解决方案的想法。但是噪音信号仍然是问题。我现在将忽略噪音问题并考虑信号清晰。