# Trouble with understanding moving average filter as an oversampling filter

I am struggling with understanding how an moving average filter can increase ENOB in a given sample.

I wrote a test for a simple MA (moving average) filter in matlab. The algorithm to create new MA value simply subtracts the new signal value from and old one (that is $$n$$ samples away), and adds the previous value of the filter to it. I run the fft and it seems to work as low pass filter - exactly how expected.

I am aware that this same algorithm can be used to increase number of bits of resolution for a sample. Furthermore, if the old value that we used to build the difference with the new value is $$n$$ sample away, then the filter value is supposed to have the resolution increased by $$n$$ bits.... I just don't really understand how is that possible. To my understanding:

1. we take the old filter value ($$m$$ bit long),
2. we add a new value to it that is a difference of the current signal value and a past signal value, that is $$n$$ samples away - both values also $$m$$ bit long,
3. how is it possible that resulting filter value could be now $$m+n$$ bit long?

Lets say we have 12 bit($$m$$) signal values. How is it possible to 'gain' additonal 6 bits($$n$$) bits by adding the signal value that is 6 samples away from the current sample? Why should the outcome have the resolution of 18 bits?

• I think you may still be confused if you believe that you gain 6 bits with a moving average over 6 bits. See my answer below to see if that helps! – Dan Boschen Feb 17 '20 at 17:57

A moving average over 6 samples will not add 6 bits of precision to the ENOB (equivalent number of bits) as stated in the question. In general, a moving average over $$N$$ samples will increase resolution by $$log2(N)/2$$, and for 6 samples this would be approximately 1.3 bits.

This approximation holds to the extent that the quantization noise on each sample is represented by a uniformly distributed white noise process (which holds well when there are a sufficient number of quantization levels and the sampling clock is not correlated to the signal being sampled). From statistics, when you add N independent random variables, the standard deviation increases at $$\sqrt{N}$$. Thus in the average where we also divide that sum by $$N$$ the standard deviation is scaled by $$\sqrt{N}/N = 1/\sqrt{N}$$.

This results in a 3 dB reduction in quantization noise for every doubling of samples in the average (from $$20Log_{10}(1/N)$$ since dB is $$20Log_{10}(\sigma)$$ where $$\sigma$$ is the standard deviation. As already detailed in the post linked below, each bit of precision represents a 6 dB reduction in quantization noise:

What are advantages of having higher sampling rate of a signal?

A moving average over 4 samples would add 1 bit of precision, 16 samples would add 2 bits, etc.

To support the increased number of bits, the result from the addition of the samples must have that many number of bits which is also apparent to eliminate overflow conditions. Filtering a digital signal (which a moving average is) grows the signal! This is why we must use extended precision accumulators when filtering. We can scale the accumulated signal back after summing (for the average) while scaling the signal first prior to the summation, or equivalently scaling the coefficients, would result in further noise contribution.

• thanks! your answer helped me a lot! – user7216373 Feb 18 '20 at 9:18
• one quick question though: if i have a MA filter that outputs a value $n$ bits longer than the input value, does this mean that this filter is equivalent to $4^n$ oversampling factor? – user7216373 Feb 20 '20 at 13:27
• It’s not really clear what you are asking as a moving average filter will output a new value on every update of the sampling clock. – Dan Boschen Feb 20 '20 at 13:59
• yes, exactly. Assuming that the algorithm I'm using is as described above ('new_MA_val = signal_in - singal_nTaps_away + new_MA_val') it gives me a value that is in $n$ bit larger that signal_in value, with $n$ being also the number of taps of this filter. Does it mean, that this kind of filtering is equivalent to $4^n$ oversampling factor? (there is no division in this algorithm, and this is what confuses me a bit). – user7216373 Feb 20 '20 at 14:17
• Then it is a moving avg filter and that is the result you would expect—- there need not be a division as that is just a scaling. Scaling the signal and the noise by the same amount does not change the SNR – Dan Boschen Feb 20 '20 at 14:20