View Raw SPL
csinterpxy(x, y, rate)
{
local olen, erate;
if (argc < 3)
{
if (argc < 2) error(sprintf("%s - input series required", __FUNC__));
rate = rate(y);
}
if (isdtunit(getvunits(x)))
{
/* dt */
sethunits(y, getvunits(x));
}
/* expected output length */
olen = 1 + round((max(x) - min(x)) * rate);
/* effective sample rate assuming input rate of 1.0 */
erate = (olen - 1) / (length(y) - 1);
/* csinterp y vals */
y = csinterp(y, rate(y) * erate);
/* linearly interp x vals */
x = xyinterp(x, deltax(x) / erate);
/* linearly sample */
y = xyinterp(x, y, 1.0 / rate);
return(y);
}