unsigned int filter_2(unsigned int data)
{
#define filter_len 10
static unsigned int buffer[filter_len] = {0};
static unsigned int* buffer_p = (int*)buffer + (filter_len - 1);
static unsigned int sum = (filter_len >> 1);
sum -= *buffer_p;
*buffer_p-- = data;
sum += data;
if (buffer_p < buffer)
{
buffer_p += filter_len;
}
return sum / filter_len;
}
例如程序中,如果存在这样的一段滤波函数,其中有一个for循环。
是不是势必会影响到程序的运行?
|