📄 test_ldpc2fold_ch_complex.c
字号:
/*************************************************************************** ldpc_2fold_ch_complex.c - 2fold LDPC-code, but with a complex channel ------------------- begin : 01 Sept 2003 authors : Nicolae Chiurtu emails : Nicolae.Chiurtu@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description 03/09/01 - Nicou - Begin 03/09/03 - ineiti - added complex channel 04/03/03 - ineiti - added short comment **************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include <stdlib.h>#include "spc.h"#include "std.h"#include "math.h"#include <fpu_control.h>#define DBG_LVL 0char desc[] ="Description:\n""As a further preparation to go over the air, this time we use a complex\n""channel. This allows us to be even more precise to the real thing.\n""The simulated chain is a 2x2 MIMO system, and the variance is increased\n""up to the point where we get errors. There should be no errors for\n""sigma < 0.09, and then the BER should be > 0.\n\n";// The number of experiments and variances#define no_var 12#define no_exp 2double getSigma(double);struct chain_t *test_chain, *test_chain_2;void *start_it( void *arg ) { swr_sdb_id mid[2],src,block_complex; swr_sdb_id split, tsd, rcd, mid_rx[2],encoder,decoder; int sigma; double a11_real, a11_imag, a12_real, a12_imag, a21_real, a21_imag, a22_real, a22_imag; double total_errors; int a, b; int errors, total_info_bits; double ber = 0.0; double real_sigma; int sigma_array[no_var] = {320, 640, 960, 1280, 1600, 1920, 2240, 2560, 2880, 3200, 3500, 3840}; block_t ch_est_ant1, ch_est_ant2; SYMBOL_COMPLEX *ch_est_ant1_ptr, *ch_est_ant2_ptr; // Division by zero and overflow /* { *//* fpu_control_t fpu_err = 0x37f - _FPU_MASK_ZM - _FPU_MASK_OM; *//* _FPU_SETCW( fpu_err ); *//* } */ PR( "Setting up main-chain\n" ); // This chain simulates a simple 2x2 MIMO without LDPC test_chain = swr_chain_create(NEW_SPC_VAR( "random", src ), NEW_SPC_VAR( "test_data_send", tsd), NEW_SPC_VAR( "ldpc_encode_2fold", encoder), NEW_SPC( "mapper"), NEW_SPC_VAR( "split", split ), NEW_SPC_VAR( "chest_send", mid[ 0 ] ), NEW_SPC_VAR( "block_complex", block_complex), NEW_SPC_VAR( "chest_rcv", mid_rx[ 0 ] ), NEW_SPC_VAR( "ldpc_decode_2fold", decoder), NEW_SPC_VAR( "test_data_rcv", rcd ), CHAIN_END ); PR( "Setting up second chain\n" ); test_chain_2 = swr_chain_create( OLD_SPC_OUT( split, 1 ), NEW_SPC_VAR( "chest_send", mid[ 1 ] ), OLD_SPC_IN_OUT( block_complex, 1, 1 ), NEW_SPC_VAR( "chest_rcv", mid_rx[ 1 ] ), OLD_SPC_IN( decoder, 1), CHAIN_END ); for ( a=0; a<2; a++ ){ swr_sdb_set_config_int( mid[ a ], "circ_ext", 0 ); swr_sdb_set_config_int( mid_rx[ a ], "circ_ext", 0 ); } PR( "Chains are set up\n" ); //Config Amplitude swr_sdb_set_config_int( mid[0], "amplitude", 32767 ); swr_sdb_set_config_int( mid[1], "amplitude", 32767 ); swr_sdb_set_config_int( block_complex, "precision", 14 ); swr_sdb_set_config_int( mid[1], "index", 1 ); swr_sdb_set_config_int( rcd, "mode", 1 ); swr_sdb_set_config_int( decoder, "chest1", mid_rx[0] ); swr_sdb_set_config_int( decoder, "chest2", mid_rx[1] ); swr_sdb_set_config_int( encoder, "ldpc_code_id", 1 ); swr_sdb_set_config_int( decoder, "ldpc_code_id", 1 ); swr_sdb_set_config_int( decoder, "iterations", 15 ); swr_sdb_set_config_int( decoder, "iterations_left", 1 ); swr_sdb_set_config_int( decoder, "iterations_right", 1 ); PR( "Connecting the test_data modules\n" ); swr_conn_add(tsd, 1,rcd, 1); //swr_sdb_set_config_int( snk, "flag", 1 ); //dump PR( "Sending first message\n" ); for (a = 0; a < no_var; a++ ) { // setting the noise variance sigma = sigma_array[a]; swr_sdb_set_config_double( block_complex, "sigma_1_real", sigma ); swr_sdb_set_config_double( block_complex, "sigma_1_imag", sigma ); swr_sdb_set_config_double( block_complex, "sigma_2_real", sigma ); swr_sdb_set_config_double( block_complex, "sigma_2_imag", sigma ); swr_sdb_set_config_int( block_complex, "size", 2000 ); total_errors = 0.0; for (b = 0; b < no_exp; b++){ // setting the channel a11_real = getSigma(1.0); a12_real = getSigma(1.0); a21_real = getSigma(1.0); a22_real = getSigma(1.0); a11_imag = getSigma(1.0); a12_imag = getSigma(1.0); a21_imag = getSigma(1.0); a22_imag = getSigma(1.0); //-0.541508 + i*-1.57244 -1.43718 + i*-0.790332; 2.10095 + i*2.10164 -0.0110254 + i*1.48566 // 375:-112i) h12(36:397i) h21(-385:61i) h22(-155:-317i/* a11_real =-0.541508 ; *//* a12_real = -1.43; *//* a21_real = 2.1; *//* a22_real = -0.01; *//* a11_imag = -1.57; *//* a12_imag = -0.79; *//* a21_imag = 2.1; *//* a22_imag = 1.48; */ //PR( "**********************************"); //PR( "\nH = [ %g %g ; %g %g ]\n", // a11, a12, a21, a22 ); swr_sdb_set_config_double( block_complex, "h11_real", a11_real ); swr_sdb_set_config_double( block_complex, "h12_real", a12_real ); swr_sdb_set_config_double( block_complex, "h21_real", a21_real ); swr_sdb_set_config_double( block_complex, "h22_real", a22_real ); swr_sdb_set_config_double( block_complex, "h11_imag", a11_imag ); swr_sdb_set_config_double( block_complex, "h12_imag", a12_imag ); swr_sdb_set_config_double( block_complex, "h21_imag", a21_imag ); swr_sdb_set_config_double( block_complex, "h22_imag", a22_imag ); // PR( "\nH = [ %g + i*%g %g + i*%g; %g + i*%g %g + i*%g ]\n", // a11_real, a11_imag, a12_real, a12_imag, a21_real, a21_imag, a22_real, a22_imag ); // here we print the scaled channel and variance // to be compared with the one we estimate ( printed in ldpc_decode.c) PR_DBG( 4, "a11(%g:%gi) a12(%g:%gi) a21(%g:%gi) a22(%g:%gi) var1(%g) var2(%g)\n", floor(a11_real*327.67), floor(a11_imag*327.67), floor(a12_real*327.67), floor(a12_imag*327.67), floor(a21_real*327.67), floor(a21_imag*327.67), floor(a22_real*327.67), floor(a22_imag*327.67), (double) pow (sigma*0.01,2), (double) pow (sigma*0.01,2)); swr_sdb_set_config_int( mid_rx[0], "num_of_antennas", 2); swr_sdb_set_config_int( mid_rx[1], "num_of_antennas", 2); swr_sdb_send_msg( src, SUBS_MSG_USER, NULL, -1 ); //PR( "Total data: %i, Errors: %i\n", // swr_sdb_get_stats_int( rcd, "total" ), // swr_sdb_get_stats_int( rcd, "error" ) ); total_info_bits = swr_sdb_get_stats_int( rcd, "total" ); errors = swr_sdb_get_stats_int( rcd, "error" ); total_errors += errors; ch_est_ant1 = swr_sdb_get_stats_block( mid_rx[0], "channel" ); ch_est_ant2 = swr_sdb_get_stats_block( mid_rx[1], "channel" ); ch_est_ant1_ptr = ch_est_ant1.data; ch_est_ant2_ptr = ch_est_ant2.data; //PR("Noise Variance ant 1 = [%i], ant 2 = [%i] \n", // swr_sdb_get_stats_int( mid_rx[0], "noise_var_real"), // swr_sdb_get_stats_int( mid_rx[1], "noise_var_real")); } // for number experiments ber = (double) total_errors / (no_exp * total_info_bits); real_sigma = (double) sigma / 32767; PR("Sigma = %g, BER = %g\n", real_sigma, ber); } // for the number of variances // swr_chain_destroy( test_chain ); return 0;}swr_spc_id_t spm_id;struct thread start;/** * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */int um_module_init(void) { PR_CL( desc ); test_chain = NULL; if ( swr_thread_init( &start, start_it, NULL ) < 0 ) goto first_no_stack; return 0;first_no_stack: PR_DBG( 0, "Couldn't allocate stack\n" ); return -1;}void um_module_exit( void ) { swr_thread_free( &start, NULL ); swr_chain_destroy( test_chain_2 ); swr_chain_destroy( test_chain );}double getSigma( double amplitude ) { unsigned short x[3]; double u, v, w, alpha; x[0] = (unsigned short)((get_time_usec()>>00)&0xffff); x[1] = (unsigned short)((get_time_usec()>>16)&0xffff); x[2] = (unsigned short)((get_time_usec()>>00)&0xffff); do { u = 2*erand48(x)-1; v = 2*erand48(x)-1; w = u*u + v*v; } while (w>=1); alpha = sqrt( -2 * log(w)/w); return alpha * u * amplitude;}module_init( um_module_init );module_exit( um_module_exit );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -