package net.heartshield.filter;

import uk.me.berndporr.iirj.Butterworth;

/**
 * Butterworth band-pass filter.
 *
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-05-15
 */
public class ButterBandPassFilter extends RFilterBlock {
    private Butterworth mButterworth;

    public ButterBandPassFilter(int order, double fps, double lowCutoffFreq, double highCutoffFreq) {
        mButterworth = new Butterworth();
        mButterworth.bandPass(order, fps, (lowCutoffFreq + highCutoffFreq) / 2.0, highCutoffFreq - lowCutoffFreq);
    }

    @Override
    protected double[] batch(double[] x) {
        double[] y = new double[x.length];
        for(int i = 0; i < x.length; i++)
            y[i] = mButterworth.filter(x[i]);
        return y;
    }
}
