In pandas, there are several methods to manipulate data in a given window (e.g. pd.rolling_mean
or pd.rolling_std
.) However, I would like to set a
I am not familiar with pandas, but in numpy you would do it something like this (untested):
def overlapped_windows(x, nwin, noverlap = None):
if noverlap is None:
noverlap = nwin // 2
step = nwin - noverlap
for i in range(0, len(x) - nwin + 1, step):
window = x[i:i+nwin] #this is a view, not a copy
y = window * hann(nwin)
#your code here with y
This is ripped from some old code to calculate an averaged PSD, which you typically process with half-overlapping windows. Note that window
is a 'view' into array x, which means it does not do any copying of data (very fast, so probably good) and that if you modify window
you also modify x
(so dont do window = hann * window
).