Closed liuyijuna closed 2 years ago
JDSP currently does not have any equivalent method for filtfilt().
A possible solution:
public double[] bandPassFiltfilt(double[] signal, int order, double lowCutoff, double highCutoff) throws IllegalArgumentException {
if (lowCutoff >= highCutoff) {
throw new IllegalArgumentException("Lower Cutoff Frequency cannot be more than the Higher Cutoff Frequency");
}
double centreFreq = (highCutoff + lowCutoff) / 2.0;
double width = Math.abs(highCutoff - lowCutoff);
double[] output = new double[signal.length];
uk.me.berndporr.iirj.Butterworth bp = new uk.me.berndporr.iirj.Butterworth();
bp.bandPass(order, this.samplingFreq, centreFreq, width);
for (int i = 0; i < output.length; i++) {
output[i] = bp.filter(signal[i]);
}
bp.reset();
double[] result = new double[output.length];
for (int i = output.length - 1; i >= 0; i--) { // reverse
result[i] = bp.filter(output[i]);
}
return result;
}
This is a great library, now I translate matlab program to java code, there is a filtfilt() method in matlab, it's Zero-phase digital filtering, is it supported in your library? thanks