mirror of
https://github.com/romanz/amodem.git
synced 2026-03-17 15:16:00 +08:00
equalizer: use low-level random API, for Python 2<->3 interoperability
Random.randrange() behaviour was changed at v3.2, see: https://bugs.python.org/issue9025
This commit is contained in:
@@ -7,11 +7,11 @@ from amodem import sampling
|
||||
import itertools
|
||||
import random
|
||||
|
||||
_constellation = [1, 1j, -1, -1j]
|
||||
|
||||
|
||||
class Equalizer(object):
|
||||
|
||||
_constellation = [1, 1j, -1, -1j]
|
||||
|
||||
def __init__(self, config):
|
||||
self.carriers = config.carriers
|
||||
self.omegas = 2 * np.pi * np.array(config.frequencies) / config.Fs
|
||||
@@ -20,7 +20,9 @@ class Equalizer(object):
|
||||
|
||||
def train_symbols(self, length, seed=0, constant_prefix=16):
|
||||
r = random.Random(seed)
|
||||
choose = lambda: [r.choice(_constellation) for j in range(self.Nfreq)]
|
||||
# Use low-level randomness for cross-version compatibility.
|
||||
random_symbol = lambda: self._constellation[r.getrandbits(2)]
|
||||
choose = lambda: [random_symbol() for j in range(self.Nfreq)]
|
||||
symbols = np.array([choose() for _ in range(length)])
|
||||
# Constant symbols (for analog debugging)
|
||||
symbols[:constant_prefix, :] = 1
|
||||
|
||||
Reference in New Issue
Block a user