CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Filter Issue

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Filter Issue
PostPosted: Tue Jan 30, 2007 7:20 pm     Reply with quote

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.

Then I do the following:
Code:


i=0;
for(i=0;i<5;i++)                   // Initialize Sensor1 Array.
{
Sensor1[i]=0;
}

for(;;)
{

//I update all the values in SensorOld[5] by reading the 5 sensors with the ADC.

i=0;                                                           
for(i=0;i<5;i++)
{
Sensor1[i]=((1-e)*(Sensor1[i]))+(e*(Sensor2[i]));
}

}



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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Filter Issue
PostPosted: Tue Jan 30, 2007 8:11 pm     Reply with quote

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

View user's profile Send private message

Re: Filter Issue
PostPosted: Wed Jan 31, 2007 10:48 am     Reply with quote

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.

Then I do the following:
Code:


i=0;
for(i=0;i<5;i++)                   // Initialize Sensor1 Array.
{
Sensor1[i]=0;
}

for(;;)
{

//I update all the values in SensorOld[5] by reading the 5 sensors with the ADC.

i=0;                                                           
for(i=0;i<5;i++)
{
Sensor1[i]=((1-e)*(Sensor1[i]))+(e*(Sensor2[i]));
}

}



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.

http://www.ccsinfo.com/forum/viewtopic.php?t=19509
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group