/**************************************************************************** * Func: interp * * * * Desc: This function inputs a set of knots and outputs an array of values * * interpolated (linearly) between the knots * * * * Params: knot_x- array of knot x values * * knot_y- array of knot y values * * spline_x- array of input x values of interpolated points * * spline_y- array of interpolated values * * spline_length- number of values to interpolate * ****************************************************************************/ void interp(float *knot_x, float *knot_y, float *spline_x, float *spline_y, int spline_length) { int i, index; /* loop variable and array index */ float left_x, right_x; /* pointer to left and right of current interval */ float left_y, right_y; /* pointer to left and right value */ float frac_x; /* fraction x is within current knot interval */ /* intialize variables */ index =0; left_x=knot_x[index]; left_y=knot_y[index]; right_x=knot_x[index+1]; right_y=knot_y[index+1]; for(i=0; i knot_x[index]) { left_x=knot_x[index]; left_y=knot_y[index]; index++; right_x=knot_x[index]; right_y=knot_y[index]; } frac_x = (spline_x[i] - left_x) / (right_x - left_x); spline_y[i] = left_y + frac_x * (right_y - left_y); } }