diff --git a/drift.py b/drift.py index 27e562a..d3a919e 100644 --- a/drift.py +++ b/drift.py @@ -13,9 +13,9 @@ def main(): S = [] Y = [] - symbols = loop.FreqLoop(x, f0) prefix = 100 - for s in symbols: + symbols = loop.FreqLoop(x, [f0]) + for s, in symbols: S.append(s) if len(S) > prefix: symbols.correct(s, np.mean(S[:prefix])) diff --git a/loop.py b/loop.py index c3444a2..1d11728 100644 --- a/loop.py +++ b/loop.py @@ -1,4 +1,5 @@ import numpy as np +import itertools import recv import sampling @@ -20,9 +21,14 @@ class Filter(object): return y class FreqLoop(object): - def __init__(self, x, freq): + def __init__(self, x, freqs): self.sampler = sampling.Sampler(x, sampling.Interpolator()) - self.symbols = recv.extract_symbols(self.sampler, freq) + self.gens = [] + + gens = itertools.tee(self.sampler, len(freqs)) + for freq, gen in zip(freqs, gens): + self.gens.append( recv.extract_symbols(self.sampler, freq) ) + Kp, Ki = 0.2, 0.01 b = np.array([1, -1])*Kp + np.array([0.5, 0.5])*Ki self.filt = Filter(b=b, a=[1]) @@ -35,4 +41,4 @@ class FreqLoop(object): self.sampler.correct(offset=self.correction) def __iter__(self): - return iter(self.symbols) + return itertools.izip(*self.gens)