Electronic – Analog circuit for moving-mean/moving-average

signal processingsingle-supply-op-amp

As a part of signal conditioning stage I am trying to find the moving mean/moving average of a signal at the output of instrumentation amplifier (used LM324-N for instrumentation amplifier).

Is it possible to find the moving average of a signal using analog circuitry alone?

Some constraints –

  1. Signal characteristics –

    • Frequency range – 0 to 2 Hz
    • Amplitude dynamic range – 0 to 3.5 V
  2. Window size to calculate the moving average = 5 sec (max)

  3. Preferably op-amp to be used, so as not to overload the output of instrumentation amplifier

  4. If op-amp to be used, it must be single supply (preferably LM324-N)

The signal-

  • Frequency Range = This is unfiltered signal, but will be band-limited to 0 to 2 Hz
  • Amplitude is of 10 bit ADC, Reference = 5V
  • Baseline shifts at approx. = 10/20/30/40/48 sec

Signal plot

Imp. Note – I am using moving average filter for baseline drift correction, and have already achieved in software. The doubt was if this can be done in pure analog circuit alone?

Best Answer

Getting a precise analogue of a digital moving average filter is somewhere between very difficult and impossible using analogue circuitry, as it involves delaying a signal for a long time.

There are various approximations you could use, which might (or might not) be acceptable to your particular application.

The first is a simple lowpass RC filter. Instead of the 'box car' impulse response of a moving average, it gives you a decaying exponential. For many signals and applications, this will result in similar dynamic behaviour. It is however a weighted average.

The second is a gated integrator, zeroed at time = 0, and read out at time = t_window. While this implements the unweighted average over the window time, it only produces one sample at the end. You could run a number of these with differing start times to produce samples more frequently, but this rapidly becomes silly in terms of duplicated hardware.

The exact analogue of an MA filter is to use an integrator on the input signal, and an analogue delay line going to a subtractor on the same integrator. 5 seconds length of cable is obviously impractical, but there used to be made 'CMOS bucket brigade charge coupled analogue delay lines'. I don't know whether these are still available, it's likely they've been completely superceded by low cost ADCs, MCUs and DACs with better and more flexible performance. Even with a high fidelity delay line, integrator drift will give you a long term problem.

If you are used to playing around with impulse responses, then you might consider the following way of tailoring the RC filter to be a bit more box-car like and a bit less exponential. Consider the impulse response as the sum of several exponentials with differing amplitudes and time constants. This image shows (in blue) an RC exponential response, and (in orange) what you get after subtracting 0.66 of an RC response of half the time constant, the result scaled up a bit. This flattens the first part of the curve and moves the weight a bit further out along the response. Just a thought. I'll let you play with adding more of these. There's not a lot that can be done about the long exponential tail however.

enter image description here