/////////////////////////////////限副滤波///////////////////
#define A 10
char value;
char filter()
{
char new_value;
new value=”get”_ad();
if ((new_value-value>A)‖(value-new_value> A)
return value;
return new_value;
}
/////////////////////////中位值滤波/////////////////////////
#define N 11
char filter()
{
char value_buf[N];
char count,i,j,temp;
for (count=0;count
value_buf[count]=get_ad();
delay();
}
for (j=0;j
{
for (i=0;i
if(value_buf[i]>value_buf[i+1])
{
temp=value_buf[i];
value_buf[i]=value_buf[i+1];
value_buf[i+1]=temp;
}
}
}
return value_buf[(N-1)/2];
}
/////////////////////////算术均匀滤波//////////////////////
#define N 12
char filter()
{
int sum=”0″;
for(count=0;count
sum+=get_ad();
delay();
}
return (char)(sum/N);
}
///////////////////去极值均匀滤波
#define N 11
int sum=”0″;
char filter()
{
char value_buf[N];
char count,i,j,temp;
for (count=0;count
value_buf[count]=get_ad();
delay();
}
for (j=0;j
{
for (i=0;i
if(value_buf[i]>value_buf[i+1])
{
temp=value_buf[i];
value_buf[i]=value_buf[i+1];
value_buf[i+1]=temp;
}
}
}
for(count=1;count<(N-1);count++)
{
sum+=value_buf[count];
delay();
}
return (char)(sum/(N-2));
}
///////////////////移动均匀滤波(递推均匀滤波)///////////
#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
return (char)(sum/N)
}
//////////////////////加权均匀滤波///////////////////////
#define N 12
char code jq[N]={1,2,3,4,5,6,7,8,9,10,11,12};//加权系数表
char code sum_jq=1+2+3+4+5+6+7+8+9+10+11+12;
char filter()
{
char count;
char value_buf[N];
int sum=”0″;
for (count=0;count
delay();
}
for (count=0;count
return (char)(sum/sum_jq);
}
/////////////////////////低通滤波////////////////////////
#define a
char value;
char filter()
{
char new_value;
new_value=get_ad();
return (a*new_value+(1-a)*value);
}