O'Reilly logo
  • Jor Fei Wong thinks this is interesting:

/* 1st order low-pass filter: time constant ~= 2^n samples

(6)           * TF = (1/2^n)/(z-((2^n - 1)/2^n)),

(6)           * e.g., n=3, y(k+1) = y(k) - y(k)/8 + x(k)/8 => y += (x - y)/8

(6)           */

Note

The transfer function (in Z-transform) of a first order low-pass filter is TF = kz^-1/(1-(1-k)z^-1) in which 1/k is the time constant. Using a time constant of 2^n, TF = (1/2^n)/(z-(2^n-1)/2^n).

Let x(k) and y(k) be the input and the output.

y(z)/x(z) = (1/2^n)/(z-(2^n-1)/2^n)
(z-(2^n-1)/2^n)y(z)=(1/2^n)x(z)
y(z)=((2^n-1)/2^n)(z^-1)y(z)+(1/2^n)(z^-1)x(z)

Take the inverse Z-transform

y(k)=((2^n-1)/2^n)y(k-1)+(1/2^n)x(k-1)

When n = 3

y(k)=y(k-1)-y(k-1)/8+x(k-1)/8

Equivalently

y(k+1)=y(k)-y(k)/8+x(k)/8