Skip to content
Snippets Groups Projects
Commit 196faad3 authored by Chad Hanna's avatar Chad Hanna
Browse files

cbc_template_fir: moving_median speed improvement

parent d18d8591
No related branches found
No related tags found
No related merge requests found
Pipeline #54497 passed with warnings
......@@ -199,9 +199,27 @@ def compute_autocorrelation_mask( autocorrelation ):
def movingmedian(interval, window_size):
interval = list(interval)
import bisect
tmp = numpy.copy(interval)
A = None
As = None
prev = None
for i in range(window_size, len(interval)-window_size):
tmp[i] = numpy.median(interval[i-window_size:i+window_size])
if A is None:
A = interval[i-window_size:i+window_size]
ix = numpy.argsort(A)
As = list(numpy.array(A)[ix])
else:
newdata = interval[i+window_size-1]
A = A + [newdata]
bisect.insort(As, newdata)
if len(As) % 2:
tmp[i] = As[len(As)/2]
else:
tmp[i] = (As[len(As)/2-1] + As[len(As)/2]) / 2.
prev = A.pop(0)
del As[bisect.bisect_left(As, prev)]
return tmp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment