⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 channel_real_input.c

📁 WCDMA的仿真程序,分别用C和MATLAB两种语言仿真
💻 C
📖 第 1 页 / 共 2 页
字号:
	      Q_collect += Qnputs[i_tmp] * channel[j];	    }      } /**/	  Iout[mem_len - i] = I_collect ; 	  Qout[mem_len - i] = Q_collect ;     }    /*        The chips in this call time (0 ...  nInputs - mem_len)  are only effected       byt this call times chips. For them the output is simple to define.       /**/    for(i = 0; i < nInputs - mem_len; i++) {      I_collect = 0;      Q_collect = 0;      for(j=0; j < taps; j++) {/**/	tmp_delay = mem_len - delay[j]; 	I_collect += Inputs[i  + tmp_delay] * channel[j];	Q_collect += Qnputs[i  + tmp_delay] * channel[j];      }	  Iout[i + mem_len] = I_collect;	  Qout[i + mem_len] = Q_collect;    }}/* -------------------------------------------------------------------- *//* * Function:    wcdma_conv * Desc.:       Channel response * * Note: *         channel_impulse and tap_delay vectors need to same length and *         their elements are corresponding, i.e. the tap_delay[i]  *         indicates how many chipintervals the channel_impulse  *         is delayd. The channel_impulse[i] indicates the attennuation *         coefficient.  * *        THE LAST ELEMENT OF tap_delay[i] VECTOR IMPLIES WHAT IS THE TOTAL *        DELAY FOR THE CHANNEL.  *//* -------------------------------------------------------------------- */int wcdma_channel_conv_double( 	     double  Inputs[],	        /* IN: input chip vector */	     double  Qnputs[],	        /* IN: input chip vector */	     int  nInputs,	        /* IN: input vector size */	     int  instance,	        /* IN: indicates the channel instance used/**/ 	     double Iout[],             /* OUT: output bit vector */	     double Qout[]              /* OUT: output bit vector */){    int i, j, i_tmp, tmp_delay, d_zero;    int  taps, mem_len;    double I_collect , Q_collect , noise,std_noise,tmp_noise ;    int  *delay;    double  *channel, *prev_I, *prev_Q;    channel_matrix_double *channel_datum_double;    /*      Get infromation about the used channel from the channel matrix      /**/          channel_datum_double = &channel_data_double[instance];    taps = channel_datum_double->n_taps;    std_noise = channel_datum_double->noise_std ;    /*        Current channel amplitudes and delays       /**/    channel = &channel_datum_double->cur_channel[0];    delay = &channel_datum_double->cur_delays[0];    mem_len = delay[taps -1];    /*      Get the last chips of previous call (stored in the channel_data_double)      /**/    prev_I = &(channel_datum_double->I_prev_chips[0]);    prev_Q = &(channel_datum_double->Q_prev_chips[0]);    /*        The first chips effect also the previous call time input chips.        /**/    for(i = mem_len ; i > 0; i--) {      I_collect = 0;    /* gathers all the multipaths signals for I /**/      Q_collect = 0;    /* and for Q/**/       d_zero = i - mem_len;      for(j = 0; j < taps; j++) {	    i_tmp = d_zero + delay[j]; 	    if( i_tmp > 0) {	      /* Use the stored chips to update the output		 /**/	      I_collect += prev_I[i_tmp - 1] * channel[j];	      Q_collect += prev_Q[i_tmp - 1] * channel[j];	    } 	    else {	      /* Use the new input chips  to update the output		 /**/	      i_tmp = abs(i_tmp);	      I_collect += Inputs[i_tmp] * channel[j];	      Q_collect += Qnputs[i_tmp] * channel[j];	    }      } /**/      /* Adding noise to each chip	 scale the random number to -1 ... 1	 multiply it by std_noise, see channel_init() function	 /**/      noise = std_noise * ( 2 * (rand() / MAX_RANDOM)   - 1);      Iout[mem_len - i] = I_collect + noise;  /* add noise here 23.4.1999/**/      Qout[mem_len - i] = Q_collect + noise;  /* add noise here 23.4.1999/**/    }    /*        The chips in this call time (0 ...  nInputs - mem_len)  are only effected       byt this call times chips. For them the output is simple to define.      /**/    for(i=0; i < nInputs - mem_len; i++) {      I_collect = 0;      Q_collect = 0;      for(j=0; j < taps; j++) {/**/	tmp_delay = mem_len - delay[j]; 	I_collect += Inputs[i  + tmp_delay] * channel[j];	Q_collect += Qnputs[i  + tmp_delay] * channel[j];      }      /* Adding noise to each chip	 scale the random number to -1 ... 1	 multiply it by std_noise, see channel_init() function	 /**/      noise = std_noise * ( 2 * (rand() / MAX_RANDOM)   - 1);      Iout[i + mem_len] = I_collect + noise;      Qout[i + mem_len] = Q_collect + noise;    }}/* -------------------------------------------------------------------- *//* * Function:    wcdma_update_channel * Desc.:       Updates the channel amplitudes and delays if necessary * * * Returns:	0  * * Note:        This fucntion is only called for random and interpolating *              channels.    *  *//* -------------------------------------------------------------------- */int wcdma_update_channel_double(  	     channel_matrix_double *data  /* IN/OUT channel data /**/  ){  int i,j,i_tmp;  int index = data->cur_impulse;  double impulse_tmp;   /*      RANDOM CHANNEL update     /**/    if ( data->mode ==  RANDOM){      /*	Randomly selects the impulse which will be used next	/**/      i_tmp = rand();      impulse_tmp  = i_tmp / MAX_RANDOM ; /*((double)32767); /*(2^15)-1);/**/      for (i = 0; i < data->n_impulses; i++){	if (impulse_tmp < data->cumul_prob[i]){	  /* 	     Update the current channel amplitude and delay /**/	  for (j = 0; j < data->n_taps; j++){	    data->cur_channel[j] = data->amplitudes[i][j];	    data->cur_delays[j] = data->delays[i][j];	  }	  /* 	     Set the cur_impulse to point in the right index/**/	    data->cur_impulse = i;	    break;	} /* IF /**/      }    return (0);    }  /*      INTERPOLATING CHANNEL update     /**/        /* just to make sure no overflows ocuur/**/    if (data->use[index] <= data->max[index]){      for (i = 0; i < data->n_taps; i++){	/* 	   add one times the derivate of channel amplitude to current channel/**/	data->cur_channel[i] += data->amplitudes[index][i];	/* 	   Check that the the change does not make the amplitude below zero /**/	if( data->cur_channel[i] < 0 ) data->cur_channel[i] = 0;	/* 	   Update the channel delay tap if necessary 	   In initialization for each channel impulse a number of timesteps 	   has been calculated when the delay taps should be changes. The sign 	   of the number of taps indicate if the delay increases or decreases.	   number of timesteps is saved to :  data->delays[index][i]	   /**/	if ( ( data->use[index] > 0 ) && (data->delays[index][i] != 0))	  if( (data->use[index] % abs(data->delays[index][i])) == 0){	    if( data->delays[index][i] > 0)	      data->cur_delays[i] += 1 ;	    else 	      data->cur_delays[i] -= 1 ;	    /* 	       Check that the the change does not make the delay below zero /**/	    	    if (data->cur_delays[i] < 0) data->cur_delays[i] = 0 ;	  }	      }      /*	After each timestep (i.e. function call) the number of timesteps	is updated for the current channel impulse.	/**/      data->use[index] += 1;    }        /*      If the current channel impulse has been the used for max number of       timesteps, move to next channel impulse.            /**/    if ( data->use[index] == data->max[index]){      data->cur_impulse += 1 ;    }    return(0);}/* -------------------------------------------------------------------- *//* * Function:    wcdma_update_memory_chips * * Desc.:       Stores the last chips of the curent input block  * * Returns:	0 *  * Note:        Stores always the max_memory number of chips *              to make sure that enough chips are saved also *              when the channel delays vary.   *//* -------------------------------------------------------------------- */int wcdma_update_memory_chips_double(             double  Inputs[],	        /* IN: input chip vector */	     double  Qnputs[],	        /* IN: input chip vector */	     int nInputs,               /* IN: length input chip vector */	     channel_matrix_double *data  /* IN/OUT channel data /**/  ){  int i,memory_length;  memory_length = data->max_memory;     /*        Store the last memory_length chips to the memory        for the next call time. */  for( i = 0; i< memory_length;  i++){    data->I_prev_chips[i]  =  Inputs[nInputs - (i + 1)];    data->Q_prev_chips[i]  =  Qnputs[nInputs - (i + 1)];      } return(0);}/* -------------------------------------------------------------------- *//* * Function:    wcdma_channel_free * Desc.:       channel clear function. * * Returns:	0 *  * Note: *//* -------------------------------------------------------------------- */int wcdma_channel_free_double(int instance){  free(channel_data_double[instance].I_prev_chips);  free(channel_data_double[instance].Q_prev_chips);     channel_alloc_list_double[instance] = FREE_INSTANCE;  channel_index_double--;  if (channel_index_double == 0) general_channel_init_flag_double = FALSE;  return(0);}/* -------------------------------------------------------------------- *//* * Function:    wcdma_channel_print * * Desc.:       Prints the channle matrix data * * Note:        For testing purposes only *//* -------------------------------------------------------------------- */void channel_print_double(int instance){    int tmp,i,j ;    int nTaps,mem_len,nimp,mode;    double std_noise;    channel_matrix_double *channel_datum_double;    int  *delay;    double  *channel, *prev_I, *prev_Q;    channel_datum_double = &channel_data_double[instance];    mode = channel_datum_double->mode;    nTaps = channel_datum_double->n_taps;    mem_len = channel_datum_double->cur_delays[channel_datum_double->n_taps -1];    std_noise = channel_datum_double->noise_std ;    nimp = channel_datum_double->n_impulses;    delay = &channel_datum_double->cur_delays[0];    channel = &channel_datum_double->cur_channel[0];    prev_I = &(channel_datum_double->I_prev_chips[0]);    prev_Q = &(channel_datum_double->Q_prev_chips[0]);    printf("\n");    printf("instance: %d  mode: %d  nTaps: %d  nImpulses: %d  cur_mem_len: %d cur: %d mem_len %d\n", 	   instance, mode,nTaps,nimp,mem_len,channel_datum_double->cur_impulse,channel_datum_double->max_memory );    printf("Curent impulse \t");    for(i = 0; i < nTaps; i++){      printf("%.2f  ",channel_datum_double->cur_channel[i]);/**/    }    printf("\nCurent delay \t");    for(i = 0; i < nTaps; i++){      printf("%d    ",channel_datum_double->cur_delays[i]); /*,channel_datum_double->cur_real_delays[i]);/**/    }    printf("\n");    if(mode >1){      printf("\nAmplitudes \t");      for(j = 0; j<nimp; j++){	for(i = 0; i < nTaps; i++){	  printf("%.2f  ",channel_datum_double->amplitudes[j][i] );/**/	}	printf("\n");      }      printf("\nDelays \t");      for(j = 0; j<nimp; j++){	for(i = 0; i < nTaps; i++){	  printf("%d ",channel_datum_double->delays[j][i]);/*,channel_datum_double->delay_diff[j][i] );/**/	  	}	printf("\n");      }      printf("\nmax \t");      for(j = 0; j<nimp; j++){	printf("%d  ",channel_datum_double->max[j] );/**/      }      printf("\nuse \t");      for(j = 0; j<nimp; j++){	printf("%d  ",channel_datum_double->use[j] );/**/      }      printf("\n");          }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -