View Raw SPL
/* XY sinc interpolation */
ITERATE sincinterpxy(x, y, rate, correct, padlen, padtype)
{
        local olen, erate, yr, yi;

        if (argc < 6)
        {
                if (argc < 5)
                {
                        if (argc < 4)
                        {
                                if (argc < 3)
                                {
                                        if (argc < 2) error(sprintf("%s - input X and Y series required", __FUNC__));

                                        /* default to double original rate */
                                        rate = rate(y);
                                }

                                /* mean correction */
                                correct = 1;
                        }

                        padlen = 20;
                }

                padtype = 3;
        }

        if (isdtunit(getvunits(x)))
        {
                /* dt */
                sethunits(y, getvunits(x));
        }

        if (iscomplex(y))
        {
                yr = sincinterpxy(x, real(y), rate, correct, padlen, padtype);
                yi = sincinterpxy(x, imag(y), rate, correct, padlen, padtype);

                y = yr + i * yi;
        }
        else
        {
                /* 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);

                /* sincinterp y vals */
                y = sincinterp(y, rate(y) * erate, correct, padlen, padtype);

                /* linearly interp x vals */
                x = xyinterp(x, deltax(x) / erate);

                /* linearly sample */
                y = xyinterp(x, y, 1.0 / rate);
        }

        return(y);
}