algorithmaudiofiltersignal-processingdc

Do these two DC filter algorithms achieve the same thing, and is one better?


I have two different DC filter algorithms and I'm wondering what their main differences are and if one is better than the other.

Here's a DC filter algorithm from dsprelated.com:

y = x - xm1 + 0.995 * ym1;
xm1 = x;
ym1 = y;

And here's the one I'm currently using, which is actually a low-pass filter that's inverted to make a high pass:

y += (x - y) * 0.005;
output = x - y;

For clarity, x is the current input sample in both cases. In the first example, y would be the output and, in the second example, output would be the output.

In the first example, there are 2 states (xm1 and ym1), and in mine there's only one (y). Doing some number crunching shows that the latter algorithm has a slower response than the first, but they do both function as low-frequency high-pass filters.

I understand that this might be subjective, but is there a preference for one of these algorithms over the other and, if so, why?

Many thanks.


Solution

  • We can write the output of each filter yt in terms of xt, xt-1, and yt-1

    Filter 1:

    yt = xt - xt-1 + 0.995yt-1

    Filter 2:

    Note that y = x-output in the original formulation, so:

    yt = xt - ( xt-1 - yt-1 + 0.005 ( xt - xt-1 + yt-1) )

    yt = xt - xt-1 + yt-1 - 0.005 ( xt - xt-1 + yt-1) )

    yt = xt - xt-1 + yt-1 - 0.005 ( xt - xt-1 + yt-1) )

    yt = 0.995xt - 0.995xt-1 + 0.995yt-1

    This is exactly the same as the first filter, except a little quieter. Multiplying the original signal by 1/0.995, we get exactly the same result.

    If you use output = (x-y)*(1.0/0.995), then you get the same filter.

    I don't see much reason to prefer one formulation over the other.