I have an array of 5 sensors. I am trying to filter it while I get it from the ADC. As in I am trying to make sure that the new value is not greater than the old value by more than10 %. I need to have the final array as an array of 16bit values.
Here is what I tried:
New Value = ((1-0.10)*(Old Value)) + (0.10*(New Value))
Here is what I did in the code:
Code:
int16 Sensor1[5];
int16 Sensor2[5];
double e =0.10;
int i;
I update all the values in Sensor2[5] by reading the 5 sensors with the ADC.
I would appreciate it if someone could find whats wrong with this code!
Thank you.
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
Re: Filter Issue
Posted: Tue Jan 30, 2007 8:11 pm
Anonymous wrote:
... As in I am trying to make sure that the new value is not greater than the old value by more than 10%. ...
Here is what I tried:
New Value = ((1-0.10)*(Old Value)) + (0.10*(New Value))
You formula alone (which, I think, is an FIR filter) doesn't guarantee that the new value will be within 10% of the old value. Imagine a case, when the new value is more than 10 times bigger than the old value.
Anonymous wrote:
I would appreciate it if someone could find whats wrong with this code!
What's wrong with the output that the present code produces?
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
Re: Filter Issue
Posted: Wed Jan 31, 2007 10:48 am
Anonymous wrote:
I have an array of 5 sensors. I am trying to filter it while I get it from the ADC. As in I am trying to make sure that the new value is not greater than the old value by more than10 %. I need to have the final array as an array of 16bit values.
Here is what I tried:
New Value = ((1-0.10)*(Old Value)) + (0.10*(New Value))
Here is what I did in the code:
Code:
int16 Sensor1[5];
int16 Sensor2[5];
double e =0.10;
int i;
I update all the values in Sensor2[5] by reading the 5 sensors with the ADC.
I would appreciate it if someone could find whats wrong with this code!
Thank you.
That code looks like it was written to run on a PC with the extensive use of floating point and use of ambiguous variable types. It's faster to just filter by a binary fraction such as 1/8 or 1/16 and do all the math in Int16.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum