Averaging as samples come in

106 Views Asked by At

I feel like this is a lot easier than I'm making it, but for some reason I just can't wrap my head around it.

Let's say I'm sampling a voltage, for argument's sake. I want to know the average voltage over a period of time. If I know the number of samples - it's simply:

$$\frac{\sum_0^n s_n}{n}$$

But, what if I'm trying to do it live? It becomes:

$$\frac{1}{T}\int_0^T s(x) dx$$

But in that case, since $T$ is changing, the first sample will be weighted most heavily, with weight decreasing over time.

Is there an easy way to get the average when I don't know how many samples I have ($n$ or $T$ in this case)? What if the number of samples is significantly large?