开发者

How can I apply multiple filters at same time?

I need to apply a FIR low pass, high pass, and notch filter at the same time. Each filter has it's own set of coefficients. All use the following algorithm. Can I add or average the output of all three or is there a better way?

SAMPLE fir_basic(SAMPLE input, int ntaps, const SAMPLE FIRcoefficient[], delay[])       
    {
        int ii;
        SAMPLE accum;

        /* store 开发者_如何学编程input at the beginning of the delay line */
        delay[0] = input;

        /* calc FIR */
        accum = 0;
        for (ii = 0; ii < ntaps; ii++) {
            accum += FIRcoefficient[ii] * delay[ii];
        }

        /* shift delay line */
        for (ii = ntaps - 2; ii >= 0; ii--) {
            delay[ii + 1] = delay[ii];
        }

        return accum;
    }


The problem with multiple stacked convolution filters (as your filter routine implementation suggests) is that for each pass, you (theoretically) need to access all the values that had an influence on the previous filter passes.

To illustrate this, consider the following example:

Input:    abcdefghijk
Filter 1: 121
Filter 2: 1210121

For pass 1, you get the following outputs:

a: 2a+b
b: a+2b+c
c: b+2c+d
d: c+2d+e
e: d+2e+f
...

In pass 2, you normally use the data already processed by pass 1 as a whole:

a: b+2c+d
b: a+c+2d+e
c: 2a+b+d+2e+f
d: a+2b+c+e+2f+g

If you combine the two:

a: (a+2b+c)+2(b+2c+d)+(c+2d+e)
b: (2a+b)+(b+2c+d)+2(c+2d+e)+(d+2e+f)
...

So, by combining the two filters, you make the function much more complicated as each pass is dependent on more original inputs than the previous one. You can precalculate the coefficients, but it needs some manual work.

Edit: I didn't take any scaling into consideration. If the scaling factor is always the same for a single filter pass, it can of course be factored out and applied to the final result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜