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.