modm API documentation
Interpolation Methods

Classes

class  modm::interpolation::Lagrange< T, Accessor >
 
class  modm::interpolation::Linear< T, Accessor >
 

Detailed Description

lbuild module: modm:math:interpolation

Simple interpolation methods between a list of points.

Linear Interpolation

Example:

// Definition of the supporting points. The first type is the
// input type, the second the output type
// Create a array of supporting points describing the curve.
const Point supportingPoints[6] =
{
{ 30, -200 },
{ 50, 0 },
{ 90, 50 },
{ 150, 2050 },
{ 200, 3000 },
{ 220, 20000 }
};
modm::interpolation::Linear<Point> value(supportingPoints, 6);
// ...
int8_t a = 40;
int16_t b = value.interpolate(a);

Example with supporting points read from flash:

// Definition of a supporting point
// Array of supporting points in flash
FLASH_STORAGE(Point supportingPoints[6]) =
{
{ 30, -200 },
{ 50, 0 },
{ 90, 50 },
{ 150, 2050 },
{ 200, 3000 },
{ 220, 20000 }
};
// Create an interpolator object which reads the
// supporting points from flash.
value(modm::accessor::asFlash(supportingPoints), 6);
// ...
int8_t a = 20;
int16_t b = value.interpolate(a);

Lagrange Interpolation

Example:

// interpolate x^2 over the range of 1 <= x <= 3
Point points[3] =
{
{ 1, 1 },
{ 2, 4 },
{ 3, 9 }
};
// ...
float output = value.interpolate(1.5f);
// output => 2.25;
Warning
Only floating points types are allowed as second type of modm::Pair, otherwise the calculation will deliver wrong results!

See Wikipedia.