# 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?

• You can't do this without some information other than the average so far Related (from a search for running weighted average): stackoverflow.com/questions/9915653/… Jun 12, 2017 at 13:29
• are you asking how to find incremental averages? Jun 12, 2017 at 13:29
• Incremental averages was what I was looking for, I didn't know what it was called. Thank you. Jun 12, 2017 at 13:42
• 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. Jun 13, 2017 at 13:15