zoukankan      html  css  js  c++  java
  • 中值滤波算法 C

    中值滤波用于在多组数据中取得平均值,过滤异常数据。

    算法如下:

    /***********************************************************************************************************************
    * Function Name: MidAvg_Filter
    * @brief  This function gets the middle average of middle values of the results.  
    * @param  buf - the pointer of the conversion result
    * @param  num - set the numbers of ad conversion result
    * @return average
    ***********************************************************************************************************************/
    uint16_t MidAvg_Filter(uint16_t *buf, uint8_t num)
    {
        uint8_t i, j;
        uint16_t tmp;
        uint32_t sum;
    
        /* sort the value from small to large */
        for(i = 0; i < num; i++)
        {
            for(j = 0; j < ((num - 1) - i); j++)
            {
                if(buf[j] > buf[j + 1])
                {
                    tmp = buf[j];
                    buf[j] = buf[j + 1];
                    buf[j + 1] = tmp;
                }
            }
        }
    
        /* Remove the smallest and largest values, then take the average */
        sum = 0;
        for(i = 2; i < (num - 2); i++)
        {
            sum += buf[i];
        }
        tmp = (uint16_t) (sum / (num - 4));
    
        return (tmp);
    }
  • 相关阅读:
    day89
    day88
    day87
    day86
    day85
    day84
    day83
    Maven仓库汇总
    [转载]AngularJS入门教程04:双向绑定
    [转载]AngularJS入门教程03:迭代器
  • 原文地址:https://www.cnblogs.com/lumao1122-Milolu/p/14283155.html
Copyright © 2011-2022 走看看