Algorithms for extracting moving average intervals I have a series of discrete events and a global clock.
Whenever an event happens, I record a timestamp and do some processing.  Specifically, I am trying to compute "moving average" (not really) statistics on how fast events are being received.  I need to do this online – as events are being entered into the system.
I can only perform processing in response to an event.
The algorithm needs to be simple and numerically stable, as I will be implementing it by hand in C++ using double-precision floating-point arithmetic.  I don't need absolute accuracy, but I do need long-term stability over the course of many events.  In particular, I need the impact of old data points to go to zero as their age goes to infinity.
Performance is also rather important, since this processing happens in a critical section, and some of the event sources are latency critical (such as JVM safepoint requests).  However, I suspect that any reasonably simple algorithm will be fast enough – we are talking tens or at most hundreds of events per second on average, and 1μs or even 10μs latency is perfectly okay.
 A: When this is done electronically it is usually done with an RC (resistance/capacitance) circuit e.g., see link. The circuit shown in that link is not what you want, rather you want the resistor in parallel with the capacitor so that the charging is immediate and the decay gradual. That is, events load charge into a capacitor, which is then slowly drained by a resistor. The resistance is usually selectable to adjust for time scales. Or, if you wish, a running cumulative impulse response to Dirac deltas, see math for a single impulse.
If you want to do this numerically, you can use exponential decay of the signal in time to make this running average. Exponential functions are memoryless, or if you wish, and in draining a load, they enforce forgetfulness. So, what you do with each count equal to 1 occurring at times $t$ is, calibrate (scale) them ($s$) and accumulate decay (half-life $\tau$) by applying $s \sum _{i=1}^n e^{-\frac{\log (2) t}{\tau }}$. Here is an example for 5 events. 
$\left(n=5;\tau =1;s=2;t=\{0.2,0.3,0.8,1.2,1.5,1.9\}\right); \text{Plot}\left[s \left(
\begin{array}{cc}
 \{ & 
\begin{array}{cc}
 0 & x<t[[1]] \\
 e^{-\frac{\log (2) x}{\tau }} & x<t[[2]] \\
 \sum _{i=1}^2 e^{-\frac{\log (2) x}{\tau }} & x<t[[3]] \\
 \sum _{i=1}^3 e^{-\frac{\log (2) x}{\tau }} & x<t[[4]] \\
 \sum _{i=1}^4 e^{-\frac{\log (2) x}{\tau }} & x<t[[5]] \\
 \sum _{i=1}^5 e^{-\frac{\log (2) x}{\tau }} & x>t[[5]] \\
\end{array}
 \\
\end{array}
\right),\{x,0,2\},\text{AxesOrigin}\to \{0,0\}\right]$

Just one word of caution, in general that may be $s=\frac{\ln{2}}{\tau}$, (see here) implying that if you want counts per second from $s$, you would set the half-life $\tau=\ln{2}$ (seconds), but please check this scale factor against actual data. 
