コード例 #1
0
ファイル: scrambler.py プロジェクト: gasparka/wifi
def do(data: bits) -> bits:
    output = bits('')
    shr = bits('1011101')
    for bit in data:
        feedback = int(shr[3]) ^ int(shr[6])
        output += str(int(bit) ^ feedback)
        shr = str(feedback) + shr[:-1]
    return output
コード例 #2
0
ファイル: convolutional_coder.py プロジェクト: gasparka/wifi
def do(data: bits) -> bits:
    """ See Figure 17-8—Convolutional encoder """
    output = bits('')
    shr = bits('0' * (K - 1))
    for bit in data:
        i = bit + shr
        output += OUTPUT_LUT[bitstr.to_int(i)]
        shr = i[:-1]  # advance the shift register

    return output
コード例 #3
0
def test_hypothesis(data, coding_rate):
    data = bits(data)

    # cant test equality because 'do' throws away data
    do1 = do(data, coding_rate)
    undo1 = undo(do1, coding_rate)
    assert len(undo1) == len(data)

    do2 = do(undo1, coding_rate)
    assert do1 == do2
コード例 #4
0
ファイル: receiver.py プロジェクト: gasparka/wifi
def test_loopback(data_rate):
    np.random.seed(0)
    data_bits = bits(
        '0x0402002E006008CD37A60020D6013CF1006008AD3BAF00004A6F792C2062726967687420737061726B206F6620646976696E6974792C0A4461756768746572206F6620456C797369756D2C0A466972652D696E73697265642077652074726561673321B6')
    iq = transmit(data_bits, data_rate)
    iq = awgn(iq, 20)

    i = packet_detector(iq)[0]
    packet = receive(iq[i - 2:])
    assert packet.bits == data_bits
コード例 #5
0
ファイル: convolutional_coder.py プロジェクト: gasparka/wifi
def test_i161():
    """
    Uses 3/4 coding rate for data field.
    """

    # Table I-15—The DATA bits after scrambling (and resetting tail bits)
    input = bits(
        '0110110000011001100010011000111101101000001000011111010010100101011000010100111111010111101011100'
        '0100100000011001111001100111010111001001011110001010011100110001100000000011110001101011011001111'
        '100011111110000010010101100000110101100010010100110101001100111111111011110000010000010010101110'
        '001111010100110001110010000011010000011011111000111001001010000110011001000100011001101100110111'
        '110110101000111101100000001101110101001000000100111011001011111101111111000011010110001111011111'
        '000110010100101110101101110000100011111001111001101010100100001000000111111101011111001010100111'
        '01000101010101000100100000010001110100110110011110100100111011110011011001001110001101011110110'
        '111110001110000000000100010000010011001101000010111110110001010001001110001011100111001000101011'
        '01000001110110010010101000101101001000100010000000000001101110001111111000011101111001011001001'
    )

    # Table I-16—The BCC encoded DATA bits
    expect = bits(
        '0010101100001000101000011111000010011101101101011001101000011101010010101111101111101000110000101'
        '0001111110000001100100001110011110000000100001111100000000110011110000011010011111010111011001010'
        '10111110011000111111010101100100001111100010110110100101100110000011001010101011011001000100000101'
        '01101000101110100110010000000110010010110011001000011001111010001110100100011100000100000101101101'
        '11101101111100010111011000100000000010111110100010110111010110111100101011100101110110000111011001'
        '11011101000011010001001001110110001001110000001001001100100100101011110000010010010010110110101011'
        '1101110111000000100011001001111000111000000001101101001101011011000011011010100110000001001101010'
        '0101111001011010100011001110010110000100000001110101110001001001101000001010001000000011011001001'
        '11100010110001010001010010110111110001101001000100010001010110000110111111011011111001011110111110'
        '01101111100010100011101111110010100101010100000011111111010010011010010001001110111001010111101100'
        '01011011001000111001100101011111001010000011111011010100111010011111011110111000000100110111010110'
        '001110111100101010000000011011011011001110100100000111010111011011000010111111'
    )

    output = do(input)
    output = puncturer.do(output, coding_rate='3/4')
    assert output == expect

    # test decoding
    data = puncturer.undo(output, coding_rate='3/4')
    decoded = undo(data)
    assert decoded == input
コード例 #6
0
ファイル: scrambler.py プロジェクト: gasparka/wifi
def test_i152():
    """
    IEEE Std 802.11-2016: I.1.4.2 Coding the SIGNAL field bits
    """
    # Table I-13—The DATA bits before scrambling
    input = bits(
        '00000000000000000010000001000000000000000111010000000000000001100001000010110011111011000110010'
        '100000000000001000110101110000000001111001000111100000000000001100001000010110101110111001111010'
        '100000000000000000101001011110110100111100011010000000100010001100100111010010110111001100001011'
        '000101110000001001100111000001110100001100100111011010110000001001111011001100110000001000010011'
        '010010110011011101001011001110110100101100010111010011110001101000101000000100010100001101010111'
        '0111001100001011000101110101001100100111000000100111101100110011000000100101000100011011010011110'
        '1100111010010110101011101011011000110100010100000110001010010110010011101010011010110100100101100'
        '1110110110011101001011001001110101001100010011000000100111011101010011000000100001011100100111010'
        '1001101000011011100110110011001000010001101101000000000000000000000000000000000000000000000000'
    )

    # Table I-15—The DATA bits after scrambling ( tail bits set to 0! )
    expect = bits(
        '011011000001100110001001100011110110100000100001111101001010010101100001010011111101011110101'
        '110001001000000110011110011001110101110010010111100010100111001100011000000000111100011010110'
        '110011111000111111100000100101011000001101011000100101001101010011001111111110111100000100000'
        '100101011100011110101001100011100100000110100000110111110001110010010100001100110010001000110'
        '011011001101111101101010001111011000000011011101010010000001001110110010111111011111110000110'
        '101100011110111110001100101001011101011011100001000111110011110011010101001000010000001111111'
        '010111110010101001110100010101010100010010000001000111010011011001111010010011101111001101100'
        '100111000110101111011011111000111000000000010001000001001100110100001011111011000101000100111'
        '000101110011100100010101101000001110110010010101000101101001000100010000000000001101110001111'
        '111000011101111001011001001')

    output = do(input)

    # test against standard -> restore the tail bits to 0
    tail_zeroed = list(output)
    tail_zeroed[816:822] = ['0', '0', '0', '0', '0', '0']
    tail_zeroed = ''.join(tail_zeroed)
    assert tail_zeroed == expect

    # test reverse
    rev = undo(output)
    assert rev == input
コード例 #7
0
ファイル: convolutional_coder.py プロジェクト: gasparka/wifi
def test_signal():
    """
    Uses 1/2 coding rate for signal field.
    """

    # IEEE Std 802.11-2016: Table I-7—Bit assignment for SIGNAL field
    input = bits('101100010011000000000000')

    # IEEE Std 802.11-2016: Table I-8—SIGNAL field bits after encoding
    expected = bits('110100011010000100000010001111100111000000000000')
    output = do(input)
    assert output == expected

    # test decoding
    decoded = undo(output)
    assert decoded == input

    # test decoding with bit errors
    # 4 errors
    output = bits('010100011010100101000010001111100111000000100000')
    decoded = undo(output)
    assert decoded == input