def polar_codes_mapping(metric, N=8, k=4, nb_pkts = 100, graph = 'BER',channel='BSC'): print('-------------------Polar Codes + Mapping-----------------------------') cont = 2 if channel == 'AWGN': design_parameter = np.linspace(0.0, 10, cont) else: design_parameter = np.linspace(0.0001, 0.1, cont) for key in [0.5]: e_design = 0.1 # print('===============Design================',key) G,infoBits = polar.polar_generator_matrix(64, k, channel, e_design) k = len(G) Nt = len(G[1]) t = int(Nt /N) U_k = utils.symbols_generator(k) # all possible messages X_m = utils.symbols_generator(t) # all possible symbol sequences C = utils.matrix_codes(U_k, k, G, Nt) nx = 2**t*key # print('nx', nx, 't', t) x = utils.mapping2(C, X_m, t, nx) N = len(x[1]) if graph == 'BLER': metric[f"P({e_design})+M({key})"] = utils.block_error_probability(N,k,x,e0,e1) else: metric[f"P({e_design})+M({key})"] = utils.bit_error_rate(k,x,nb_pkts,e0,e1)
def autoencoder_NN(metric, N=8, k=4, nb_pkts = 100, graph = 'BER',interval=False): print('------------------- NN-autoencoder -----------------------------', interval) key = 'NN_auto' C = utils.NN_encoder(k,N) # print(np.array(C)) print('k ', k, 'N ', N) if graph == 'BLER': metric[key] = utils.block_error_probability(N, k, C, e0, e1) a,metric['BLER'] = utils.bit_error_rate_NN_predict(N, k, C, 10000, e0, e1, inter=interval) else: print("NN BER") t = time.time() metric[key],a = utils.bit_error_rate_NN_predict(N, k, C, nb_pkts, e0, e1, inter=interval) t = time.time() - t print(f"NN time = {t}s ========================") print(metric[key]) MAP_test = False if MAP_test: print("MAP BER") t = time.time() metric['MAP_dec'],a = utils.bit_error_rate(k, C, nb_pkts, e0, e1) t = time.time() - t print(f"MAP time = {t}s =======================") print(metric['MAP_dec'])
def integrated_scheme(metric, N=8, k=4, nb_pkts=100, graph='BER', channel='BSC'): print( '-------------------Integrated Scheme Code-----------------------------' ) for key in [0.5]: G, infoBits = polar.polar_generator_matrix(64, k, channel, 0.1) k = len(G) Nt = len(G[1]) t = int(Nt / N) U_k = utils.symbols_generator(k) # all possible messages C = utils.integrated_function(infoBits, U_k, k, Nt, -1) X_m = utils.symbols_generator(t) # all possible symbol sequences nx = 2**t * key # print('nx', nx, 't', t) x = utils.mapping(C, X_m, t, nx) N = len(x[1]) if graph == 'BLER': metric[f"Int_P({key})"] = utils.block_error_probability( N, k, C, e0, e1) else: metric[f"Int_P({key})"] = utils.bit_error_rate( k, x, nb_pkts, e0, e1)
def BER_NN(nb_pkts=100): # e0 = np.logspace(-3, 0, 15) # e0 = np.linspace(0.001, 0.999, 11) e0 = np.concatenate( (np.array([0.001]), np.linspace( 0.01, 0.1, 10, endpoint=False), np.linspace(0.1, 1, 15)), axis=0) e0[len(e0) - 1] = e0[len(e0) - 1] - 0.001 e1 = [t for t in e0 if t <= 0.5] inter_list = np.array(np.tile([0, 0, 0, 1], (2**k, 1))) C = np.round(model_encoder.predict([np.array(u_k), inter_list])).astype('int') print('codebook \n', C) print('codebook C is Linear? ', utils.isLinear(C)) aux = [] for code in C.tolist(): if code not in aux: aux.append(code) nb_repeated_codes = len(C) - len(aux) print('+++++++++++++++++++ Repeated Codes NN encoder = ', nb_repeated_codes) print('dist = ', sum([sum(codeword) for codeword in C]) * 1.0 / (N * 2**k)) print('***************************************************************') if nb_repeated_codes == 0: BER = test.read_ber_file(N, k, 'BER') BER = test.saved_results(BER, N, k) BLER = test.read_ber_file(N, k, 'BLER') BLER = test.saved_results(BLER, N, k, 'BLER') print("NN BER") t = time.time() BER['auto-array-inter'], BLER['auto-array-inter'] = bit_error_rate_NN( N, k, C, nb_pkts, e0, e1, channel) t = time.time() - t print(f"NN time = {t}s ========================") print("BER['auto-array-inter'] = ", BER['auto-array-inter']) print("BLER['auto-array-inter'] = ", BLER['auto-array-inter']) if MAP_test: print("MAP BER") t = time.time() BER['MAP'] = utils.bit_error_rate(k, C, 1000, e0, e1) t = time.time() - t print(f"MAP time = {t}s =======================") print("NN BLEP") t = time.time() BLER['auto_BLEP'] = utils.block_error_probability(N, k, C, e0, e1) t = time.time() - t print(f"NN time = {t}s ========================") utils.plot_BSC_BAC(f'BER Coding Mechanism N={N} k={k} - NN Interval', BER, k / N) utils.plot_BSC_BAC(f'BLER Coding Mechanism N={N} k={k} - NN Interval', BLER, k / N) else: print('Bad codebook repeated codewords')
def uncoded(metric, k=4, nb_pkts = 100, graph = 'BER'): print('-------------------Uncoded-----------------------------') key = f"Uncode" N = k U_k = utils.symbols_generator(k) # all possible messages if graph == 'BLER': metric[key] = utils.block_error_probability(N,k,U_k,e0,e1) else: metric[key] = utils.bit_error_rate(k,U_k,nb_pkts,e0,e1,False)
def flip_codes(metric, N=8, k=4, nb_pkts=100, graph='BER', channel='BSC'): print('-------------------Flip Code-----------------------------') key = '2,4,6' all_C = flip.codebook_generator_k4(N) C = all_C[2, 4, 6] print('Flip codebook', np.array(C)) if graph == 'BLER': metric[f"Flip({key})"] = utils.block_error_probability(N, k, C, e0, e1) else: metric[f"Flip({key})"] = utils.bit_error_rate(k, C, nb_pkts, e0, e1)
def polar_codes(metric, N=8, k=4, nb_pkts = 100, graph = 'BER',channel='BSC'): print('-------------------Polar Code-----------------------------') for key in [0.1]: G, infoBits = polar.polar_generator_matrix(N,k, channel, key) k = len(G) N = len(G[1]) U_k = utils.symbols_generator(k) # all possible messages C = utils.matrix_codes(U_k, k, G, N) # print('Polar codebook', np.array(C)) if graph == 'BLER': metric[f"Polar({key})"] = utils.block_error_probability(N,k,C,e0,e1) else: metric[f"Polar({key})"] = utils.bit_error_rate(k,C,nb_pkts,e0,e1) print(metric[f"Polar({key})"])
def polar_codes_NN(metric, N=8, k=4, nb_pkts = 100, graph = 'BER',channel='BSC'): print('-------------------Polar Code + NN decoder -----------------------------') key = 'NN_dec' G,infoBits = polar.polar_generator_matrix(N, k, channel, 0.1) # print('G = ', np.array(G)) k = len(G) N = len(G[1]) U_k = utils.symbols_generator(k) # all possible messages C = utils.matrix_codes(U_k, k, G, N) print('k ', k, 'N ', N) if graph == 'BLER': metric[key] = utils.block_error_probability(N, k, C, e0, e1) else: metric[key] = utils.bit_error_rate_NN(N, k, C, nb_pkts, e0, e1, channel)
def bch_codes(metric, N=8, k=4, nb_pkts = 100, graph = 'BER'): print('-------------------BCH Code-----------------------------') G = mat_gen.matrix_codes(N, k, 'bch') if G != []: for key in [0]: # print('G = ', np.array(G)) k = len(G) N = len(G[1]) U_k = utils.symbols_generator(k) # all possible messages C = utils.matrix_codes(U_k, k, G, N) print('k ',k,'N ',N) if graph == 'BLER': metric[f"BCH({key})"] = utils.block_error_probability(N,k,C,e0,e1) else: metric[f"BCH({key})"] = utils.bit_error_rate(k,C,nb_pkts,e0,e1)
def linear_codes(metric, N=8, k=4, nb_pkts=100, graph='BER'): print('-------------------Linear Code-----------------------------') for key in ['BKLC']: print(key) G = mat_gen.matrix_codes(N, k, key) if G != []: # print('G = ', np.array(G)) k = len(G) N = len(G[1]) U_k = utils.symbols_generator(k) # all possible messages C = utils.matrix_codes(U_k, k, G, N) print(np.array(C)) print('k ', k, 'N ', N) if graph == 'BLER': metric[key] = utils.block_error_probability(N, k, C, e0, e1) else: metric[key] = utils.bit_error_rate(k, C, nb_pkts, e0, e1)
def linear_codes_mapping(metric, N=8, k=4, nb_pkts = 100, graph = 'BER'): print('-------------------Linear Code + Mapping-----------------------------') G = mat_gen.matrix_codes(64,k,'linear') if G!= []: for key in [0.55]: k = len(G) Nt = len(G[1]) t = int(Nt/N) U_k= utils.symbols_generator(k) # all possible messages X_m = utils.symbols_generator(t) # all possible symbol sequences C = utils.matrix_codes(U_k, k, G, Nt) nx = 2**t*key # print('nx', nx, 't', t) x = utils.mapping(C, X_m, t, nx) #codebook after mapping N = len(x[1]) if graph == 'BLER': metric[f"L+M({key})"] = utils.block_error_probability(N,k,x,e0,e1) else: metric[f"L+M({key})"] = utils.bit_error_rate(k,x,nb_pkts,e0,e1)