x is the timeseries.
m is the window length.
v is the variance.
Aslak Grinsted 2005
I believe n2 and m2 are the wrong way round: the longer sequence to remove is at the end not the start (try with a constant vector e.g. ones(1000,1)).
Also v can end up with a small negative value, which is not good for a variance. So I suggest:
Excellent, does just what I needed, without using a loop. NB/ this is the biased variance.