package net.heartshield.filter;

import net.heartshield.signal.DVec;
import net.heartshield.signal.Signal;

/**
 * Running percentile in a recent window.
 *
 * Includes a single-window delay and the first window's output samples are 0.
 *
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-05-16
 */
public class PercentileFilter extends WindowedBatchFilter {
    private double q;

    /**
     * @param win window size in samples
     * @param q   percentile in range [0:100]
     */
    public PercentileFilter(int win, double initial, double q) {
        super(win, initial);
        this.q = q;
    }

    @Override
    protected double processWindow(double[] buf, int start) {
        return Signal.percentile(DVec.get(buf, start, start + mDelay), q);
    }

    @Override
    public double[] batch(double[] x) {
        return super.batch(x);
    }
}
