先介绍一下算法的基本思想:在一组采样值中,去掉 abandonMaxNum 个最大数据,去掉 abandonMinNum 个最小数据,余下的数据求平均值
/*
*函数功能:抗脉冲滤波法
*输入参数:*pArray:待滤波数组
num: 待滤波数据个数
abandonMaxNum:待清除最大数据个数
abandonMinNum:待清除最小数据个数
*返回值:滤波数据结果,如果数据有误,则返回0
*/
uint16_t AntiPulse_DigitalFilter(uint16_t* pArray,uint16_t num,uint16_t abandonMinNum,uint16_t abandonMaxNum)
{
uint16_t maxvalue;
uint16_t maxtmp;
uint16_t minvalue;
uint16_t mintmp;
uint16_t ui16i;
uint16_t maxcount = 0;
uint16_t mincount = 0;
uint32_t ui32total = 0;
uint32_t ui32max = 0;
uint32_t ui32min = 0;
if((pArray == NULL)||(num <= abandonMaxNum+abandonMinNum)||(num <2)||(num>60))
return 0;
maxvalue = pArray[0];
minvalue = pArray[0];
for(ui16i=0;ui16i