# Difference between the average operation and the application of the equivalent LPF

I would be glad if someone could answer my question. I have a bit stream of data and I want to extract the low frequency component. When post processing the data I can calculate the average value over a certain number of samples with the MATLAB operation mean(data(1:N))

Then I tired to build the equivalent LPF of this operation:

$$V_o(k) = \frac 1N \big[V_i(k-1) + V_i(k-2) + \ldots + V_i(k-N)\big]$$

Plotted the equivalent filter transfer function: freqz(ones(1,N),N,1e3).

And it looks like a sort of first order LPF. Now if I filter the data I don't get the same results of the average operation, filter(ones(1,N),N,data).

So what am I missing? The purpose of this investigation is to look for a better filter that will be implemented on FPGA to do real time processing.

You are missing $$1/N$$ factor in your filter if you want to do a moving average.
Moreover, FIR filter has a group delay of $$\frac{N-1}{2}$$. So if N is odd the value of mean(data(1:N)) should be at the $$\frac{N-1}{2}$$ sample of the filter output