Exemplo n.º 1
0
def run(
    current_state: List[List[str]],
    neighbour_counter: Callable,
    get_new_state: Callable,
    hook: Callable,
):
    last_state = None

    while current_state != last_state:
        hook(current_state)
        last_state = current_state
        current_state = common.iterate(current_state, neighbour_counter, get_new_state)
Exemplo n.º 2
0
def encode(data, nsym=DEFAULT_NSYM):
    chunk_size = BLOCK_SIZE - nsym - 1

    for _, chunk in common.iterate(data, chunk_size, bytearray, truncate=False):
        size = len(chunk)
        if size < chunk_size:
            padding = [0] * (chunk_size - size)
            chunk.extend(padding)

        block = bytearray([size]) + chunk
        yield rs_encode_msg(block, nsym)

    yield rs_encode_msg(end_of_stream(chunk_size), nsym)
Exemplo n.º 3
0
def detect(samples, freq):

    counter = 0
    bufs = collections.deque([], maxlen=config.baud)  # 1 second of symbols
    for offset, buf in common.iterate(samples, config.Nsym):
        bufs.append(buf)

        coeff = sigproc.coherence(buf, config.Fc)
        if abs(coeff) > COHERENCE_THRESHOLD:
            counter += 1
        else:
            counter = 0

        if counter == CARRIER_THRESHOLD:
            length = (CARRIER_THRESHOLD - 1) * config.Nsym
            begin = offset - length
            amplitude = report_carrier(bufs, begin=begin)
            break
    else:
        raise ValueError('No carrier detected')

    log.debug('Buffered %d ms of audio', len(bufs))

    to_append = SEARCH_WINDOW + (CARRIER_DURATION - CARRIER_THRESHOLD)
    bufs_iterator = common.iterate(samples, config.Nsym)
    for _, buf in itertools.islice(bufs_iterator, to_append):
        bufs.append(buf)

    bufs = tuple(bufs)[-CARRIER_DURATION-2*SEARCH_WINDOW:]
    buf = np.concatenate(bufs)

    offset = find_start(buf, length=config.Nsym*CARRIER_DURATION)
    start = begin - config.Nsym * SEARCH_WINDOW + offset
    log.info('Carrier starts at %.3f ms',
             start * config.Tsym * 1e3 / config.Nsym)

    return itertools.chain(buf[offset:], samples), amplitude
Exemplo n.º 4
0
def extract_symbols(x, freq, offset=0):
    Hc = exp_iwt(-freq, Nsym) / (0.5*Nsym)

    for _, symbol in common.iterate(x, Nsym):
        yield np.dot(Hc, symbol)
Exemplo n.º 5
0
 def encode(self, bits):
     for _, bits_tuple in common.iterate(bits, self.bits_per_symbol, tuple):
         yield self._enc[bits_tuple]
Exemplo n.º 6
0
def iterlist(x, *args, **kwargs):
    x = np.array(x)
    return list((i, list(x)) for i, x in common.iterate(x, *args, **kwargs))