mirror of
https://github.com/romanz/amodem.git
synced 2026-03-17 07:05:59 +08:00
calibration: handle KeyboardInterrupt
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
killall -q aplay arecord
|
||||
./calib.py send &
|
||||
SENDER_PID=$!
|
||||
./calib.py recv
|
||||
killall -q aplay arecord
|
||||
|
||||
kill -INT $SENDER_PID
|
||||
|
||||
56
calib.py
56
calib.py
@@ -12,35 +12,39 @@ sig_dump = common.dumps(sig)
|
||||
|
||||
|
||||
def send():
|
||||
p = wave.play('-', stdin=wave.sp.PIPE)
|
||||
while True:
|
||||
try:
|
||||
p.stdin.write(sig_dump)
|
||||
except IOError:
|
||||
return
|
||||
|
||||
p = wave.play('-', stdin=wave.sp.PIPE, stderr=open('/dev/null'))
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
p.stdin.write(sig_dump)
|
||||
except IOError:
|
||||
return
|
||||
except KeyboardInterrupt:
|
||||
p.kill()
|
||||
|
||||
def recv():
|
||||
out = wave.record('-', stdout=wave.sp.PIPE).stdout
|
||||
while True:
|
||||
data = out.read(len(sig_dump))
|
||||
if len(data) < len(sig_dump):
|
||||
return
|
||||
try:
|
||||
x = common.loads(data)
|
||||
except common.SaturationError as e:
|
||||
print('saturation: {}'.format(e))
|
||||
continue
|
||||
x = x - np.mean(x)
|
||||
|
||||
c = np.abs(np.dot(x, sig)) / (np.sqrt(0.5 * len(x)) * sigproc.norm(x))
|
||||
z = np.dot(x, sig.conj()) / (0.5 * len(x))
|
||||
amp = np.abs(z)
|
||||
phase = np.angle(z)
|
||||
peak = np.max(np.abs(x))
|
||||
print('coherence={:.3f} amp={:.3f} phase={:.1f} peak={:.3f}'.format(
|
||||
c, amp, phase * 180 / np.pi, peak))
|
||||
p = wave.record('-', stdout=wave.sp.PIPE)
|
||||
try:
|
||||
while True:
|
||||
data = p.stdout.read(len(sig_dump))
|
||||
if len(data) < len(sig_dump):
|
||||
return
|
||||
try:
|
||||
x = common.loads(data)
|
||||
except common.SaturationError as e:
|
||||
print('saturation: {}'.format(e))
|
||||
continue
|
||||
x = x - np.mean(x)
|
||||
|
||||
c = np.abs(np.dot(x, sig)) / (np.sqrt(0.5 * len(x)) * sigproc.norm(x))
|
||||
z = np.dot(x, sig.conj()) / (0.5 * len(x))
|
||||
amp = np.abs(z)
|
||||
phase = np.angle(z)
|
||||
peak = np.max(np.abs(x))
|
||||
print('coherence={:.3f} amp={:.3f} phase={:.1f} peak={:.3f}'.format(
|
||||
c, amp, phase * 180 / np.pi, peak))
|
||||
except KeyboardInterrupt:
|
||||
p.kill()
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
|
||||
Reference in New Issue
Block a user