• 滑动平均滤波算法(递推平均滤波法)


            /// <summary>

            ///滑动平均滤波算法(递推平均滤波法)

            /// </summary>

            /// <param name="ADNum"为获得的AD数></param>

            /// GN为数组value_buf[]的元素个数,该函数主要被调用,利用参数的数组传值

            /// <returns></returns>   

            private const int GN = 12;

            private int filterPtr = 0;

            private bool isFirstGF = true;

            public float gSum = 0;

            float[] gbuf = new float[GN];

            public float GlideFilterAD(float ADNum)

            {

                if (isFirstGF)

                {

                    isFirstGF = false;

                    for (int i = 0; i < GN; i++)

                        gbuf[i] = ADNum;

                    gSum = ADNum * GN;

                    return ADNum;

                }

                else

                {

                    gSum += ADNum - gbuf[filterPtr] ;

                    gbuf[filterPtr++] = ADNum;

                    if (filterPtr == GN)

                        filterPtr = 0;    //先进先出,再求平均值

                    return (gSum / GN);

                }

            }  

           /// <summary>

           /// 限幅防抖滤波法

           /// </summary>

           /// <param name="ADNum"采样值></param>

           /// RANG:幅度  LPNUM :测试计数

           /// <returns></returns>

            private const int RANGE = 100;

            private const int LPNUM = 5;

            private float currentValue = 0;

            private int tmpCount = 0;

            private bool isFirstLF = true;

            public float LimitFilterAD(float ADNum)

            {

                if (isFirstLF)

                {

                    isFirstLF = false;

                    currentValue = ADNum;

                }

                if (Math.Abs(ADNum - currentValue) > RANGE)

                {

                    if(tmpCount++ >LPNUM)

                    {

                        isFirstLF = true;    // 初始化滑动平均值

                        tmpCount =0;

                        currentValue = ADNum;

                    }

                }

                else

               {

                    tmpCount =0;

               }

               return currentValue;

            }

  • 相关阅读:
    移动端工作心得
    小程序初探
    你可能会用到的"奇技赢巧"
    一个知乎日报pwa
    Progressive Web Applications
    Java中的基本数据类型以及装箱、拆箱
    用sql获得指定记录的空段数目和字段名称--实在想不通,这种场景应用在哪
    putIfAbsent,一个字段为空的话,将该字段设置为指定值
    PO、VO、BO、POJO、DAO、DTO都是什么对象
    Java中字符串连接符(+)和append的区别
  • 原文地址:https://www.cnblogs.com/xihong2014/p/4129341.html
Copyright © 2020-2023  润新知