If you are happy with an exponentially-filtered estimate of the RMS of the AC component of a signal - more or less what an old analogue RMS-reading meter would indicate - and your data points are sampled at constant intervals, you can use a fast recursive algorithm to calculate the exponentially-weighted mean (DC level) and variance (square of the AC RMS value), sample by sample:
diff := x - mean
incr := alpha * diff
mean := mean + incr
variance := (1 - alpha) * (variance + diff * incr)
To start up, set the value of
mean to the first sample value
x, and set the value of
variance to zero, then iterate starting from the second sample. Constant
alpha (0 <
alpha < 1) sets the 'time constant' of the filter; variables
diff and
incr are used for temporary storage. Take the square root of
variance if and when you need the actual RMS value.
Source:
https://fanf2.user.srcf.net/hermes/doc/antiforgery/stats.pdfImplementation using fixed-point arithmetic is left as an excercise for the reader
