In plain C, the difference equation for the dc blocker could be written as follows:
y = x - xm1 + 0.995 * ym1; xm1 = x; ym1 = y;Here, x denotes the current input sample, and y denotes the current output sample. The variables xm1 and ym1 hold once-delayed input and output samples, respectively (and are typically initialized to zero). In this implementation, the pole is fixed at , which corresponds to an adaptation time-constant of approximately samples. A smaller value allows faster tracking of ``wandering dc levels'', but at the cost of greater low-frequency attenuation.
A complete C++ class implementing a dc blocking filter is included in the free, open-source Synthesis Tool Kit (STK) . (See the DCBlock STK class.)
For a discussion of issues and solutions related to fixed-point implementations, see .