A. method: set a=0~1, this filter result = (1-a) * this sample value +a* the last filter results.
B. advantages: periodic interference with good inhibitory effect, suitable for occasions with higher frequency.
C. disadvantages: phase delay, sensitivity low degree of latency depends on a size cannot eliminate filter more frequently than the sampling frequency one-second interference signals.
E. test code
int Filter_Value; int Value; void setup () { Serial.begin (9600); / / initialize the serial communication randomSeed (analogRead (0)); / / random seed Value = 300; } void loop () { Filter_Value = Filter (); / / get the filter output value Serial.println (Filter_Value); / / serial output delay (50); } / / Used to randomly generate a current value of around 300 int Get_AD () { return random (295, 305); } / / First order lag filter method # define FILTER_A 0.01 int Filter () { int NewValue; NewValue = Get_AD (); Value = (int) ((float) NewValue * FILTER_A + (1.0 - FILTER_A) * (float) Value); return Value; }
Leave a Reply
You must be logged in to post a comment.