detect: find actual starting offset of the carrier

This commit is contained in:
Roman Zeyde
2015-02-16 19:11:19 +02:00
parent b3619a75ba
commit 90dd3e55f0
2 changed files with 21 additions and 11 deletions

View File

@@ -66,7 +66,7 @@ class Detector(object):
bufs.append(np.array(trailing))
buf = np.concatenate(bufs)
offset = self.find_start(buf, duration=self.CARRIER_DURATION)
offset = self.find_start(buf)
start_time += (offset / self.Nsym - self.SEARCH_WINDOW) * self.Tsym
log.debug('Carrier starts at %.3f ms', start_time * 1e3)
@@ -76,14 +76,24 @@ class Detector(object):
amplitude, freq_err = self.estimate(buf[:prefix_length])
return itertools.chain(buf, samples), amplitude, freq_err
def find_start(self, buf, duration):
filt = dsp.FIR(dsp.exp_iwt(self.omega, self.Nsym))
p = np.abs(list(filt(buf))) ** 2
p = np.cumsum(p)[self.Nsym-1:]
p = np.concatenate([[0], p])
length = (duration - 1) * self.Nsym
correlations = np.abs(p[length:] - p[:-length])
offset = np.argmax(correlations)
def find_start(self, buf):
carrier = dsp.exp_iwt(self.omega, self.Nsym)
carrier = np.tile(carrier, self.SEARCH_WINDOW // 4)
zeroes = carrier * 0.0
signal = np.concatenate([zeroes, carrier])
signal = (2 ** 0.5) * signal / dsp.norm(signal)
coeffs = []
for i in range(len(buf) - len(signal)):
b = buf[i:i+len(signal)]
c = 0.0
if dsp.norm(b):
c = np.abs(np.dot(b, signal)) / dsp.norm(b)
coeffs.append(c)
index = np.argmax(coeffs)
log.debug('Starting coherence: %.3f%%', coeffs[index] * 100)
offset = index + len(zeroes)
return offset
def estimate(self, buf, skip=5):

View File

@@ -19,7 +19,7 @@ def test_detect():
detector = detect.Detector(config, pylab=common.Dummy())
samples, amp, freq_err = detector.run(x)
assert abs(1 - amp) < 1e-12
assert abs(freq_err) < 1e-16
assert abs(freq_err) < 1e-12
x = np.cos(2 * np.pi * (2*config.Fc) * t)
with pytest.raises(ValueError):
@@ -56,6 +56,6 @@ def test_find_start():
for offset in range(32):
bufs = [prefix, [0] * offset, carrier, postfix]
buf = np.concatenate(bufs)
start = detector.find_start(buf, length)
start = detector.find_start(buf)
expected = offset + len(prefix)
assert expected == start