Commit 2d95cf90 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 MISC/Enumerable.cs 添加 平滑函数

parent 2c1358f2
......@@ -212,6 +212,51 @@ namespace Misc
}
return System.Linq.Enumerable.SequenceEqual(first, second, comparer);
}
/// <summary>
/// 对数列平滑;
/// 数列的两端,平滑量只有 radius;中间数据平滑量 = radius*2+1
/// </summary>
/// <param name="data">数列</param>
/// <param name="radius">平滑半径</param>
/// <returns></returns>
public static double[] Smooth(this IEnumerable<double> frame, int radius)
{
if (radius > 0)
{
double[] frame2 = new double[frame.Count()];
for (int i = 0; i < frame.Count(); i++)
{
double sum = 0;
int cnt = 0;
int index_b = i - radius;
int index_e = i + radius;
for (int j = index_b; j <= index_e; j++)
{
if ((j >= 0) && (j < frame.Count()))
{
double v = frame.ElementAt(j);
if (!double.IsNaN(v))
{
sum += v;
cnt++;
}
}
}
if (cnt > 0)
frame2[i] = sum / cnt;
else
frame2[i] = double.NaN;
}
return frame2;
}
else
{
return frame.ToArray();
}
}
}
/// <summary>
/// X Y 组合
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment