📄 test_mimoldpc.c
字号:
/*************************************************************************** test_MimoLdpc.c - runs a successive interference canceller using ldpc-codes ------------------- begin : 19 Aug 2003 authors : Selvavinayagam Gunabalan emails : Selvavinayagam.Gunabalan@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description 19/09/03 - Selva - Begin 04/03/03 - ineiti - added a small description **************************************************************************//*************************************************************************** * * * 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"char desc[] ="Description:\n""This is a test for the successive interference canceller using\n""ldpc-codes. A 2x2 MIMO system is simulated, and 6 iterations\n""are done with a randomly chosen channel-matrix H. For each\n""iteration, the number of errors is printed. Expect it to be\n""0, except for some rare cases where H is of rank 1.\n\n";#define DBG_LVL 4// Well, to really use this, put it to something like// 20000 and drink some Chai#define NOV 2#define NOS 3double getSigma( double );struct chain_t *test_chain, *test_chain_2, *test_chain_3;void *start_it( void *arg ) { swr_sdb_id mid[2],src,block_complex; swr_sdb_id split, tsd, rcd, mid_rx[2],encoder,decoder,sic, slicer,map; int i,j; double a11,a12,a21,a22; int sigma; double totalerr; double snr1 = 0.; double snr2 = 0.; double snr_1_temp = 0.; double snr_2_temp = 0.; int error; double ber = 0.; int sigma_array[ NOV ] = {10,25};//50,100,150,200,300,450,600,750};//1000,1200,1500, //1600,1700,1800,1900, //2000,2100,2200,2300,2500,2800,3000}; block_t ch_est_ant1, ch_est_ant2; SYMBOL_COMPLEX *ch_est_ant1_ptr, *ch_est_ant2_ptr; PR( "Setting up main-chain\n" ); test_chain = swr_chain_create(NEW_SPC_VAR( "random", src ), NEW_SPC_VAR( "test_data_send", tsd), NEW_SPC_VAR( "ldpc_encode", encoder), NEW_SPC_VAR( "mapper",map), 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_IN( "sic", sic, 1 ), NEW_SPC_VAR( "slicer", slicer ), NEW_SPC_VAR( "test_data_rcv", rcd ), CHAIN_END ); PR( "Connecting the test_data modules\n" ); swr_conn_add( tsd, 1, rcd, 1 ); 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( sic, 2), CHAIN_END ); for ( i=0; i<2; i++ ){ swr_sdb_set_config_int( mid[i], "circ_ext", 0 ); swr_sdb_set_config_int( mid_rx[i], "circ_ext", 0 ); } PR( "Linking sic with LDPC\n" ); test_chain_3 = swr_chain_create (OLD_SPC_OUT( sic, 1), NEW_SPC_VAR( "ldpc_decode_soft", decoder), OLD_SPC_IN( sic, 0), CHAIN_END ); PR( "Chains are set up\n" ); swr_sdb_set_config_int( block_complex, "precision", 16 ); swr_sdb_set_config_int( block_complex, "size", 1260 ); //Config Amplitude swr_sdb_set_config_int( mid[0], "amplitude", 2048 ); swr_sdb_set_config_int( mid[1], "amplitude", 2048 ); swr_sdb_set_config_int( map, "amplitude", 2048 ); swr_sdb_set_config_int( mid[1], "index", 1 ); swr_sdb_set_config_int( rcd, "wait", 1 ); swr_sdb_set_config_int( rcd, "mode", 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,"sic", sic ); swr_sdb_set_config_int( sic, "num_of_outer_loops", 5 ); swr_sdb_set_config_int( sic, "chest_1", mid_rx[0]); swr_sdb_set_config_int( sic, "chest_2", mid_rx[1]); swr_sdb_set_config_int( sic, "ldpc", decoder ); swr_sdb_set_config_int( sic, "data_always", 1 ); for (i = 0; i < NOV; i++) { sigma = sigma_array[i]; //sigma_array[1] snr1 = 0.; snr2 = 0.; totalerr = 0.; //PR( "Sending first message\n" ); for (j = 1; j <= NOS; j += 1 ) { a11 = getSigma(1.0); a12 = getSigma(1.0); a21 = getSigma(1.0); a22 = getSigma(1.0); swr_sdb_set_config_double( block_complex, "h11_real", a11 ); swr_sdb_set_config_double( block_complex, "h22_real", a22 ); swr_sdb_set_config_double( block_complex, "h12_real", a12 ); swr_sdb_set_config_double( block_complex, "h21_real", a21 ); //PR_DBG( 0, "Doing %i of %i loops\n", j, NOS ); 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( mid_rx[0], "num_of_antennas", 2); swr_sdb_set_config_int( mid_rx[1], "num_of_antennas", 2); // PR( "Sending to source\n" ); swr_sdb_call_module( src, 0 ); error = swr_sdb_get_stats_int( rcd, "error" ); snr1 += swr_sdb_get_stats_double( mid_rx[0], "snr" ); snr2 += swr_sdb_get_stats_double( mid_rx[1], "snr" ); 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; totalerr += error; ber = (double) totalerr / (j * 1000); //1000-> bcos the code we use has only 1000 information bits. Rate = 1000/4000 snr_1_temp = swr_sdb_get_stats_double( mid_rx[0], "snr" ); snr_2_temp = swr_sdb_get_stats_double( mid_rx[1], "snr" ); PR( "a11:%5.5g a12:%5.5g\n", a11,a12 ); PR( "a21:%5.5g a22:%5.5g\n", a21,a22 ); PR( "snr1: %5.5g snr2: %5.5g errors:%i\n", snr_1_temp,snr_2_temp,error ); PR( "\n" ); }//for NOS //PR("%g \t %g \t %g \t %g \t %g \t %g\n", a11,a12,a21,a22,0.5*(snr1 + snr2)/j, ber); } //for variance usleep(1000000); //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 ); PR_DBG( 0, "chain 3\n" ); swr_chain_destroy( test_chain_3 ); PR_DBG( 0, "chain 2\n" ); swr_chain_destroy( test_chain_2 ); PR_DBG( 0, "chain\n" ); 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 + -