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


            /// <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;

            }

  • 相关阅读:
    vim进阶:better,faster and stronger
    转:开发者如何提升和推销自己
    python 列表及字典(按key、按value排序)
    python繁体中文到简体中文的转换
    svm支持向量机分类方法
    git与svn
    wchar_t与char转换、wstring与string转换
    mysql 事务
    mysql_real_escape_string() vs addslashes() vs addcslashes()
    Safe3 Web漏洞扫描系统 v9.6免费版
  • 原文地址:https://www.cnblogs.com/xihong2014/p/4129341.html
Copyright © 2020-2023  润新知