Assume that the data is read from 8-bit AD (if the higher-order AD can define the data type as int), the subroutine is get_ad();
1, limited secondary filtering 2, the median value filtering method/* N value can be adjusted according to the actual situation
Sorting using bubbling method*/
#define N 11
Char filter()
{
Char value_buf[N];
Char count,i,j,temp;
For ( count=0;count"N;count++)
{
Value_buf[count] = get_ad();
Delay();
}
For (j=0;j"N-1;j++)
{
For (i=0;i"Nj;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];
}
3. Arithmetic average filtering method 4, recursive average filtering method (also known as sliding average filtering method) 5, the median average filtering method (also known as anti-pulse interference average filtering method)/*
*/
#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"Nj;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[count];
Return (char)(sum/(N-2));
}
Machine Case,Cooling Fan,Micro Atx,Water Pump
Guangzhou Lufeng Electronic Technology Co. , Ltd. , https://www.lufengelectronics.com