Created
March 5, 2012 04:32
-
-
Save veeresht/1976633 to your computer and use it in GitHub Desktop.
MAP Decoder simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from numpy import array, arange, power, log10, zeros, sqrt | |
| from numpy.random import randint, randn | |
| from commpy.channelcoding import turbo_encode, map_decode, Trellis | |
| from commpy.utilities import hamming_dist | |
| total_bits = 1000000 | |
| block_size = 1000 | |
| num_blocks = total_bits/block_size | |
| # Noise Variance | |
| noise_var = 1/power(10, arange(0, 0.5, 0.05)) | |
| # Compute Eb/No using noise variance and Eb = 2 (for BPSK) | |
| Eb_No_dB = 10 * log10(1/noise_var) | |
| prob_bit_error = zeros(len(Eb_No_dB)) | |
| # Encoder Definition | |
| memory = array([2]) | |
| g_matrix = array([[04, 07]]) | |
| feedback = 05 | |
| trellis = Trellis(memory, g_matrix, feedback, 'rsc') | |
| interlv_seed = 64 | |
| total_bit_errors = 0 | |
| for i in xrange(len(noise_var)): | |
| print "======== Iteration " + str(i) + " =========" | |
| print "Progress: ", | |
| for block_num in xrange(num_blocks): | |
| msg_bits = randint(0, 2, block_size) | |
| [sys_stream, non_sys_stream_1, non_sys_stream_2] = \ | |
| turbo_encode(msg_bits, trellis, trellis, interlv_seed) | |
| awgn = sqrt(noise_var[i]) * randn((block_size+2)*2) | |
| rx_sys_stream = (2*sys_stream - 1) + awgn[0:block_size+2] | |
| rx_non_sys_stream_1 = (2*non_sys_stream_1 - 1) + awgn[block_size+2:] | |
| L_int = zeros(block_size+2) | |
| [L_ext, decoded_bits] = map_decode(rx_sys_stream, | |
| rx_non_sys_stream_1, | |
| trellis, noise_var[i], L_int) | |
| #print sys_stream | |
| #print decoded_bits | |
| block_bit_errors = hamming_dist(sys_stream, decoded_bits) | |
| total_bit_errors += block_bit_errors | |
| if block_num+1 % 20 == 0: | |
| print ".", | |
| prob_bit_error[i] = total_bit_errors / ((block_size+2)*num_blocks) | |
| print " ================================" | |
| print "SNR: " + str(Eb_No_dB[i]) | |
| print "Pe: " + str(prob_bit_error[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment