📄 fading_multi.c
字号:
/*************************************************************************** fading_multi.c - Module for a complex multi-path fading noise channel ------------------- begin : 2002 authors : Linus Gasser emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description 03-01-17 - ineiti - begin **************************************************************************//*************************************************************************** * * * 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 <math.h>#include <stdlib.h>#include "system.h"#include "debugging.h"#include "server.h"#define DBG_LVL 0/** * @short a simple fading channel with no reflexions */double path_loss_fading_multi[MAX_CLIENTS][MAX_CLIENTS], noise;double u,v;double alpha, w;unsigned short simrand[3];// The variance of the Gaussian noisedouble sigma = 200;/** * @short initialises the channel */void fading_multi_init() { int t, i, j; struct timeval tp; // Set the white noise to 0 noise = 0; // initialize the random generator gettimeofday(&tp,NULL); simrand[0]=(unsigned short)(tp.tv_sec&0177777); simrand[1]=(unsigned short)((tp.tv_sec>>12)&0177777); simrand[2]=(unsigned short)((tp.tv_sec>>24)&0177777); // Creates default unitary channels and one 0-channel for ( i=0; i< MAX_CLIENTS; i++ ) { PR_DBG( 4, "Receiver %i with gid %i \n", i,client[i].gid ); for( j = 0; j < MAX_CLIENTS; j++){ PR_DBG( 4, " Sender %i with gid %i \n ", j,client[j].gid ); for ( t=0; t<CHANNEL_LENGTH; t++ ) { //Channel set for BS->MS channel_tap[ i ][ j ][ t ] = (t == 0) * (i<MAX_CLIENTS); PR_DBG_CL( 2, "%i ", (int)channel_tap[ i ][ j ][ t ] ); } PR_DBG_CL( 2, "\n" ); } }}#define sign(x) ((x)>=0?1:-1)/** * @short calculates the fading */void fading_multi_calc( int nb_clients, int max_gid ) { int n,i,j, t; short *rx, *tx; int res,MIMO; double taps[ CHANNEL_LENGTH ]; double gain; //The first 'MIMO' entries correspond to Tx-Rx antennas in the BS MIMO=(max_gid)/2; //MIMO=1; for ( i = 0; i < MAX_CLIENTS; i++ ) { if ( client[i].id == -1 ) { continue; } // For all receiving clients rx = (short*)rx_signal_buffer[i][BLOCK_ACT_RX(tx_block)]; // initialized to zero memset( rx, 0, DAQ_DMA_BLOCK_SIZE_BYTES ); for (j=0;j<MAX_CLIENTS;j++) { if ( ( client[j].id == -1 ) || ( j == i ) ) { continue; } if ( client[j].gid == client[i].gid ) { continue; } // And all sending clients gain = 100. / ( 1 << 14 ) * rx_gain[i] * tx_gain[j]; // Some debugging stuff if ( !( tx_block % 100 ) ) { PR_DBG( 2, "tx_gain[%i] = %e, rx_gain[%i] = %e\n", j, tx_gain[j], i, rx_gain[i] ); PR_DBG( 2, "From %i to %i, gain %e\n", j, i, gain ); PR_DBG( 2, "Taps: " ); } // Initialise the channel-taps for ( t=0; t<CHANNEL_LENGTH; t++ ) { taps[ t ] = channel_tap[ i ][ j ][ t ] * gain; // And some more debugging if ( !( tx_block % 100 ) ) { PR_DBG_CL( 2, "%g ", taps[ t ] ); } } // Still more debugging if ( !( tx_block % 100 ) ) { PR_DBG_CL( 2, "\n" ); } tx = (short*)tx_signal_buffer[j][BLOCK_ACT_TX(tx_block)]; // Do the convolution for ( n = 0; n < DAQ_DMA_BLOCK_SIZE_SAMPLES; n++ ) { res = 0; for ( t=0; t<CHANNEL_LENGTH; t++ ) { res += tx[n - t] * taps[ t ]; } // rx[n] += res; do { u = 2*erand48(simrand)-1; v = 2*erand48(simrand)-1; w = u*u + v*v; } while (w>=1); alpha = sqrt(-2*log(w)/w); rx[n] += res + sigma*alpha*u; rx[n] = max( rx[n], (short int)-2048 ); rx[n] = min( rx[n], (short int)2047 ); } } // Some reality-check: the output has to fit into 12 bits for ( n = 0; n < DAQ_DMA_BLOCK_SIZE_SAMPLES; n++ ) { if ( abs( rx[n] ) > ( 1 << 11 ) ) { rx[n] = ( 1 << 11 ) * sign( rx[n] ); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -