A. Name: limiting filtering method (also known as program judgment filtering method)
B. Method:
Determine the maximum allowable deviation value from the twice sample (set it as A), when detect a new value, judge: if the deviation between the this value and last time value <=A, this time value is effect. If the deviation between this time and last time > A, this time value is invalid, give up this value, and use the last time value instead of this time value.
C. Advantage
Can effectively overcome the pulse interference caused by accidental factors.
D.Disadvantage
It is unable to restrain periodic interface, and the smoothness is poor.
E. Test code
int Filter_Value; int Value; void setup() { Serial.begin(9600); randomSeed(analogRead(0)); Value = 300; } void loop() { Filter_Value = Filter(); Value = Filter_Value; Serial.println(Filter_Value); delay(50); } int Get_AD() { return random(295, 305); } #define FILTER_A 1 int Filter() { int NewValue; NewValue = Get_AD(); if(((NewValue - Value) > FILTER_A) || ((Value - NewValue) > FILTER_A)) return Value; else return NewValue; }
Leave a Reply
You must be logged in to post a comment.