View previous topic :: View next topic |
Author |
Message |
control guy Guest
|
Best method to interpolate a point on a curve? |
Posted: Wed May 09, 2007 8:58 am |
|
|
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
|
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Wed May 09, 2007 11:50 am |
|
|
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
|
|
|
control guy Guest
|
|
Posted: Thu May 10, 2007 3:16 am |
|
|
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
|
|
Posted: Thu May 10, 2007 5:00 am |
|
|
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
|
|
Posted: Mon May 14, 2007 2:06 am |
|
|
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 |
|
|
|