Example #1
0
def turbo_encode(msg_bits, trellis1, trellis2, interleaver):
    """ Turbo Encoder.

    Encode Bits using a parallel concatenated rate-1/3
    turbo code consisting of two rate-1/2 systematic
    convolutional component codes.

    Parameters
    ----------
    msg_bits : 1D ndarray containing {0, 1}
        Stream of bits to be turbo encoded.

    trellis1 : Trellis object
        Trellis representation of the
        first code in the parallel concatenation.

    trellis2 : Trellis object
        Trellis representation of the
        second code in the parallel concatenation.

    interleaver : Interleaver object
        Interleaver used in the turbo code.

    Returns
    -------
    [sys_stream, non_sys_stream1, non_sys_stream2] : list of 1D ndarrays
        Encoded bit streams corresponding
        to the systematic output

        and the two non-systematic
        outputs from the two component codes.
    """

    stream = conv_encode(msg_bits, trellis1, 'rsc')
    #print('This is after stream 1') 
    sys_stream = stream[::2]
    non_sys_stream_1 = stream[1::2]

    interlv_msg_bits = interleaver.interlv(sys_stream)
    puncture_matrix = array([[0, 1]])
    #print('interlv_msg_bits', interlv_msg_bits)
    non_sys_stream_2 = conv_encode(interlv_msg_bits, trellis2, 'rsc', puncture_matrix)
    #print('This is after stream 2')

    sys_stream = sys_stream[0:-trellis1.total_memory]
    non_sys_stream_1 = non_sys_stream_1[0:-trellis1.total_memory]
    non_sys_stream_2 = non_sys_stream_2[0:-trellis2.total_memory]

    return [sys_stream, non_sys_stream_1, non_sys_stream_2]
Example #2
0
def turbo_encode(msg_bits, trellis1, trellis2, interleaver):
    """ Turbo Encoder.

    Encode Bits using a parallel concatenated rate-1/3
    turbo code consisting of two rate-1/2 systematic
    convolutional component codes.

    Parameters
    ----------
    msg_bits : 1D ndarray containing {0, 1}
        Stream of bits to be turbo encoded.

    trellis1 : Trellis object
        Trellis representation of the
        first code in the parallel concatenation.

    trellis2 : Trellis object
        Trellis representation of the
        second code in the parallel concatenation.

    interleaver : Interleaver object
        Interleaver used in the turbo code.

    Returns
    -------
    [sys_stream, non_sys_stream1, non_sys_stream2] : list of 1D ndarrays
        Encoded bit streams corresponding
        to the systematic output

        and the two non-systematic
        outputs from the two component codes.
    """

    stream = conv_encode(msg_bits, trellis1, 'rsc')
    sys_stream = stream[::2]
    non_sys_stream_1 = stream[1::2]

    interlv_msg_bits = interleaver.interlv(sys_stream)
    puncture_matrix = array([[0, 1]])
    non_sys_stream_2 = conv_encode(interlv_msg_bits, trellis2, 'rsc', puncture_matrix)

    sys_stream = sys_stream[0:-trellis1.total_memory]
    non_sys_stream_1 = non_sys_stream_1[0:-trellis1.total_memory]
    non_sys_stream_2 = non_sys_stream_2[0:-trellis2.total_memory]

    return [sys_stream, non_sys_stream_1, non_sys_stream_2]