A. method: it is the equal to “limiting filter method” + “average recursive filter method”, it will do the amplitude limiting for the new sample data each time, and send the new data to the queues to do the average recursive filter process.
B. advantages: blend the advantages of two filtering methods, it can eliminate impulse interference caused by deviation of sample values for the occasional pulse interference.
C. disadvantages: wasting RAM.
D. test code
#define FILTER_N 12 int Filter_Value; int filter_buf[FILTER_N]; void setup() { Serial.begin(9600); //initialize the serial communication randomSeed(analogRead(0)); // random seed filter_buf[FILTER_N - 2] = 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); } // Amplitude limiting the average filter method #define FILTER_A 1 int Filter() { int i; int filter_sum = 0; filter_buf[FILTER_N - 1] = Get_AD(); if(((filter_buf[FILTER_N - 1] - filter_buf[FILTER_N - 2]) > FILTER_A) || ((filter_buf[FILTER_N - 2] - filter_buf[FILTER_N - 1]) > FILTER_A)) filter_buf[FILTER_N - 1] = filter_buf[FILTER_N - 2]; for(i = 0; i < FILTER_N - 1; i++) { filter_buf[i] = filter_buf[i + 1]; filter_sum += filter_buf[i]; } return (int)filter_sum / (FILTER_N - 1);
Leave a Reply
You must be logged in to post a comment.