def _band_filter(size, dt, fc1, fc2): lpf_low = Filter.low_pass_filter(size, dt, fc1).y lpf_up = Filter.low_pass_filter(size, dt, fc2).y for i in range(2 * size + 1): if i == size: lpf_low[i] = 1 + lpf_low[i] - lpf_up[i] else: lpf_low[i] = lpf_low[i] - lpf_up[i] return Sequence.from_func(range(2 * size + 1), lambda x: lpf_low[x])
def gist(seq, intervals=10): from collections import defaultdict res = defaultdict(int) mi = min(seq.y) ma = max(seq.y) size = (ma - mi) / intervals for y in seq.y: idx = (y - mi) // size res[idx] += 1 return Sequence.from_func(range(intervals), lambda x: res[x])
def high_pass_filter(size, dt, fc): lpf = Filter.low_pass_filter(size, dt, fc) lpw = lpf.y hpf = [] for i in range(2 * size + 1): if i == size: hpf.append(1 - lpw[i]) else: hpf.append(-lpw[i]) return Sequence.from_func(range(2 * size + 1), lambda x: hpf[x])
def idft(complex_pairs): res = [] n = len(complex_pairs) for k in range(n): sum = 0 for t in range(n): angle = (2 * math.pi * k * t) / n sum += complex_pairs[t][0] * math.cos( angle) + complex_pairs[t][1] * math.sin(angle) res.append(sum) return Sequence.from_func(range(n), lambda x: res[x])
def convolution(first, second): one = first.y two = second.y n = len(first) m = len(second) conv = [] for i in range(n): if i in range(n + m): res = 0 for j in range(m): if (i - j) in range(0, n): res += one[i - j] * two[j] conv.append(res) else: conv.append(0) return Sequence.from_func(range(n), lambda x: conv[x])
def convolve(a, v): c = np.convolve(a.y, v.y) return Sequence.from_func(range(len(v), len(a)), lambda x: c[x])
def low_pass_filter(size, dt, fc): half = Filter._half_filter(size, dt, fc) result = [*list(reversed(half)), *half[1:]] return Sequence.from_func(range(2 * size + 1), lambda x: result[x])
def delta(dots, interval): return Sequence.from_func(range(dots), lambda x: 1 if x % interval == 0 else 0)
def base(dots, freq, dt, relaxation): mult = 2 * math.pi * freq * dt return Sequence.from_func( range(dots), lambda x: math.sin(mult * x) * math.exp(-relaxation * dt * x))