skip initial spikes

This commit is contained in:
Roman Zeyde
2014-07-21 13:58:35 +03:00
parent 871ec8bb46
commit 194a967cc3
3 changed files with 21 additions and 16 deletions

View File

@@ -46,6 +46,12 @@ class SaturationError(ValueError):
pass
def check_saturation(x):
peak = np.max(np.abs(x))
if peak > SATURATION_THRESHOLD:
raise SaturationError(peak)
def load(fileobj, time=False):
return loads(fileobj.read(), time=time)
@@ -53,10 +59,6 @@ def load(fileobj, time=False):
def loads(data, time=False):
x = np.fromstring(data, dtype='int16')
x = x / scaling
peak = np.max(np.abs(x))
if peak > SATURATION_THRESHOLD:
raise SaturationError(peak)
if time:
t = np.arange(len(x)) / Fs
return t, x
@@ -121,6 +123,10 @@ def icapture(iterable, result):
result.append(i)
yield i
def take(iterable, n):
return np.array(list(itertools.islice(iterable, n)))
if __name__ == '__main__':
import pylab

16
recv.py
View File

@@ -85,11 +85,6 @@ def find_start(buf, length):
return np.argmax(cumsumP[length:] - cumsumP[:-length])
def take(symbols, n):
symbols = itertools.islice(symbols, n)
return np.array(list(symbols))
def receive_prefix(symbols):
S = take(symbols, len(train.prefix))[:, carrier_index]
sliced = np.round(S)
@@ -228,14 +223,13 @@ def main(fname):
log.info('Running MODEM @ {:.1f} kbps'.format(sigproc.modem_bps / 1e3))
fd = sys.stdin if (fname == '-') else open(fname, 'rb')
samples = stream.iread(fd)
result = detect(samples, Fc)
if result is None:
log.warning('No carrier detected')
return
signal = stream.iread(fd)
take(signal, 100) # skip initial 0.1 second, due to spurious spikes
stream.check = check_saturation
size = 0
bits = receive(result, frequencies)
signal = detect(signal, Fc)
bits = receive(signal, frequencies)
try:
for chunk in decode(bits):
sys.stdout.write(chunk)

View File

@@ -14,6 +14,7 @@ class Reader(object):
def __init__(self, fd):
self.fd = fd
self.check = None
def __iter__(self):
return self
@@ -26,8 +27,12 @@ class Reader(object):
data = self.fd.read(left)
if data:
block.extend(data)
if len(block) == self.BUFSIZE:
return common.loads(str(block))
values = common.loads(str(block))
if self.check:
self.check(values)
return values
time.sleep(self.WAIT)