This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-MSPM0L1306: CCS, IQMATH, 1D interpolation

Part Number: LP-MSPM0L1306
Other Parts Discussed in Thread: MSPM0L1306

CCS IQMATH 1D interpolation

use CCS 12.2.0

mspm0_sdk_0_57_00_00_eng

is there a simple way to do 1D interpolation using IQMATH or another library?

Thanks,

Changhe Huang

  • Hi Changhe,

    The IQmath library utilizes the basic math functions allowing for fast floating point calculations. If you wanted to do some linear interpolation then you would have to create the formula and utilize the IQmath library functions to improve processing speed. 

    For example to get the slope based on 2 points you could use the formula (Y2 - Y1) / (X2 - X1) and use IQmath to speed up the floating point calculation. 

    //Initialize variables, using global type for example
    _iq qY2, qY1, qX2, qX1; 
    qY2 = _IQ(2.5);
    qY1 = _IQ(1.0);
    qX2 = _IQ(4.5);
    qX1 = _IQ(3.0);
    
    _iq deltaY = qY2 - qY1;
    _iq deltaX = qX2 - qX1;
    
    _iq slope = _IQdiv(deltaY, deltaX);
    
    _iq intercept = qY2 - _IQmpy(slope, qX2);
    
    

    Regards,

    Luke

  • Hello Luke:

    Thanks for the quick reply.

    I need to create an array of 32 elements, that is 32 X's and 32 Y's table, and do linear interpolation from some x to get y value, similar to IQMATH for calculating sine function. this is for sensor calibration.

    I am new to TI MCU. MSPM0L1306 is a very powerful hardware, but in IQMATH example, I cannot find how to process array function. 

    In other MCU like NXP KEA8 series, they have library function to make this calculation very easy.

    In order to use the 2-element array example you provided, need following steps:

    first Compute the index representing the interval, in which the linear interpolation will be performed.

    second Compute the abscissa offset within an interpolating interval.

    finally Compute the interpolated value by the linear interpolation between the ordinates read from the table at the start and the end of the computed interval.

    Please let me know if I am correct or not, or is there any easier way to do this.

    Best

    Changhe Huang

  • Hi Changhe,

    You would need to create your own function and pass in the 2 arrays (X array and Y array), then perform the math for linear interpolation. Since you have 32 elements linear regression might also work (though this is more extensive).

    There are plenty of tutorials on how to do linear interpolation or regression, you would then use the IQmath library for your datatypes and math functions (multiply and divide) to get the benefit of processing speed on the floating point math.

    Regards,

    Luke