#NEWLINE# def turbo_encode( msg_bits , trellis1 , trellis2 , interleaver ) : #NEWLINE# #INDENT# ' Turbo Encoder.\n\n    Encode Bits using a parallel concatenated rate-1/3\n    turbo code consisting of two rate-1/2 systematic\n    convolutional component codes.\n\n    Parameters\n    ----------\n    msg_bits : 1D ndarray containing {0, 1}\n        Stream of bits to be turbo encoded.\n\n    trellis1 : Trellis object\n        Trellis representation of the\n        first code in the parallel concatenation.\n\n    trellis2 : Trellis object\n        Trellis representation of the\n        second code in the parallel concatenation.\n\n    interleaver : Interleaver object\n        Interleaver used in the turbo code.\n\n    Returns\n    -------\n    [sys_stream, non_sys_stream1, non_sys_stream2] : list of 1D ndarrays\n        Encoded bit streams corresponding\n        to the systematic output\n\n        and the two non-systematic\n        outputs from the two component codes.\n    ' #NEWLINE# stream = conv_encode ( msg_bits , trellis1 , 'rsc' ) #NEWLINE# sys_stream = stream [ : : 2 ] #NEWLINE# non_sys_stream_1 = stream [ 1 : : 2 ] #NEWLINE# interlv_msg_bits = interleaver . interlv ( sys_stream ) #NEWLINE# puncture_matrix = array ( [ [ 0 , 1 ] ] ) #NEWLINE# non_sys_stream_2 = conv_encode ( interlv_msg_bits , trellis2 , 'rsc' , non_sys_stream_1 ) #NEWLINE# sys_stream = sys_stream [ 0 : ( - trellis1 . total_memory ) ] #NEWLINE# non_sys_stream_1 = non_sys_stream_1 [ 0 : ( - trellis1 . total_memory ) ] #NEWLINE# non_sys_stream_2 = non_sys_stream_2 [ 0 : ( - trellis2 . total_memory ) ] #NEWLINE# return [ sys_stream , non_sys_stream_1 , non_sys_stream_2 ]