mirror of
https://github.com/romanz/amodem.git
synced 2026-04-21 22:06:27 +08:00
move stats handling to main
This commit is contained in:
39
recv.py
39
recv.py
@@ -111,6 +111,9 @@ def train_receiver(symbols, freqs):
|
|||||||
return filters
|
return filters
|
||||||
|
|
||||||
|
|
||||||
|
stats = {}
|
||||||
|
|
||||||
|
|
||||||
def demodulate(symbols, filters, freqs):
|
def demodulate(symbols, filters, freqs):
|
||||||
streams = []
|
streams = []
|
||||||
symbol_list = []
|
symbol_list = []
|
||||||
@@ -133,26 +136,15 @@ def demodulate(symbols, filters, freqs):
|
|||||||
bits = sigproc.modulator.decode(S, freq_handler) # list of bit tuples
|
bits = sigproc.modulator.decode(S, freq_handler) # list of bit tuples
|
||||||
streams.append(bits) # stream per frequency
|
streams.append(bits) # stream per frequency
|
||||||
|
|
||||||
|
stats['symbol_list'] = symbol_list
|
||||||
|
stats['rx_bits'] = 0
|
||||||
|
stats['rx_start'] = time.time()
|
||||||
|
|
||||||
log.info('Demodulation started')
|
log.info('Demodulation started')
|
||||||
decoded_bits = 0
|
|
||||||
start = time.time()
|
|
||||||
for block in itertools.izip(*streams): # block per frequency
|
for block in itertools.izip(*streams): # block per frequency
|
||||||
for bits in block:
|
for bits in block:
|
||||||
|
stats['rx_bits'] = stats['rx_bits'] + len(bits)
|
||||||
yield bits
|
yield bits
|
||||||
decoded_bits = decoded_bits + len(bits)
|
|
||||||
|
|
||||||
# TODO: make this run even after EOF
|
|
||||||
duration = time.time() - start
|
|
||||||
audio_time = decoded_bits / sigproc.modem_bps
|
|
||||||
log.info('Demodulated %.3f kB @ %.3f seconds = %.1f%% realtime',
|
|
||||||
decoded_bits / 8e3, duration, 100 * duration / audio_time)
|
|
||||||
|
|
||||||
if pylab:
|
|
||||||
pylab.figure()
|
|
||||||
symbol_list = np.array(symbol_list)
|
|
||||||
for i, freq in enumerate(freqs):
|
|
||||||
pylab.subplot(HEIGHT, WIDTH, i+1)
|
|
||||||
show.constellation(symbol_list[i], '$F_c = {} Hz$'.format(freq))
|
|
||||||
|
|
||||||
|
|
||||||
def receive(signal, freqs):
|
def receive(signal, freqs):
|
||||||
@@ -180,8 +172,7 @@ def decode(bits_iterator):
|
|||||||
break
|
break
|
||||||
yield bytearray(block.tobytes())
|
yield bytearray(block.tobytes())
|
||||||
|
|
||||||
data = ecc.decode(blocks())
|
return ecc.decode(blocks())
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def main(fname):
|
def main(fname):
|
||||||
@@ -218,6 +209,18 @@ def main(fname):
|
|||||||
|
|
||||||
log.info('Decoded %.3f kB', size / 1e3)
|
log.info('Decoded %.3f kB', size / 1e3)
|
||||||
|
|
||||||
|
duration = time.time() - stats['rx_start']
|
||||||
|
audio_time = stats['rx_bits'] / sigproc.modem_bps
|
||||||
|
log.info('Demodulated %.3f kB @ %.3f seconds = %.1f%% realtime',
|
||||||
|
stats['rx_bits'] / 8e3, duration, 100 * duration / audio_time)
|
||||||
|
|
||||||
|
if pylab:
|
||||||
|
pylab.figure()
|
||||||
|
symbol_list = np.array(symbol_list)
|
||||||
|
for i, freq in enumerate(freqs):
|
||||||
|
pylab.subplot(HEIGHT, WIDTH, i+1)
|
||||||
|
show.constellation(symbol_list[i], '$F_c = {} Hz$'.format(freq))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(level=logging.INFO,
|
logging.basicConfig(level=logging.INFO,
|
||||||
format='%(asctime)s %(levelname)-12s %(message)s')
|
format='%(asctime)s %(levelname)-12s %(message)s')
|
||||||
|
|||||||
Reference in New Issue
Block a user