How to use the amodem.sampling 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_transfer.py View on Github external
def run(size, chan=None, df=0, success=True, reader=None, cfg=None):
    if cfg is None:
        cfg = config.fastest()
    tx_data = os.urandom(size)
    tx_audio = BytesIO()
    main.send(config=cfg, src=BytesIO(tx_data), dst=tx_audio, gain=0.5)

    data = tx_audio.getvalue()
    data = common.loads(data)
    if chan is not None:
        data = chan(data)
    if df:
        sampler = sampling.Sampler(data, sampling.Interpolator())
        sampler.freq += df
        data = sampler.take(len(data))

    data = common.dumps(data)
    rx_audio = BytesIO(data)
    rx_data = BytesIO()
    dump = BytesIO()

    if reader:
        rx_audio = reader(rx_audio)
    try:
        result = main.recv(config=cfg, src=rx_audio, dst=rx_data,
                           dump_audio=dump, pylab=None)
    finally:
        rx_audio.close()
github romanz / amodem / tests / test_detect.py View on Github external
def symbols_stream(signal):
        sampler = sampling.Sampler(signal)
        return dsp.Demux(sampler=sampler, omegas=[omega], Nsym=config.Nsym)
    r = recv.Receiver(config, pylab=common.Dummy())
github romanz / amodem / tests / test_sampling.py View on Github external
def test_resample():
    x = np.sin(2*np.pi * 10 * np.linspace(0, 1, 1001))
    src = BytesIO(common.dumps(x))
    dst = BytesIO()
    sampling.resample(src=src, dst=dst, df=0.0)
    y = common.loads(dst.getvalue())
    err = x[:len(y)] - y
    assert np.max(np.abs(err)) < 1e-4

    dst = BytesIO()
    sampling.resample(src=BytesIO(b'\x00\x00'), dst=dst, df=0.0)
    assert dst.tell() == 0
github romanz / amodem / amodem / loop.py View on Github external
def __init__(self, src, freqs):
        interp = sampling.Interpolator()
        self.sampler = sampling.Sampler(src, interp)
        self.gens = []

        samplers = itertools.tee(self.sampler, len(freqs))
        for freq, generator in zip(freqs, samplers):
            gen = sigproc.extract_symbols(generator, freq)
            self.gens.append(gen)
github romanz / amodem / amodem / calib.py View on Github external
def frame_iter(config, src, frame_length):
    frame_size = frame_length * config.Nsym * config.sample_size
    omegas = 2 * np.pi * np.array(config.frequencies) / config.Fs

    while True:
        data = src.read(frame_size)
        if len(data) < frame_size:
            return
        data = common.loads(data)
        frame = data - np.mean(data)

        sampler = sampling.Sampler(frame)
        symbols = dsp.Demux(sampler, omegas, config.Nsym)

        symbols = np.array(list(symbols))
        coeffs = np.mean(np.abs(symbols) ** 2, axis=0) ** 0.5

        peak = np.max(np.abs(frame))
        total = np.sqrt(np.dot(frame, frame) / (0.5 * len(frame)))
        yield coeffs, peak, total
github romanz / amodem / amodem / main.py View on Github external
common.take(signal, int(config.skip_start * config.Fs))

    pylab = pylab or common.Dummy()
    detector = detect.Detector(config=config, pylab=pylab)
    receiver = _recv.Receiver(config=config, pylab=pylab)
    try:
        log.info('Waiting for carrier tone: %.1f kHz', config.Fc / 1e3)
        signal, amplitude, freq_error = detector.run(signal)

        freq = 1 / (1.0 + freq_error)  # receiver's compensated frequency
        log.debug('Frequency correction: %.3f ppm', (freq - 1) * 1e6)

        gain = 1.0 / amplitude
        log.debug('Gain correction: %.3f', gain)

        sampler = sampling.Sampler(signal, sampling.defaultInterpolator,
                                   freq=freq)
        receiver.run(sampler, gain=1.0/amplitude, output=dst)
        return True
    except BaseException:
        log.exception('Decoding failed')
        return False
    finally:
        dst.flush()
        receiver.report()
github romanz / amodem / amodem / equalizer.py View on Github external
def demodulator(self, signal, size):
        signal = itertools.chain(signal, itertools.repeat(0))
        symbols = dsp.Demux(sampler=sampling.Sampler(signal),
                            omegas=self.omegas, Nsym=self.Nsym)
        return np.array(list(itertools.islice(symbols, size)))
github romanz / amodem / amodem / loop.py View on Github external
def __init__(self, src, freqs):
        interp = sampling.Interpolator()
        self.sampler = sampling.Sampler(src, interp)
        self.gens = []

        samplers = itertools.tee(self.sampler, len(freqs))
        for freq, generator in zip(freqs, samplers):
            gen = sigproc.extract_symbols(generator, freq)
            self.gens.append(gen)