A. method: continuous access to n sample values for arithmetic operations. When the value of n is large: the signal smoothness is high, but with lower sensitivity; when the value of n is small: the signal smoothness is lower, but the sensitivity is higher. Select N value: general flow, N=12, pressure: N=4
B. advantages: apply to filter the signal with random interference, this signal is characterized by an average, the signal in the vicinity of a range of values fluctuate.
C. disadvantages: it is not suitable for the measuring speed slower or requiring faster real-time control, and it is a little wasting RAM.
int Filter_Value; void setup () { Serial.begin (9600); / / initialize the serial communication randomSeed (analogRead (0)); / / random seed } 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); } / / Arithmetic average filter # define FILTER_N 12 int Filter () { int i; int filter_sum = 0; for (i = 0; i <FILTER_N; i + +) { filter_sum + = Get_AD (); delay (1); } return (int) (filter_sum / FILTER_N); }
Leave a Reply
You must be logged in to post a comment.