rewrote interpolation function based on julius smith's approach