mirror of
https://github.com/romanz/amodem.git
synced 2026-05-09 13:07:39 +08:00
PEP8 fixes
This commit is contained in:
@@ -4,6 +4,7 @@ import functools
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ALSA(object):
|
class ALSA(object):
|
||||||
def __init__(self, tool, Fs):
|
def __init__(self, tool, Fs):
|
||||||
self.Fs = int(Fs) # sampling rate
|
self.Fs = int(Fs) # sampling rate
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ def run_recorder(config, recorder):
|
|||||||
fmt = '{freq:6.0f} Hz: {message:s}{extra:s}'
|
fmt = '{freq:6.0f} Hz: {message:s}{extra:s}'
|
||||||
fields = ['peak', 'total', 'rms', 'coherency']
|
fields = ['peak', 'total', 'rms', 'coherency']
|
||||||
|
|
||||||
|
|
||||||
def recv(config, audio_record=audio.record, verbose=False):
|
def recv(config, audio_record=audio.record, verbose=False):
|
||||||
extra = ''
|
extra = ''
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ class Configuration(object):
|
|||||||
# QAM constellation
|
# QAM constellation
|
||||||
Nx = 2 ** int(np.ceil(bits_per_symbol / 2))
|
Nx = 2 ** int(np.ceil(bits_per_symbol / 2))
|
||||||
Ny = self.Npoints // Nx
|
Ny = self.Npoints // Nx
|
||||||
symbols = np.array([complex(x, y) for x in range(Nx) for y in range(Ny)])
|
symbols = [complex(x, y) for x in range(Nx) for y in range(Ny)]
|
||||||
|
symbols = np.array(symbols)
|
||||||
symbols = symbols - symbols[-1]/2
|
symbols = symbols - symbols[-1]/2
|
||||||
self.symbols = symbols / np.max(np.abs(symbols))
|
self.symbols = symbols / np.max(np.abs(symbols))
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class MODEM(object):
|
|||||||
self.symbols = symbols
|
self.symbols = symbols
|
||||||
self.bits_per_symbol = bits_per_symbol
|
self.bits_per_symbol = bits_per_symbol
|
||||||
|
|
||||||
bits_map = dict((symbol, bits) for bits, symbol in self.encode_map.items())
|
bits_map = dict(item[::-1] for item in self.encode_map.items())
|
||||||
self.decode_list = [(s, bits_map[s]) for s in self.symbols]
|
self.decode_list = [(s, bits_map[s]) for s in self.symbols]
|
||||||
|
|
||||||
def encode(self, bits):
|
def encode(self, bits):
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import random
|
|||||||
|
|
||||||
_constellation = [1, 1j, -1, -1j]
|
_constellation = [1, 1j, -1, -1j]
|
||||||
|
|
||||||
|
|
||||||
class Equalizer(object):
|
class Equalizer(object):
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
@@ -22,7 +23,6 @@ class Equalizer(object):
|
|||||||
choose = lambda: [r.choice(_constellation) for j in range(self.Nfreq)]
|
choose = lambda: [r.choice(_constellation) for j in range(self.Nfreq)]
|
||||||
return np.array([choose() for i in range(length)])
|
return np.array([choose() for i in range(length)])
|
||||||
|
|
||||||
|
|
||||||
def modulator(self, symbols):
|
def modulator(self, symbols):
|
||||||
gain = 1.0 / len(self.carriers)
|
gain = 1.0 / len(self.carriers)
|
||||||
result = []
|
result = []
|
||||||
@@ -65,7 +65,8 @@ class Equalizer(object):
|
|||||||
return h
|
return h
|
||||||
|
|
||||||
def equalize_signal(self, signal, expected, order, lookahead=0):
|
def equalize_signal(self, signal, expected, order, lookahead=0):
|
||||||
signal = np.concatenate([np.zeros(order-1), signal, np.zeros(lookahead)])
|
signal = [np.zeros(order-1), signal, np.zeros(lookahead)]
|
||||||
|
signal = np.concatenate(signal)
|
||||||
length = len(expected)
|
length = len(expected)
|
||||||
|
|
||||||
A = []
|
A = []
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class Receiver(object):
|
|||||||
|
|
||||||
def start(self, signal, gain=1.0):
|
def start(self, signal, gain=1.0):
|
||||||
sampler = sampling.Sampler(signal, sampling.Interpolator())
|
sampler = sampling.Sampler(signal, sampling.Interpolator())
|
||||||
symbols = dsp.Demux(sampler=sampler, omegas=self.omegas, Nsym=self.Nsym)
|
symbols = dsp.Demux(sampler, omegas=self.omegas, Nsym=self.Nsym)
|
||||||
freq_err = self._prefix(symbols, gain=gain)
|
freq_err = self._prefix(symbols, gain=gain)
|
||||||
sampler.freq -= freq_err
|
sampler.freq -= freq_err
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from . import framing
|
|||||||
from . import equalizer
|
from . import equalizer
|
||||||
from . import dsp
|
from . import dsp
|
||||||
|
|
||||||
|
|
||||||
class Sender(object):
|
class Sender(object):
|
||||||
def __init__(self, fd, config):
|
def __init__(self, fd, config):
|
||||||
self.offset = 0
|
self.offset = 0
|
||||||
@@ -50,6 +51,7 @@ class Sender(object):
|
|||||||
total_bits = i * Nfreq * self.modem.bits_per_symbol
|
total_bits = i * Nfreq * self.modem.bits_per_symbol
|
||||||
log.debug('Sent %8.1f kB', total_bits / 8e3)
|
log.debug('Sent %8.1f kB', total_bits / 8e3)
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
sender = Sender(args.output, config=args.config)
|
sender = Sender(args.output, config=args.config)
|
||||||
Fs = args.config.Fs
|
Fs = args.config.Fs
|
||||||
|
|||||||
Reference in New Issue
Block a user