I have an application in which I need to remove DC components from a sampled signal in real time (basically the same constraints of ECG, but it has nothing to do with the brain). My measured signal in in the single µV range and the undesired offset wanders around and can be as high as tens of mV.

In this application, fast electrical stimulation is introduced which can reach hundreds of volts and can introduce a measurement artifact of nearly a volt. This stimulus is basically an impulse from the point of view of the processing.

Currently I am using a 200Hz 1st order highpass, as this has an acceptable artifact (i.e., impulse response) after the stimulus. Higher orders are not needed, and these are undesirable as it would make the artifact worse.

My problem is that the actual application will require filters to go down to 1Hz or even lower (in some cases we use 0.05Hz, as this is above the frequency content of the "wandering"). A filter at these frequencies would have an unacceptably long impulse response.

Are there any other techniques that would remove the DC-wandering without having the impulse response artifact problem?


The way this problem is usually handled involves knowledge of the location and duration of the disturbance (whose description I simplified for this question). This enters the category of evoqued response and involves some non-linear processing. Some of the alternatives I have tried:

  • Blanking the interference before it hits the filter. This requires precise synchronization that is not always available.
  • Remove the real-time aspect and process the data non-causally. Long data records are still required due to filter transients, initial conditions are critical (and, of course it is not real time).
  • Model the transients and remove them with data fits. Precise synchronization is no longer needed, but this might introducers own artifacts.
  • 1
    $\begingroup$ I don't want to be that guy but if your offset wanders around, it's not really DC. For one given, repeatible setup, is the offset stable? $\endgroup$
    – Ben
    Nov 5, 2018 at 23:06
  • $\begingroup$ @Ben picky, picky, picky ;^) Is there anything that is ever really DC? But no. It is not stable, it depends on slow electrochemical/physical processes (hence the <0.05Hz bandwidth) and moves a couple of mV. On a related application we just get a 1min average and subtract it, but that does not work here. $\endgroup$ Nov 5, 2018 at 23:11
  • 1
    $\begingroup$ Perhaps use a simple IIR order 1 filter, but preset its memory so that it starts with an output of 0. Simply use the first data (before your signal of intereset) to preset the filter. $\endgroup$
    – Ben
    Nov 5, 2018 at 23:19
  • $\begingroup$ @Ben those are the types of techniques that are used in the field (e.g., “blanking” the artifact before filtering), but they require precise knowledge of the location of the artifacts and can make the end-user uncomfortable. I should probably edit the question and add some of that information. $\endgroup$ Nov 6, 2018 at 0:26

1 Answer 1


Any filter with a DC gain of zero and, for most other frequencies, a gain of (or close to) 1, is a DC blocking filter.

So just make a high-pass filter (HPF) and put the corner frequency as close as you can to zero.

Of course, when the system is switched on, there will be a transient from blocking DC of 0 to blocking DC of whatever value it is. Without prior knowledge of what the initial DC is, I do not see how you can assume the initial value is anything other than zero. So all of the initial states of your HPF are zero. But once the turn-on transient is over, there should be no other transients unless the DC component has a sudden change (like a step function) and is not just "trending" to another value.

If this is done in fixed-point, you will have some serious numerical issues. You might even have serious numerical issues if it's floating-point and your HPF corner frequency is very very low. You might want to look at this old thing from me or this article from IEEE Signal Processing magazine. I dunno where to find it free.

  • $\begingroup$ The problem is not the initial transient, but the transients introduced by very large fast signal artifacts in the input. $\endgroup$ Nov 6, 2018 at 0:08
  • 1
    $\begingroup$ well, those transients are exactly what's left over in your signal after removing the DC. $\endgroup$ Nov 6, 2018 at 1:39
  • $\begingroup$ considering that those transients are one or two orders of magnitude larger than the signal of interest, that is not very helpful. Pure linear filtering is not a viable alternative, that is why I asked the question. $\endgroup$ Nov 6, 2018 at 1:44
  • 1
    $\begingroup$ so you have something contaminating your signal of interest that is one or two orders of magnitude larger than the signal of interest. if you cannot remove or attenuate the source of this contamination, then you need to somehow automatically recognize the contamination. that means the contamination must have properties that separate it from the signal of interest. one is evidently its size. another might be its shape, like perhaps a step discontinuity. $\endgroup$ Nov 6, 2018 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.