-
Notifications
You must be signed in to change notification settings - Fork 116
/
loop.py
37 lines (29 loc) · 948 Bytes
/
loop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import numpy as np
import itertools
from . import sampling
from . import sigproc
from . import common
class Filter(object):
def __init__(self, b, a=()):
self.b = b
self.a = a
self.x = [0] * len(b)
self.y = [0] * len(a)
def __call__(self, x):
self.x = [x] + self.x
self.x = self.x[:len(self.b)]
self.y = self.y[:len(self.a)]
y = np.dot(self.x, self.b) + np.dot(self.y, self.a)
self.y = [y] + self.y
return y
class FreqLoop(object):
def __init__(self, src, freqs):
interp = sampling.Interpolator()
self.sampler = sampling.Sampler(src, interp)
self.gens = []
samplers = itertools.tee(self.sampler, len(freqs))
for freq, generator in zip(freqs, samplers):
gen = sigproc.extract_symbols(generator, freq)
self.gens.append(gen)
def __iter__(self):
return common.izip(*self.gens)