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 support@ccsinfo.com

Best method to interpolate a point on a curve?

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







Best method to interpolate a point on a curve?
PostPosted: Wed May 09, 2007 8:58 am     Reply with quote

Hi guys,

Just wondering what is the most memory efficient method to calculate a point on a curve.

I have some data like:
X Y
-50 343000
-20 48910
0 16370
20 6250
50 1802
100 341

So given say, -10 I want to find a number between 16370 and 48910.

Is there a way to do it without needing to compute the gradient and intercept or is that the only/best way for an 8 bit micro?

Regards,
Ad
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Wed May 09, 2007 9:09 am     Reply with quote

Take a look at
http://www.bytecraft.com/Non-linear_Data_Transformations
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Wed May 09, 2007 11:50 am     Reply with quote

have a look at this thread:

Calibration Tables

this suggests a few methods.

Interpolation is quick but not accurate, a polynomial curve fit is more accurate but a bit slower !! I prefer the latter, but then again, my background is Instrumenatation and Test so I like the accuracy.
_________________
Regards,
Simon.
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Wed May 09, 2007 6:05 pm     Reply with quote

This is also a good link for interpolation with tables.

Reading word data from a table, interpolation
control guy
Guest







PostPosted: Thu May 10, 2007 3:16 am     Reply with quote

Thanks for the ideas ppl, much appreciated.

I've used excel to plot my dataset and solved using a polynomial.

The best fit curve I get is a 5th order poly. I currently use a straight line equation which is rough and ready and there is a significant difference in accuracy. This is what I would like to use:

y = -0.975x5 + 12.889x4 - 64.924x3 + 155.06x2 - 195.23x + 150.38

(y = temp, x = volts(0-5v))

The question is, how difficult is this to do for an 8 bit micro, and what considerations should I be aware of?

I still see the benefits of using the lookup table approach as I can specify the exact data in the code. So I think it is dependent on how practical it is to use the poly method which determines if I implement it.

BR,
Ad
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Thu May 10, 2007 5:00 am     Reply with quote

Which micro did you have in mind ? I've used the polynomial code (in the link above) in many 16Fxx and 18Fxxx devices with excellent results.

It all depends on you application and how much execution time and code space you can afford.

If its time, try the code I posted and do some timings on your micro. for your order of fit and a 40Mhz clock, the conversion should take around 620uS (according to CCS supplied figures).

Now, depending on what your calibration represents (i.e. temperature, pressure, voltage, etc) you can afford longer calc times as the sensor response time is going to be the 'slowest' part of the 'real world' to 'micro' conversion process.
_________________
Regards,
Simon.
control guy
Guest







PostPosted: Mon May 14, 2007 2:06 am     Reply with quote

Hi sjbaxter,

Thanks, I've decided to use a 3rd order poly to trade off accuracy and memory usage.

It seems to do the job!

Regards,
Ad
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