但是梵蒂冈梵蒂冈的报告

该代码段生成了用于测试的卷积编码器和Turbo编码的例子。它涉及到了随机消息生成、噪声添加、调制解调以及编码解码过程。主要步骤包括设置编码参数、创建Trellis结构、生成噪声、执行Turbo编码和添加噪声到信号中。
摘要由CSDN通过智能技术生成
def generate_examples(k_test=1000, step_of_history=200, SNR=0, code_rate = 2):

    trellis1 = cc.Trellis(np.array([2]), np.array([[7,5]]))
    trellis2 = cc.Trellis(np.array([2]), np.array([[7,5]]))
    #print('trellis: cc.Trellis(np.array([2]), np.array([[7,5]]))') # G(D) corresponding to the convolutional encoder

    tic = time.time()

    ### TEST EXAMPLES

    # Initialize Test Examples/
    noisy_codewords = np.zeros([1,int(k_test/step_of_history),step_of_history,2])
    true_messages = np.zeros([1,int(k_test/step_of_history),step_of_history,1])

    iterations_number = int(k_test/step_of_history)

    #for idx in range(SNR_points):
    nb_errors = np.zeros([iterations_number,1])


    tic = time.time()

    noise_sigmas = 10**(-SNR*1.0/20)

    mb_test_collect = np.zeros([iterations_number,step_of_history])

    interleaver = RandInterlv.RandInterlv(step_of_history,0)
    print("interleaver", interleaver)

    for iterations in range(iterations_number):

    #    print(iterations)
        message_bits = np.random.randint(0, 2, step_of_history)
        mb_test_collect[iterations,:] = message_bits
        [sys, par1, par2] = turbo.turbo_encode(message_bits, trellis1, trellis2, interleaver)

        noise = noise_sigmas*np.random.standard_normal(sys.shape) # Generate noise
        sys_r = (2*sys-1) + noise # Modulation plus noise
        noise = noise_sigmas*np.random.standard_normal(par1.shape) # Generate noise
        par1_r = (2*par1-1) + noise # Modulation plus noise
        noise = noise_sigmas*np.random.standard_normal(par2.shape) # Generate noise
        par2_r = (2*par2-1) + noise # Modulation plus noise

        sys_symbols = sys_r
        non_sys_symbols_1 = par1_r
        non_sys_symbols_2 = par2_r

        # ADD Training Examples
        noisy_codewords[0,iterations,:,:] = np.concatenate([sys_r.reshape(step_of_history,1),par1_r.reshape(step_of_history,1)],axis=1)

        # Message sequence
        true_messages[0,iterations,:,:] = message_bits.reshape(step_of_history,1)


    noisy_codewords = noisy_codewords.reshape(int(k_test/step_of_history),step_of_history,code_rate)
    true_messages = true_messages.reshape(int(k_test/step_of_history),step_of_history,1)
    target_true_messages  = mb_test_collect.reshape([mb_test_collect.shape[0],mb_test_collect.shape[1],1])

    toc = time.time()

    #print('time to generate test examples:', toc-tic)

    return (noisy_codewords, true_messages, target_true_messages)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值