package net.heartshield.filter;

import net.heartshield.signal.DVec;

/**
 * Simple time delay filter block. Initialized with zeros.
 *
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-03-26
 */
public class Delay extends RFilterBlock {
    private int mDelay;
    private double[] mBuf;

    /**
     * @param delay  delay in number of samples
     */
    public Delay(int delay) {
        mDelay = delay;
        mBuf = DVec.zeros(delay);
    }

    @Override
    protected double[] batch(double[] x) {
        double[] buf = DVec.stack(mBuf, x);
        double[] y = DVec.get(buf, 0, buf.length - mDelay);
        mBuf = DVec.get(buf, buf.length - mDelay, buf.length);
        return y;
    }
}
