How to use the amodem.dsp function in amodem

To help you get started, we’ve selected a few amodem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github romanz / amodem / tests / test_dsp.py View on Github external
def test_demux():
    freqs = np.array([1e3, 2e3])
    omegas = 2 * np.pi * freqs / config.Fs
    carriers = [dsp.exp_iwt(2*np.pi*f/config.Fs, config.Nsym) for f in freqs]
    syms = [3, 2j]
    sig = np.dot(syms, carriers)
    res = dsp.Demux(sampling.Sampler(sig.real), omegas, config.Nsym)
    res = np.array(list(res))
    assert np.max(np.abs(res - syms)) < 1e-12
github romanz / amodem / amodem / detect.py View on Github external
def _wait(self, samples):
        counter = 0
        bufs = collections.deque([], maxlen=self.maxlen)
        for offset, buf in common.iterate(samples, self.Nsym, index=True):
            if offset > self.max_offset:
                raise ValueError('Timeout waiting for carrier')
            bufs.append(buf)

            coeff = dsp.coherence(buf, self.omega)
            if abs(coeff) > self.COHERENCE_THRESHOLD:
                counter += 1
            else:
                counter = 0

            if counter == self.CARRIER_THRESHOLD:
                return offset, bufs

        raise ValueError('No carrier detected')
github romanz / amodem / amodem / recv.py View on Github external
prefix = postfix = equalizer.silence_length * self.Nsym
        signal_length = equalizer_length * self.Nsym + prefix + postfix

        signal = sampler.take(signal_length + lookahead)

        coeffs = equalizer.train(
            signal=signal[prefix:-postfix],
            expected=np.concatenate([train_signal, np.zeros(lookahead)]),
            order=order, lookahead=lookahead
        )

        self.plt.figure()
        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]
        self._verify_training(equalized, train_symbols)
        return equalization_filter
github romanz / amodem / amodem / equalizer.py View on Github external
def train_symbols(self, length, constant_prefix=16):
        r = dsp.prbs(reg=1, poly=0x1100b, bits=2)
        constellation = [1, 1j, -1, -1j]

        symbols = []
        for _ in range(length):
            symbols.append([constellation[next(r)] for _ in range(self.Nfreq)])

        symbols = np.array(symbols)
        # Constant symbols (for analog debugging)
        symbols[:constant_prefix, :] = 1
        return symbols
github romanz / amodem / amodem / recv.py View on Github external
def __init__(self, config, pylab=None):
        self.stats = {}
        self.plt = pylab
        self.modem = dsp.MODEM(config.symbols)
        self.frequencies = np.array(config.frequencies)
        self.omegas = 2 * np.pi * self.frequencies / config.Fs
        self.Nsym = config.Nsym
        self.Tsym = config.Tsym
        self.iters_per_update = 100  # [ms]
        self.iters_per_report = 1000  # [ms]
        self.modem_bitrate = config.modem_bps
        self.equalizer = equalizer.Equalizer(config)
        self.carrier_index = config.carrier_index
        self.output_size = 0  # number of bytes written to output stream
        self.freq_err_gain = 0.01 * self.Tsym  # integration feedback gain
github romanz / amodem / amodem / detect.py View on Github external
def find_start(self, buf):
        carrier = dsp.exp_iwt(self.omega, self.Nsym)
        carrier = np.tile(carrier, self.START_PATTERN_LENGTH)
        zeroes = carrier * 0.0
        signal = np.concatenate([zeroes, carrier])
        signal = (2 ** 0.5) * signal / dsp.norm(signal)

        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)
        offset = index + len(zeroes)
        return offset