• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoAverage recursive filter method for pcDuino/Arduin ...
Previous Next

Average recursive filter method for pcDuino/Arduino(4)

Posted by: admin , April 23, 2014

 A. name: Average recursive filter method (also known as the moving average filter method)

B. method: take the continuous n sample values as a queue, the length of the queue is fixed as n, put each sample new data into the end of the line and throw away the original data (basis on first in, first out), do mean queue operations arithmetic for the n data, you can get new filter results. N value select: flow, N=12, pressure: N=4; liquid, N=4~12 temperature, N=1~4

C. advantages: it has a good interference for periodic inhibition, the smoothness is high, and it is suitable for high-frequency oscillation system.

D. disadvantages: the sensitivity is low, it is poor interface in occasional impulse inhibition and difficult to eliminate the sampling deviation of pulse interference, it is not suitable for more severe pulse interference, it wastes more RAM.

E. 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); 
} 
  
/ / Recursive average filtering method (also known as the moving average filter) 
# define FILTER_N 12 
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]; 
   } 
   return (int) (filter_sum / FILTER_N); 
}

Tags: pcDuino

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors