mirror of
https://github.com/romanz/amodem.git
synced 2026-04-03 11:06:24 +08:00
Merge remote-tracking branch 'jwoillez/jwoillez'
This commit is contained in:
@@ -85,12 +85,10 @@ class Detector(object):
|
||||
signal = np.concatenate([zeroes, carrier])
|
||||
signal = (2 ** 0.5) * signal / dsp.norm(signal)
|
||||
|
||||
coeffs = []
|
||||
for i in range(len(buf) - len(signal)):
|
||||
b = buf[i:i+len(signal)]
|
||||
norm_b = dsp.norm(b)
|
||||
c = (np.abs(np.dot(b, signal)) / norm_b) if norm_b else 0.0
|
||||
coeffs.append(c)
|
||||
corr = np.abs(np.correlate(buf, signal))
|
||||
norm_b = np.sqrt(np.correlate(np.abs(buf)**2, np.ones(len(signal))))
|
||||
coeffs = np.zeros_like(corr)
|
||||
coeffs[norm_b > 0.0] = corr[norm_b > 0.0] / norm_b[norm_b > 0.0]
|
||||
|
||||
index = np.argmax(coeffs)
|
||||
log.info('Carrier coherence: %.3f%%', coeffs[index] * 100)
|
||||
|
||||
@@ -46,9 +46,9 @@ class Equalizer(object):
|
||||
return np.array(list(itertools.islice(symbols, size)))
|
||||
|
||||
|
||||
prefix = [1]*200 + [0]*50
|
||||
equalizer_length = 200
|
||||
silence_length = 50
|
||||
prefix = [1]*equalizer_length + [0]*silence_length
|
||||
|
||||
|
||||
def train(signal, expected, order, lookahead=0):
|
||||
|
||||
@@ -59,7 +59,8 @@ def recv(config, src, dst, dump_audio=None, pylab=None):
|
||||
gain = 1.0 / amplitude
|
||||
log.debug('Gain correction: %.3f', gain)
|
||||
|
||||
sampler = sampling.Sampler(signal, sampling.Interpolator(), freq=freq)
|
||||
sampler = sampling.Sampler(signal, sampling.defaultInterpolator,
|
||||
freq=freq)
|
||||
receiver.run(sampler, gain=1.0/amplitude, output=dst)
|
||||
return True
|
||||
except BaseException:
|
||||
|
||||
@@ -70,6 +70,7 @@ class Receiver(object):
|
||||
self.plt.plot(np.arange(order+lookahead), coeffs)
|
||||
|
||||
equalization_filter = dsp.FIR(h=coeffs)
|
||||
log.debug('Training completed')
|
||||
# Pre-load equalization filter with the signal (+lookahead)
|
||||
equalized = list(equalization_filter(signal))
|
||||
equalized = equalized[prefix+lookahead:-postfix+lookahead]
|
||||
@@ -95,6 +96,7 @@ class Receiver(object):
|
||||
self._constellation(symbols[:, i], train_symbols[:, i],
|
||||
'$F_c = {0} Hz$'.format(freq), index=i)
|
||||
assert error_rate == 0, error_rate
|
||||
log.debug('Training verified')
|
||||
|
||||
def _bitstream(self, symbols, error_handler):
|
||||
streams = []
|
||||
@@ -156,6 +158,7 @@ class Receiver(object):
|
||||
)
|
||||
|
||||
def run(self, sampler, gain, output):
|
||||
log.debug('Receiving')
|
||||
symbols = dsp.Demux(sampler, omegas=self.omegas, Nsym=self.Nsym)
|
||||
self._prefix(symbols, gain=gain)
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@ class Interpolator(object):
|
||||
assert len(self.filt) == resolution
|
||||
|
||||
|
||||
defaultInterpolator = Interpolator()
|
||||
|
||||
|
||||
class Sampler(object):
|
||||
def __init__(self, src, interp=None, freq=1.0):
|
||||
self.freq = freq
|
||||
|
||||
Reference in New Issue
Block a user