• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeProgramming LanguagesCLimiting filter method for pcDuino/Arduino (1)
Previous Next

Limiting filter method for pcDuino/Arduino (1)

Posted by: admin , May 8, 2014

A. Name: limiting filtering method (also known as program  judgment filtering method)

B. Method:
Determine the maximum allowable  deviation  value  from  the  twice  sample  (set it as A),  when detect  a new value,  judge: if the deviation  between the this value and last time value <=A,  this time value is effect.  If the deviation between this time and last time > A, this time value is invalid, give up this value, and use the last time value instead of this time value.

C. Advantage

Can effectively overcome the pulse interference caused by accidental factors.

D.Disadvantage

It is unable to restrain periodic interface, and the smoothness is poor.

E. Test code

int Filter_Value;
int Value;
  
void setup() {
  Serial.begin(9600);      
  randomSeed(analogRead(0)); 
  Value = 300;
}
  
void loop() {
  Filter_Value = Filter();       
  Value = Filter_Value;         
  Serial.println(Filter_Value); 
  delay(50);
}
  

int Get_AD() {
  return random(295, 305);
}
  

#define FILTER_A 1
int Filter() {
  int NewValue;
  NewValue = Get_AD();
  if(((NewValue - Value) > FILTER_A) || ((Value - NewValue) > FILTER_A))
    return Value;
  else
    return NewValue;
}

 

Tags: C

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