package net.heartshield.filter;

/**
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-05-16
 */
public class Diff extends RFilterBlock {
    double prev = 0;

    // could also just have been FIR({-1, 1})
    @Override
    protected double[] batch(double[] x) {
        double[] y = new double[x.length];
        if(x.length == 0)
            return y;
        y[0] = x[0] - prev;
        for(int i = 1; i < x.length; i++)
            y[i] = x[i] - x[i-1];
        prev = x[x.length - 1];
        return y;
    }
}
