char filter()
{
int sum = 0;
for ( count=0;count<N;count++)
{
sum + = get_ad();
delay();
}
return (char)(sum/N);
}
4、递推平均滤波法(又称滑动平均滤波法)
#define N 12
char value_buf[N];
char i=0;
char filter()
{
char count;
int sum=0;
value_buf[i++] = get_ad();
if ( i == N ) i = 0;
for ( count=0;count<N,count++)
sum = value_buf[count];
return (char)(sum/N);
}
5、中位值平均滤波法(又称防脉冲干扰平均滤波法)
#define N 12
char filter()
{
char count,i,j;
char value_buf[N];
int sum=0;
for (count=0;count<N;count++)
{
value_buf[count] = get_ad();
delay();
}
for (j=0;j<N-1;j++)
{
for (i=0;i<N-j;i++)
{
if ( value_buf>value_buf[i+1] )
{
temp = value_buf;
value_buf = value_buf[i+1];
value_buf[i+1] = temp;
}
}
}
for(count=1;count<N-1;count++)
sum += value[count];
return (char)(sum/(N-2));
}
6、限幅平均滤波法
/*
*/
略 参考子程序1、3