我的圖表中有一系列的線。這與下圖所示的方波類似。我如何計算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;
}
}
這是如何實現的?我們將需要看到一些代碼。 – gleng
@gleng我已經包含了一些代碼。我寧願你指定一個像史蒂夫一樣的算法,而不需要評論一些代碼。 – Demir