0
$\begingroup$

I designed a low pass Butterworth filter like so

public class LowPassFilter{

    double apass;
    double fpass;

    public LowPassFilter(double apass, double fpass){
        this.apass = apass;
        this.fpass = fpass;
    }

    public double[] firstOrderButterWorth(double[] wave, float sr) {
        double[] f = new double[wave.length];
        double k = 2.0*sr;
        k = (this.fpass*Math.PI*2.0)/Math.tan(this.fpass*Math.PI*2.0/k);
        double fpass = k*(Math.atan(((this.fpass*Math.PI*2.0)/k))); 
        double pbga = Math.sqrt(Math.pow(10.0, -0.1*apass)-1.0);
        double r = Math.pow(pbga, -1.0);
        double b2 = r;
        double b1 = 1.0/fpass; 
        double xn = (b2/b1)/((b2/b1)+k);
        double yn = (b2/b1-k)/((b2/b1)+k);
        double xBuf = 0.0;
        double yBuf = 0.0;
        for(int i = 0; i < wave.length; i++) {
            f[i] = (xn*wave[i])+(xn*xBuf)-(yn*yBuf);
            xBuf = wave[i];
            yBuf = f[i];
        }
        return f; 
    }
}

The filter works at the cutoff frequency, but the rolloff is less than 20db/decade.

Case 1: At fpass = 1hz and apass = -1db, I get a reduction of -0.98db at 1.5hz, and -13.31db at 10.5hz. Shouldn't the reduction at 10.5hz be close to -21db?

Case 2: At fpass = 1hz and apass = -3db, I get a reduction of -2.89db at 1.5hz, and -20.02db at 10.5hz. Shouldn't the reduction at 10.5hz be closer to -23db?

Besides that, there is a noise floor that goes up as the frequency goes down. At 0.5hz, the noise is 15.86% of the 1hz signal and 3.15% of the 10hz signal. That is for case 2. Case 1 has a lower noise floor, so it appears that the noise floor goes up as apass gets lower.

A third case at fpass = 1hz and apass = -10db confirms the hypothesis, (although it is not proof), because the noise floor is at 25.12% at 0.5hz for the 1hz signal. The 2.5hz bin is at 4.13% and goes down as the frequency goes up.

I am wondering if the noise floor is normal and if there is a way to reduce it.

I am also wondering why the roll off is not -20db/decade like it should be for a first order filter.

Thank you for taking the time to look over my question.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.