A. method: it is the improvement of average recursive filter method which adds the different right for the data at different time. Usually, the closer the moment of data, the bigger the right value it gets. The bigger the right value is given, sensitivity is higher, but the signal smoothness is lower.
B. advantages: for a large time delay relatively short sampling period and the time constant of the object system.
C. disadvantages: it could not rapid respond the current severity when the delay time constant is small, the sample time is long and the signal change is slow. The filter effect is worse.
D. test code
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); } / / Weighted average recursive filtering method # define FILTER_N 12 int coe [FILTER_N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; / / weighting coefficient table int sum_coe = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12; / / weighting factor and int filter_buf [FILTER_N + 1]; int Filter () { int i; int filter_sum = 0; filter_buf [FILTER_N] = Get_AD (); for (i = 0; i <FILTER_N; i + +) { filter_buf [i] = filter_buf [i + 1]; / / All data left, lower still out filter_sum + = filter_buf [i] * coe [i]; } filter_sum / = sum_coe; return filter_sum; }
Leave a Reply
You must be logged in to post a comment.