赞
踩
- #define A 10
- uchar Value; //上次采样有效值
- uchar AmplitudeLimiterFilter()
- {
- uchar NewValue,ReturnValue;
- NewValue=GetAD(); //本次采样值
- if(((NewValue-Value)>A)||((Value-NewValue)>A)))
- ReturnValue=Value;
- else ReturnValue=NewValue;
- return(ReturnValue);
- }
- #define N 9
- unchar MiddleValueFilter()
- {
- unchar i,j,k;
- uchar temp;
- uchar ArrDataBuffer[N];
- for(i=0;i<N;i++) //一次采集N个数据放入数组中
- {
- ArrDataBuffer[i]=GetAD();
- Delay();
- }
- for(j=0;j<N-1;j++)//采样值由小到大排列
- {
- for(k=0;k<N-j-1;k++)
- {
- if(ArrDataBuffer[k]>ArrDataBuffer[k+1])
- {
- temp=ArrDataBuffer[k];
- ArrDataBuffer[k]=ArrDataBuffer[k+1];
- ArrDataBuffer[k+1]=temp;
- }
- }
- }
- return(ArrDataBuffer[(N-1)/2]); //取中间值
- }
- #define N 12
- uchar ArithmeticalAverageValueFilter()
- {
- uchar i;
- uchar Value;
- uchar sum;
- sum=0;
- for(i=0;i<N;i++)
- {
- sum+=GetAD();
- Delay();
- }
- Value=sum/N;
- return(Value);
- }
- #define N 12
- uchar Data[];
- uchar Gilde(Data[])
- {
- ucahr i,Value,sum;
- sum=0;
- Data[N]=GetAD();
- for(i=0;i<N;i++)
- {
- Data[i]=Data[i+1];//所有数据左移,低位仍掉
- sum+=Data[i];
- }
- Value=sum/N;
- return(Value);
- }
- #define N 12
- uchar Middle()
- {
- ucahr i,j,k,l;
- uchar temp;
- uchar ArrDataBuffer[N];
- uchar sum,Value;
- for(i=0;i<N;i++)//一次采集N个数据,存入数组
- {
- ArrDataBuffer[i]=GetAD();
- Delay();
- }
- for(j=0;j<N-1;j++)//采样值由小到大排列
- {
- for(k=0;k<N-j-1;k++)
- {
- if(ArrDataBuffer[k]>ArrDataBuffer[k+1])
- {
- temp=ArrDataBuffer[k];
- ArrDataBuffer[k]=ArrDataBuffer[k+1];
- ArrDataBuffer[k+1]=temp;
- }
- }
- }
- for(l=0;l<N-1;l++)
- {
- sum=ArrDataBuffer[l];
- }
- Value=Sum/(N-2);
- return(Value);
- }
- char Filter()
- {
- char max.min;
- int sum;
- char i;
- QUEUE[0]=NewData;
- max=QUEUE[0];
- min=QUEUE[0];
- sum=QUEUE[0];
- for(i=n-1;i!=0;i--)
- {
- if(QUEUE[i]>max)
- max=QUEUE[i];
- else if(QUEUE[i]<min)
- min=QUEUE[i];
- sum+=QUEUE[i];
- QUEUE[i]=QUEUE[i-1];
- }
- i=n-2;
- sum=sum-max-min+i/2;//加入(n-2)/2目的为了四舍五入
- sum=sum/i;
- return(sum);
- }
- #define A 10
- #define N 12
- uchar Data[N];
- uchar Limit()
- {
- ucahr i,Value,sum;
- Data[N]=GetAD();
- if(((Data[N]-Data[N-1])>A)||((Data[N-1]-Data[N])>A)))
- Data[N]=Data[N-1];
- else
- Data[N]=NewValue;
- for(i=0;i<N;i++)
- {
- Data[i]=Data[i+1];
- sum+=Data[i];
- }
- Value=sum/N;
- return(Value);
- }
- #define a 128
- uchar Value;
- ucahr OneFactorialFiler()
- {
- uchar NewValue;
- uchar ReturnValue;
- NewValue=GetAD();
- ReturnValue=(255-a)*NewValue+a*Value;
- ReturnValue/=255;
- return(ReturnValue);
- }
- #define N 10
- #define CoeSum 55
- const Coefficient[N]={1,2,3,4,5,6,7,8,9,10};
- uchar Data[N];
- uchar AAGAFilter()
- {
- uchar i,Value,sum;
- sum=0;
- Data[N]=GetAD();
- for(i=0;i<N;i++)
- {
- Data[i]=Data[i+1];
- sum+=Data[i]*Coefficient[i];
- }
- Value=sum/CoeSum;
- return(Value);
- }
- #define N 20
- uchar count;
- uchar Value;
- uchar Avoid()
- {
- uchar NewValue;
- if(NewValue==Value)
- count=0;
- else
- {
- count++;
- if(count>N)
- {
- count=0;
- Value=NewValue;
- }
- }
- return(Value);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。