diff --git a/amodem/detect.py b/amodem/detect.py index 9fc81d3..66c9c19 100644 --- a/amodem/detect.py +++ b/amodem/detect.py @@ -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) diff --git a/amodem/equalizer.py b/amodem/equalizer.py index 6f6e985..998801b 100644 --- a/amodem/equalizer.py +++ b/amodem/equalizer.py @@ -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): diff --git a/amodem/main.py b/amodem/main.py index 8144903..fa7da27 100644 --- a/amodem/main.py +++ b/amodem/main.py @@ -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: diff --git a/amodem/recv.py b/amodem/recv.py index 2544cdd..fb6404d 100644 --- a/amodem/recv.py +++ b/amodem/recv.py @@ -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) diff --git a/amodem/sampling.py b/amodem/sampling.py index b01ad4b..b369746 100644 --- a/amodem/sampling.py +++ b/amodem/sampling.py @@ -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