# Averaging as samples come in [duplicate]

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?

## marked as duplicate by Namaste, Leucippus, Claude Leibovici, hardmath, user91500Jun 13 '17 at 14:37

• Note that the first expression ("If I know the number of samples") has a sum of $n+1$ terms in the numerator but divides by $n$ in the denominator. – hardmath Jun 13 '17 at 13:15