IIR滤波器设计(java)

对于IIR系统可用如下表达式描述:
IIR滤波器设计(java)_第1张图片
其中,a、b为滤波器系数如:

b = [b(0),b(1),b(2),b(3)]
a = [a(0),a(1),a(2),a(3)],其中a(0)=1
public synchronized float[] IIRFilter(float[] signal, float[] a,float[] b) {

        in = new float[b.length];
        out = new float[a.length-1];

        float[] outData = new float[signal.length];

        for (int i = 0; i < signal.length; i++) {

            System.arraycopy(in, 0, in, 1, in.length - 1);
            in[0] = signal[i];

            //calculate y based on a and b coefficients
            //and in and out.
            float y = 0;
            for(int j = 0 ; j < b.length ; j++){
                y += b[j] * in[j];

            }

            for(int j = 0;j < a.length-1;j++){
                y -= a[j+1] * out[j];
            }

            //shift the out array
            System.arraycopy(out, 0, out, 1, out.length - 1);
            out[0] = y;

            outData[i] = y;


        }
        return outData;
    }

如需设计低通、高通、带通等滤波器只需传入不同的滤波器系数即可。

你可能感兴趣的:(Android)