五点三次平缓滤波
作者:互联网
/// <summary> /// 降噪算法 /// </summary> /// <param name="inList">集合</param> /// <param name="func">运算字段</param> /// <param name="setFunc">赋值字段</param> /// <returns></returns> public static IList<T> OptimizePoints<T>(IList<T> inList, Func<T, double> func, Func<T, double, T> setFunc) { var N = inList.Count; IList<T> outList = new List<T>(); int i; if (N < 5) { return inList; } else { outList = inList;//先赋值然后再单个子项赋值 setFunc(outList[0], (3.0 * func(inList[0]) + 2.0 * func(inList[1]) + func(inList[2]) - func(inList[4])) / 5.0); for (i = 2; i <= N - 3; i++) { setFunc(outList[i], (func(inList[i - 2]) + func(inList[i - 1]) + func(inList[i]) + func(inList[i + 1]) + func(inList[i + 2])) / 5.0); } setFunc(outList[N - 2], (4.0 * func(inList[N - 1]) + 3.0 * func(inList[N - 2]) + 2 * func(inList[N - 3]) + func(inList[N - 4])) / 10.0); } return outList; }
调用
OptimizePoints<T>(result, s => s.字段, (t, val) => { t.字段 = val; return t; })
标签:outList,val,五点,平缓,滤波,IList,func,inList,赋值 来源: https://www.cnblogs.com/jiamiemie/p/10559643.html