- Products
- Download
- What's New
- Support
- FAQs
- technical support
- Installation
- Application Notes
- Device List
- Hints and Tips
- C38 - Special Page Access
- C6805 - Filling Unused ROM
- C6805 - Setting Multiple MORs
- C6805 - Working with MMEVS05/MMDS05
- C6808 and Emulators
- COP8C - Executing Initialization Code
- COP8C - S Register Support
- Debugging: Using Macros to Monitor Program Flow
- Declaring SPECIAL Memory
- eTPU - Function Set Support
- LCD Interface
- LOCAL Memory
- Low Cost, Low Speed A/D conversion for Embedded Systems
- MPC - Branch Islands on the PIC16C5x
- MPC - Constant ROM Arrays
- MPC - Named Address Space
- MPC - Setting Configuration Fuses
- Non-linear Data Transformations
- Using the CodeWright(TM) Editor
- Product-specific Notes
- Resources
- CODSupport
- product registration
- Distributors and resellers
- About Us
- search
- Fixed Point
- Fuzzy Logic
- Publishing
- FAE/Client Login
- more information
Non-linear Data Transformations
interpolation | nonlinear
There is a simple algorithm for interpolating values in a non-linear data set. The function interpolates between adjacent values in the data set using the bits of the lower value to weight the bits in the higher value. This data transformation algorithm requires that you have a set of data points at evenly spaced intervals, scaled to intervals of 256.
In the example below, the constable array holds 6 Y values for entries between 0 and 1280 at even intervals of 256 on the X axis. The findY() function uses the most significant byte of its argument, Xvalue, to index into the constable array, and performs a linear interpolation between the adjacent constable entries which fall immediately below and above the Xvalue.
The bits of the least significant byte of Xvalue are used to weight the interpolation by successively adding fractions of the difference between two table entries.
long l;
/* Y values for X-axis values from 0 to 1279 */
long constable[] = { 1,234,566,786,1234,4455 };
long findY (long Xvalue)
{
unsigned long Yvalue, DeltaY;
signed int lowbyte; //signed 8-bit int
/* Use MSB to index into the table. DeltaY is the
difference between the adjacent table entries */
Yvalue = constable[(short)Xvalue >> 8];
DeltaY = constable[((short)(Xvalue >> 8))+1]-Yvalue;
/* Use LSB of Xvalue to weight bits in DeltaY */
lowbyte = Xvalue &0xff;
do {
/* Divide the delta value by 2 */
DeltaY >>= 1;
/* If the high bit of the Xvalue LSB is set,
add remaining DeltaY to result */
if (lowbyte < 0)
{
Yvalue += DeltaY;
}
} while (lowbyte <<= 1); /* Examine next bit */
return(Yvalue);
}
void main (void)
{
l = findY(300);
}

eTPU_C:
C6808: