#NEWLINE# def map_decode( sys_symbols , non_sys_symbols , trellis , noise_variance , L_int , mode = 'decode' ) : #NEWLINE# #INDENT# " Maximum a-posteriori probability (MAP) decoder.\n\n    Decodes a stream of convolutionally encoded\n    (rate 1/2) bits using the MAP algorithm.\n\n    Parameters\n    ----------\n    sys_symbols : 1D ndarray\n        Received symbols corresponding to\n        the systematic (first output) bits in\n        the codeword.\n\n    non_sys_symbols : 1D ndarray\n        Received symbols corresponding to the non-systematic\n        (second output) bits in the codeword.\n\n    trellis : Trellis object\n        Trellis representation of the convolutional code.\n\n    noise_variance : float\n        Variance (power) of the AWGN channel.\n\n    L_int : 1D ndarray\n        Array representing the initial intrinsic\n        information for all received\n        symbols.\n\n        Typically all zeros,\n        corresponding to equal prior\n        probabilities of bits 0 and 1.\n\n    mode : str{'decode', 'compute'}, optional\n        The mode in which the MAP decoder is used.\n        'decode' mode returns the decoded bits\n\n        along with the extrinsic information.\n        'compute' mode returns only the\n        extrinsic information.\n\n    Returns\n    -------\n    [L_ext, decoded_bits] : list of two 1D ndarrays\n        The first element of the list is the extrinsic information.\n        The second element of the list is the decoded bits.\n\n    " #NEWLINE# k = trellis . k #NEWLINE# n = trellis . n #NEWLINE# rate = ( float ( k ) / n ) #NEWLINE# number_states = trellis . number_states #NEWLINE# number_inputs = trellis . number_inputs #NEWLINE# msg_length = len ( sys_symbols ) #NEWLINE# f_state_metrics = zeros ( [ number_states , 2 ] ) #NEWLINE# f_state_metrics [ 0 ] [ 0 ] = 1 #NEWLINE# b_state_metrics = zeros ( [ number_states , ( msg_length + 1 ) ] ) #NEWLINE# b_state_metrics [ : , msg_length ] = 1 #NEWLINE# branch_probs = zeros ( [ number_inputs , number_states , ( msg_length + 1 ) ] ) #NEWLINE# app = zeros ( number_inputs ) #NEWLINE# lappr = 0 #NEWLINE# decoded_bits = zeros ( msg_length , 'int' ) #NEWLINE# L_ext = zeros ( msg_length ) #NEWLINE# priors = empty ( [ 2 , msg_length ] ) #NEWLINE# priors [ 0 , : ] = ( 1 / ( 1 + exp ( L_int ) ) ) #NEWLINE# priors [ 1 , : ] = ( 1 - priors [ 0 , : ] ) #NEWLINE# _backward_recursion ( trellis , msg_length , noise_variance , sys_symbols , non_sys_symbols , branch_probs , priors , b_state_metrics ) #NEWLINE# _forward_recursion_decoding ( trellis , mode , msg_length , noise_variance , sys_symbols , non_sys_symbols , b_state_metrics , f_state_metrics , branch_probs , app , L_int , priors , L_ext , priors ) #NEWLINE# return [ L_ext , decoded_bits ]