mirror of
https://github.com/romanz/amodem.git
synced 2026-02-08 10:28:00 +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))
|
||||
if len(data) < len(sig_dump):
|
||||
return
|
||||
_, x = common.loads(data)
|
||||
x = common.loads(data)
|
||||
x = x - np.mean(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)
|
||||
|
||||
|
||||
def load(fileobj):
|
||||
return loads(fileobj.read())
|
||||
def load(fileobj, time=False):
|
||||
return loads(fileobj.read(), time=time)
|
||||
|
||||
|
||||
def loads(data):
|
||||
def loads(data, time=False):
|
||||
x = np.fromstring(data, dtype='int16')
|
||||
x = x / scaling
|
||||
t = np.arange(len(x)) / Fs
|
||||
return t, x
|
||||
if np.max(np.abs(x)) > SATURATION_THRESHOLD:
|
||||
raise ValueError('saturation')
|
||||
|
||||
if time:
|
||||
t = np.arange(len(x)) / Fs
|
||||
return t, x
|
||||
else:
|
||||
return x
|
||||
|
||||
|
||||
def dumps(sym, n=1):
|
||||
|
||||
@@ -72,7 +72,7 @@ if __name__ == '__main__':
|
||||
df, = sys.argv[1:]
|
||||
df = float(df)
|
||||
|
||||
_, x = common.load(sys.stdin)
|
||||
x = common.load(sys.stdin)
|
||||
sampler = Sampler(x, Interpolator())
|
||||
sampler.freq += df
|
||||
y = np.array(list(sampler))
|
||||
|
||||
2
show.py
2
show.py
@@ -29,7 +29,7 @@ if __name__ == '__main__':
|
||||
import common
|
||||
|
||||
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.title(fname)
|
||||
spectrogram(t, x, common.Fs)
|
||||
|
||||
Reference in New Issue
Block a user