/ concept-collection / timeseries-entropy
Sign in
concept-collection / timeseries-entropy
33 lines · 874 BBlameHistoryRaw
1"""Kernel constructors matching timeseries-compressibility's filters."""
3import numpy as np
6def identity():
7 return np.array([1.0])
10def moving_average(width):
11 return np.full(width, 1.0 / width)
14def first_difference():
15 return np.array([1.0, -1.0])
18def windowed_sinc_lowpass(fc, taps):
19 """Hamming-windowed sinc, cutoff fc in cycles/sample, unit DC gain."""
20 n = taps | 1
21 mid = (n - 1) / 2
22 i = np.arange(n)
23 t = i - mid
24 sinc = np.where(t == 0, 2 * fc,
25 np.sin(2 * np.pi * fc * t) / (np.pi * np.where(t == 0, 1, t)))
26 w = 0.54 - 0.46 * np.cos(2 * np.pi * i / (n - 1))
27 h = sinc * w
28 return h / h.sum()
31def windowed_sinc_bandpass(f_lo, f_hi, taps):
32 """Difference of two windowed-sinc lowpasses; edges in cycles/sample."""
33 return windowed_sinc_lowpass(f_hi, taps) - windowed_sinc_lowpass(f_lo, taps)
moveopenescclose