Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero-phase digital filtering #35

Closed
liuyijuna opened this issue Apr 26, 2022 · 2 comments
Closed

Zero-phase digital filtering #35

liuyijuna opened this issue Apr 26, 2022 · 2 comments

Comments

@liuyijuna
Copy link

liuyijuna commented Apr 26, 2022

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

@psambit9791
Copy link
Owner

JDSP currently does not have any equivalent method for filtfilt().

@psambit9791 psambit9791 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2022
@wenhuancui
Copy link

wenhuancui commented Aug 30, 2023

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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants