mirror of
https://github.com/romanz/amodem.git
synced 2026-02-09 02:48:01 +08:00
Made PEP8 changes to several scripts and files.
This commit is contained in:
@@ -6,6 +6,7 @@ import time
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Interface(object):
|
||||
def __init__(self, config, debug=False):
|
||||
self.debug = bool(debug)
|
||||
|
||||
@@ -11,29 +11,27 @@ log = logging.getLogger(__name__)
|
||||
|
||||
scaling = 32000.0 # out of 2**15
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
def load(fileobj):
|
||||
''' Load signal from file object. '''
|
||||
""" Load signal from file object. """
|
||||
return loads(fileobj.read())
|
||||
|
||||
|
||||
def loads(data):
|
||||
''' Load signal from memory buffer. '''
|
||||
""" Load signal from memory buffer. """
|
||||
x = np.frombuffer(data, dtype='int16')
|
||||
x = x / scaling
|
||||
return x
|
||||
|
||||
|
||||
def dumps(sym):
|
||||
''' Dump signal to memory buffer. '''
|
||||
""" Dump signal to memory buffer. """
|
||||
sym = sym.real * scaling
|
||||
return sym.astype('int16').tostring()
|
||||
|
||||
|
||||
def iterate(data, size, func=None, truncate=True, index=False):
|
||||
''' Iterate over a signal, taking each time *size* elements. '''
|
||||
""" Iterate over a signal, taking each time *size* elements. """
|
||||
offset = 0
|
||||
data = iter(data)
|
||||
|
||||
@@ -51,9 +49,9 @@ def iterate(data, size, func=None, truncate=True, index=False):
|
||||
|
||||
|
||||
def split(iterable, n):
|
||||
''' Split an iterable of n-tuples into n iterables of scalars.
|
||||
""" Split an iterable of n-tuples into n iterables of scalars.
|
||||
The k-th iterable will be equivalent to (i[k] for i in iter).
|
||||
'''
|
||||
"""
|
||||
def _gen(it, index):
|
||||
for item in it:
|
||||
yield item[index]
|
||||
@@ -63,26 +61,26 @@ def split(iterable, n):
|
||||
|
||||
|
||||
def icapture(iterable, result):
|
||||
''' Appends each yielded item to result. '''
|
||||
""" Appends each yielded item to result. """
|
||||
for i in iter(iterable):
|
||||
result.append(i)
|
||||
yield i
|
||||
|
||||
|
||||
def take(iterable, n):
|
||||
''' Take n elements from iterable, and return them as a numpy array. '''
|
||||
""" Take n elements from iterable, and return them as a numpy array. """
|
||||
return np.array(list(itertools.islice(iterable, n)))
|
||||
|
||||
|
||||
def izip(iterables):
|
||||
''' "Python 3" zip re-implementation for Python 2. '''
|
||||
""" "Python 3" zip re-implementation for Python 2. """
|
||||
iterables = [iter(iterable) for iterable in iterables]
|
||||
while True:
|
||||
yield tuple([next(iterable) for iterable in iterables])
|
||||
|
||||
|
||||
class Dummy(object):
|
||||
''' Dummy placeholder object for testing and mocking. '''
|
||||
""" Dummy placeholder object for testing and mocking. """
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self
|
||||
|
||||
@@ -62,7 +62,7 @@ def coherence(x, omega):
|
||||
|
||||
|
||||
def linear_regression(x, y):
|
||||
''' Find (a,b) such that y = a*x + b. '''
|
||||
""" Find (a,b) such that y = a*x + b. """
|
||||
x = np.array(x)
|
||||
y = np.array(y)
|
||||
mean_x = np.mean(x)
|
||||
@@ -100,7 +100,7 @@ class MODEM(object):
|
||||
yield self.encode_map[bits_tuple]
|
||||
|
||||
def decode(self, symbols, error_handler=None):
|
||||
''' Maximum-likelihood decoding, using naive nearest-neighbour. '''
|
||||
""" Maximum-likelihood decoding, using naive nearest-neighbour. """
|
||||
symbols_vec = self.symbols
|
||||
_dec = self.decode_list
|
||||
for received in symbols:
|
||||
@@ -113,7 +113,7 @@ class MODEM(object):
|
||||
|
||||
|
||||
def prbs(reg, poly, bits):
|
||||
''' Simple pseudo-random number generator. '''
|
||||
""" Simple pseudo-random number generator. """
|
||||
mask = (1 << bits) - 1
|
||||
|
||||
size = 0 # effective register size (in bits)
|
||||
|
||||
@@ -2,9 +2,9 @@ import numpy as np
|
||||
|
||||
|
||||
def solver(t, y):
|
||||
''' Solve Mx = y for x, where M[i,j] = t[|i-j|], in O(N^2) steps.
|
||||
""" Solve Mx = y for x, where M[i,j] = t[|i-j|], in O(N^2) steps.
|
||||
See http://en.wikipedia.org/wiki/Levinson_recursion for details.
|
||||
'''
|
||||
"""
|
||||
N = len(t)
|
||||
assert len(y) == N
|
||||
|
||||
|
||||
@@ -34,5 +34,6 @@ def main():
|
||||
|
||||
pylab.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -17,5 +17,6 @@ def main():
|
||||
|
||||
resample(src=sys.stdin, dst=sys.stdout, df=args.df)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user