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?

  • \$\begingroup\$ What is the S/N ratio before and after you expect and what is the noise spectrum? What group delay is tolerated as the breakpoint introduces a phase shift whose slope is time delay? ( often seen on stock market charts) These parameters are needed to optimize your results. i.e. to match the filter of your spectrum pass filter and block the noise spectrum. Both combined create ideal moving average. Your hand drawing shows about 6f e.g. 2Hz and 12Hz noise with 0dB SNR ( signal=noise level) \$\endgroup\$ Mar 29 '19 at 7:06
  • 2
    \$\begingroup\$ This is one case where MCUs are superior. A simple low cost MCU with a very simple program can do this. And you can get a high accuracy analog signal out of it by rectifying PWM with a single op amp. What's the reason you can't use a MCU? \$\endgroup\$
    – Lundin
    Mar 29 '19 at 7:59
  • 2
    \$\begingroup\$ Development cost or BOM cost? The solution I propose is a few dollars of BOM, but you'll need a couple of weeks of programmer time. \$\endgroup\$
    – Lundin
    Mar 29 '19 at 8:38
  • 1
    \$\begingroup\$ Smells like an XY problem. \$\endgroup\$
    – Andy aka
    Mar 29 '19 at 8:44
  • \$\begingroup\$ In one of your comments on an answer you mention an anti-aliasing filter - which to me implies that you have some sort of sampling and probably something digital in your circuit which you haven't shared with us. You really should give us all the details if you want optimized solutions to your problem. \$\endgroup\$
    – brhans
    Mar 29 '19 at 13:34

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

  • \$\begingroup\$ An RC works exactly as an RC works. The question is, does it provide the response you are looking for? Are you looking for exactly a MA response, in which case the only solution is an ADC and MCU? Or are you looking for something that can be implemented with an LM324-N, and if so, what compromises are you prepared to make with the response? You might consider a 3rd order bessel lowpass filter, this can be implemented with a single LM324-N. It would have a higher latency than the RC I've described, but be more box-car like, and have a shorter tail. But it's still a weighted average. \$\endgroup\$
    – Neil_UK
    Mar 29 '19 at 9:29
  • \$\begingroup\$ @KulbhushanChand I think you have some misconceptions about how your moving average filter will behave. Have you done simulations? \$\endgroup\$ Mar 29 '19 at 13:54

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

"Is it possible" tends to be a poor question, because usually, things are possible but not practical. The short answer is (so long as you are talking about causal filters) yes, it's possible, but you probably don't want to do this.

Let's start with the idea that a moving average is a simple finite impulse response (FIR) filter, and the simplest form of the moving average impulse response would just be a series of points in discete time space of height 1/N, where N is the width of your filter -- i.e., a simple rectangle function. The frequency response would be a sinc function.

Now that you have the frequency response, there are algorithms that will let you transform this to the continuous time (see http://www.ijcst.com/vol23/3/karan.pdf, for example). Then, you would have a transfer function, consisting of zeros and poles, and there are a variety of tools that would let you design such a filter with op amps.

The resulting filters would be complicated, hard to build to good tolerance, expensive, and most likely, won't work particularly well when you're done, because of tolerance issues.

The real answer is to think about what you're trying to accomplish, not how you're accomplishing it. You're most likely trying to do something that requires a low-pass filtering operation. If so, design and implement the appropriate low-pass filter.

Alternatively, if you really need your moving average, the easiest path forward is probably to sample the signal, do your moving average, convert it back to analog, and Bob's your uncle.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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