Interpolation

This project shows you how to implement linear interpolation with Realizer. The value of input X is used to find the nearest 2 points in the lookup-table. Those 2 points are interpolated, which results in output Y.

Main scheme

Used variables:
  • X: the value of the input
  • X1, X2: the nearest points in the lookup-table (input-values of the lookup-table)
  • Y1: the output of the lookup-table when the input is X1
  • Y2: the output of the lookup-table when the input is X2
  • DX: distance between X2 and X1, is always 10, DX = 10
  • DY: distance between Y2 and Y1, DY = Y2 - Y1
  • dx: distance between X and X1, dx = X - X1
  • dy: distance between Y and Y1, dy = Y - Y1

Linear interpolation:
  • DX/DY = dx/dy
  • so dy = dx * DY / DX
  • as dy = Y - Y1 and DX = 10, this results in
  • Y - Y1 = dx * DY / 10
  • so Y = dx * DY / 10 + Y1

Simulation

On the figure shown above is the interpolation schematic in the Realizer simulator. As you can see on the table on top the X is already known that is 15.
  • On 15 seconds the interpolation calculats that the Y must be 226.
  • 226 is where the two lines cross.
  • One step back is 14 with output 196 and one step forward is 15 with output 130.

Download

Interpolation.zip

Prepared for device: ST6230B, PIC16F876 other devices possible by reconnecting I/O pins.