Group delay of moving average filter

I have implemented a moving average filter (in Python) where I fill a list with values and average them. When new values arrive the oldest will be deleted.

Now I am wondering how much delay I get with this filtering.

I am sampling a sensor signal (voltage) with 1000 Hz and I have read often that the group delay (for my understanding that is the delay?) for a moving average filter for M values (window size) is (M-1)/2.

I can't really understand it because:

Lets say I have the a window size of 5 and following measured values arriving in my empty moving average filter:

• 6x 1 Volt
• 6x 3 Volt

|1|1|1|1|1|1|3|3|3|3|3|3|

First I am waiting until my moving average filter is filled (until the fifth measured value).

Then I get these average values

|1|1|1|1|1| 1 |3|3|3|3|3|3|   1   [1,1,1,1,1]
|1|1|1|1|1|1| 3 |3|3|3|3|3|  7/5  [1,1,1,1,3] <- 3 Volt first time measured
|1|1|1|1|1|1|3| 3 |3|3|3|3|  9/5  [1,1,1,3,3]
|1|1|1|1|1|1|3|3| 3 |3|3|3| 11/5  [1,1,3,3,3]
|1|1|1|1|1|1|3|3|3| 3 |3|3| 13/5  [1,3,3,3,3]
|1|1|1|1|1|1|3|3|3|3| 3 |3| 15/5  [3,3,3,3,3] <- 3 Volt average


I would expect that my delay would be (M-1)/2 = (5-1)/2 = 2 measurements but I get my 3 volts in my moving average filter just after 4 more measurements (so delay M-1).

I would be very happy if someone could explain how I can determine my delay.

"Group delay" isn't the delay between the change on the input and the first effect; it's the delay that a packet of oscillations of different frequencies experience.

In the case of a linear phase filter (and your moving average, its impulse response being symmetric, is linear phase) that is the "center" of the effects of a single impulse. So, it's the center between you seeing the first effect of your input change, and the last effect.

If your window is realizable (causal, and it has to be as we cannot measure and use future values) you have to wait for whole window not the half of it.

• but the group delay is half the window width. – robert bristow-johnson Aug 2 '17 at 19:14
• Is my delay the full window size M or M-1? I think it's M-1. – ce_guy Aug 10 '17 at 14:27
• It is M-1, thinking the extremes may help time to time. Consider your filter being a dirac delta function (A window of size 1), it causes no delay. – keoxkeox Aug 15 '17 at 21:01

Here's another way to look at it:

group delay (what non-dsp people call "lag") is also the center of gravity (COG) of the weights of the average. For a Simple Moving Average (SMA), those weights look like a rectangle (length M, height 1/M), so the COG of the SMA is in the middle: that's why a 10-period SMA will have a 5 period lag. Another possible moving average would be the Weighted Moving Average: there the weights look like a right triangle (length M, height M/sum(1:M) ). The horizontal coordinate of the COG of a triangle is at 2/3rd the base, so the lag (group delay) of a WMA is 1/3 the length of the window it's calculated on.