mirror of
https://github.com/romanz/amodem.git
synced 2026-04-21 05:36:42 +08:00
common.loads() should return time only if asked to
This commit is contained in:
2
calib.py
2
calib.py
@@ -25,7 +25,7 @@ def recv():
|
|||||||
data = out.read(len(sig_dump))
|
data = out.read(len(sig_dump))
|
||||||
if len(data) < len(sig_dump):
|
if len(data) < len(sig_dump):
|
||||||
return
|
return
|
||||||
_, x = common.loads(data)
|
x = common.loads(data)
|
||||||
x = x - np.mean(x)
|
x = x - np.mean(x)
|
||||||
|
|
||||||
c = np.abs(np.dot(x, sig)) / (np.sqrt(0.5 * len(x)) * sigproc.norm(x))
|
c = np.abs(np.dot(x, sig)) / (np.sqrt(0.5 * len(x)) * sigproc.norm(x))
|
||||||
|
|||||||
16
common.py
16
common.py
@@ -42,15 +42,21 @@ def to_byte(bits):
|
|||||||
return chr(byte)
|
return chr(byte)
|
||||||
|
|
||||||
|
|
||||||
def load(fileobj):
|
def load(fileobj, time=False):
|
||||||
return loads(fileobj.read())
|
return loads(fileobj.read(), time=time)
|
||||||
|
|
||||||
|
|
||||||
def loads(data):
|
def loads(data, time=False):
|
||||||
x = np.fromstring(data, dtype='int16')
|
x = np.fromstring(data, dtype='int16')
|
||||||
x = x / scaling
|
x = x / scaling
|
||||||
t = np.arange(len(x)) / Fs
|
if np.max(np.abs(x)) > SATURATION_THRESHOLD:
|
||||||
return t, x
|
raise ValueError('saturation')
|
||||||
|
|
||||||
|
if time:
|
||||||
|
t = np.arange(len(x)) / Fs
|
||||||
|
return t, x
|
||||||
|
else:
|
||||||
|
return x
|
||||||
|
|
||||||
|
|
||||||
def dumps(sym, n=1):
|
def dumps(sym, n=1):
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ if __name__ == '__main__':
|
|||||||
df, = sys.argv[1:]
|
df, = sys.argv[1:]
|
||||||
df = float(df)
|
df = float(df)
|
||||||
|
|
||||||
_, x = common.load(sys.stdin)
|
x = common.load(sys.stdin)
|
||||||
sampler = Sampler(x, Interpolator())
|
sampler = Sampler(x, Interpolator())
|
||||||
sampler.freq += df
|
sampler.freq += df
|
||||||
y = np.array(list(sampler))
|
y = np.array(list(sampler))
|
||||||
|
|||||||
2
show.py
2
show.py
@@ -29,7 +29,7 @@ if __name__ == '__main__':
|
|||||||
import common
|
import common
|
||||||
|
|
||||||
for fname in sys.argv[1:]:
|
for fname in sys.argv[1:]:
|
||||||
t, x = common.load(open(fname, 'rb'))
|
t, x = common.load(open(fname, 'rb'), time=True)
|
||||||
pylab.figure()
|
pylab.figure()
|
||||||
pylab.title(fname)
|
pylab.title(fname)
|
||||||
spectrogram(t, x, common.Fs)
|
spectrogram(t, x, common.Fs)
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ class Reader(object):
|
|||||||
if data:
|
if data:
|
||||||
block.extend(data)
|
block.extend(data)
|
||||||
if len(block) == self.BUFSIZE:
|
if len(block) == self.BUFSIZE:
|
||||||
_, values = common.loads(str(block))
|
return common.loads(str(block))
|
||||||
return values
|
|
||||||
|
|
||||||
time.sleep(self.WAIT)
|
time.sleep(self.WAIT)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user