Commit cd2a5347 authored by Xiwen JIANG's avatar Xiwen JIANG

intergrate estiamte_DLSCI_from_ULCSI into dlsim_tm7

parent f50df1bf
......@@ -1841,7 +1841,7 @@ target_link_libraries (oaisim_nos1 ${T_LIB})
# Unitary tests for each piece of L1: example, mbmssim is MBMS L1 simulator
#####################################
foreach(myExe dlsim ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim)
foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim)
add_executable(${myExe}
${OPENAIR_BIN_DIR}/messages_xml.h
${OPENAIR1_DIR}/SIMULATION/LTE_PHY/${myExe}.c
......@@ -1922,6 +1922,7 @@ if (${T_TRACER})
add_dependencies(oaisim generate_T)
add_dependencies(oaisim_nos1 generate_T)
add_dependencies(dlsim generate_T)
add_dependencies(dlsim_tm7 generate_T)
add_dependencies(ulsim generate_T)
add_dependencies(pbchsim generate_T)
add_dependencies(scansim generate_T)
......
......@@ -1226,6 +1226,7 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
common_vars->txdata[eNB_id] = (int32_t**)malloc16(fp->nb_antennas_tx*sizeof(int32_t*));
common_vars->txdataF[eNB_id] = (int32_t **)malloc16(NB_ANTENNA_PORTS_ENB*sizeof(int32_t*));
common_vars->txdataF_BF[eNB_id] = (int32_t **)malloc16(fp->nb_antennas_tx*sizeof(int32_t*));
common_vars->tdd_calib_coeffs[eNB_id] = (int32_t **)malloc16(fp->nb_antennas_tx*sizeof(int32_t*));
for (i=0; i<14; i++) {
common_vars->txdataF[eNB_id][i] = (int32_t*)malloc16_clear(fp->ofdm_symbol_size*fp->symbols_per_tti*10*sizeof(int32_t) );
......@@ -1238,6 +1239,8 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
for (i=0; i<fp->nb_antennas_tx; i++) {
common_vars->txdataF_BF[eNB_id][i] = (int32_t*)malloc16_clear(fp->ofdm_symbol_size*sizeof(int32_t) );
common_vars->tdd_calib_coeffs[eNB_id][i] = (int32_t*)malloc16_clear(fp->ofdm_symbol_size*sizeof(int32_t) );
if (eNB->node_function != NGFI_RCC_IF4p5)
common_vars->txdata[eNB_id][i] = (int32_t*)malloc16_clear(fp->samples_per_tti*10*sizeof(int32_t) );
......
......@@ -161,7 +161,6 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_
dlsch->calib_dl_ch_estimates = (int32_t**)malloc16(frame_parms->nb_antennas_tx*sizeof(int32_t*));
for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
dlsch->calib_dl_ch_estimates[aa] = (int32_t *)malloc16(OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t));
}
for (i=0; i<10; i++)
......
......@@ -64,15 +64,16 @@ int beam_precoding(int32_t **txdataF,
memset(txdataF_BF[aa],0,sizeof(int32_t)*(frame_parms->ofdm_symbol_size));
for (p=0; p<14; p++) {
//if (p==0 || p==1 || p==4 || p==5 || p>=7)
//multadd_cpx_vector((int16_t*)txdataF[p],(int16_t*)beam_weights[p][aa], (int16_t*)txdataF_BF[aa], 0, frame_parms->ofdm_symbol_size, 15);
/*
if (p==0 || p==1 || p==5)
multadd_cpx_vector((int16_t*)txdataF[p],(int16_t*)beam_weights[p][aa], (int16_t*)txdataF_BF[aa], 0, frame_parms->ofdm_symbol_size, 15);
*/
for (re=0;re<frame_parms->ofdm_symbol_size;re++) {
if ((p==0 || p==1 || p==4 || p==5 || p>=7) && txdataF[p][slot_offset_F+symbol*frame_parms->ofdm_symbol_size+re]!=0) {
if ((p==0 || p==1 || p==5) && txdataF[p][slot_offset_F+symbol*frame_parms->ofdm_symbol_size+re]!=0) {
((int16_t*)&txdataF_BF[aa][re])[0] += (int16_t)((((int16_t*)&txdataF[p][slot_offset_F+symbol*frame_parms->ofdm_symbol_size+re])[0]*((int16_t*)&beam_weights[p][aa][re])[0])>>15);
((int16_t*)&txdataF_BF[aa][re])[0] -= (int16_t)((((int16_t*)&txdataF[p][slot_offset_F+symbol*frame_parms->ofdm_symbol_size+re])[1]*((int16_t*)&beam_weights[p][aa][re])[1])>>15);
((int16_t*)&txdataF_BF[aa][re])[1] += (int16_t)((((int16_t*)&txdataF[p][slot_offset_F+symbol*frame_parms->ofdm_symbol_size+re])[0]*((int16_t*)&beam_weights[p][aa][re])[1])>>15);
((int16_t*)&txdataF_BF[aa][re])[1] += (int16_t)((((int16_t*)&txdataF[p][slot_offset_F+symbol*frame_parms->ofdm_symbol_size+re])[1]*((int16_t*)&beam_weights[p][aa][re])[0])>>15);
/*
printf("beamforming.c:txdataF[%d][%d]=%d+j%d, beam_weights[%d][%d][%d]=%d+j%d,txdata_BF[%d][%d]=%d+j%d\n",
p,slot_offset_F+symbol*frame_parms->ofdm_symbol_size+re,
......
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h> // contains the header information or prototype of the malloc
#include "UTIL/LOG/log.h"
#include "PHY/impl_defs_lte.h"
int f_read(char *calibF_fname, int nb_ant, int nb_freq, int32_t **tdd_calib_coeffs){
int read_calibration_matrix(int32_t **tdd_calib_coeffs, char *calibF_fname, LTE_DL_FRAME_PARMS *frame_parms) {
FILE *calibF_fd;
int i,j,l,calibF_e;
calibF_fd = fopen(calibF_fname,"r");
if (calibF_fd) {
printf("Loading Calibration matrix from %s\n", calibF_fname);
FILE *calibF_fd ;
int aa,re,calibF_e ;
printf("Number of antennas = %d\n", frame_parms->nb_antennas_tx) ;
printf("OFDM symbol size = %d\n", frame_parms->ofdm_symbol_size) ;
calibF_fd = fopen(calibF_fname,"r") ;
if (calibF_fd == NULL) {
printf("ERR: %s not found, running with defaults\n", calibF_fname);
return 1;
}
printf("Loading Calibration matrix from %s\n", calibF_fname);
for(i=0;i<nb_ant;i++){
for(j=0;j<nb_freq*2;j++){
fscanf(calibF_fd, "%d", &calibF_e);
tdd_calib_coeffs[i][j] = (int16_t)calibF_e;
}
for (aa=0;aa<frame_parms->nb_antennas_tx;aa++) {
for(re=0;re<frame_parms->ofdm_symbol_size;re++) {
fscanf(calibF_fd, "%d", &calibF_e) ;
printf("aa=%d, re=%d, tdd_calib[0]=%d\n", aa, re, calibF_e);
((int16_t*)(&tdd_calib_coeffs[aa][re]))[0] = calibF_e;
fscanf(calibF_fd, "%d", &calibF_e) ;
printf("aa=%d, re=%d, tdd_calib[1]=%d\n", aa, re, calibF_e);
((int16_t*)(&tdd_calib_coeffs[aa][re]))[1] = calibF_e;
//printf("aa=%d, re=%d, tdd_calib=%d+i%d\n", aa, re, (int16_t*)(&tdd_calib_coeffs[aa][re])[0],(int16_t*)(&tdd_calib_coeffs[aa][re])[1]);
}
printf("%d\n",(int)tdd_calib_coeffs[0][0]);
printf("%d\n",(int)tdd_calib_coeffs[1][599]);
} else
printf("%s not found, running with defaults\n",calibF_fname);
}
}
void estimate_DLCSI_from_ULCSI(int32_t **calib_dl_ch_estimates, int32_t **ul_ch_estimates, int32_t **tdd_calib_coeffs, LTE_DL_FRAME_PARMS *frame_parms) {
int aa,re;
int estimate_DLCSI_from_ULCSI(int32_t **calib_dl_ch_estimates, int32_t **ul_ch_estimates, int32_t **tdd_calib_coeffs, int nb_ant, int nb_freq) {
for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
/*multadd_cpx_vector((int16_t*)(&tdd_calib_coeffs[aa][0]),(int16_t*)(&ul_ch_estimates[aa][0]),(int16_t*)(&calib_dl_ch_estimates[aa][0]),1,nb_freq,15);*/
for (re=0; re<frame_parms->ofdm_symbol_size; re++) {
((int16_t*)(&calib_dl_ch_estimates[aa][re]))[0] += (((int16_t*)(&tdd_calib_coeffs[aa][re]))[0]*((int16_t*)(&ul_ch_estimates[aa][re]))[0])>>15;
((int16_t*)(&calib_dl_ch_estimates[aa][re]))[0] -= (((int16_t*)(&tdd_calib_coeffs[aa][re]))[1]*((int16_t*)(&ul_ch_estimates[aa][re]))[1])>>15;
((int16_t*)(&calib_dl_ch_estimates[aa][re]))[1] += (((int16_t*)(&tdd_calib_coeffs[aa][re]))[0]*((int16_t*)(&ul_ch_estimates[aa][re]))[1])>>15;
((int16_t*)(&calib_dl_ch_estimates[aa][re]))[1] += (((int16_t*)(&tdd_calib_coeffs[aa][re]))[1]*((int16_t*)(&ul_ch_estimates[aa][re]))[0])>>15;
/*printf("aa=%d, re=%d tdd_calib_coeffs= (%d, %d), ul_ch_estimates = (%d, %d), calib_dl_ch_estimates = (%d, %d)\n",
aa, re,
((int16_t*)&tdd_calib_coeffs[aa][re])[0], ((int16_t*)&tdd_calib_coeffs[aa][re])[1],
((int16_t*)&ul_ch_estimates[aa][re])[0], ((int16_t*)&ul_ch_estimates[aa][re])[1],
((int16_t*)&calib_dl_ch_estimates[aa][re])[0], ((int16_t*)&calib_dl_ch_estimates[aa][re])[1]);*/
}
}
}
int compute_BF_weights(int32_t **beam_weights, int32_t **calib_dl_ch_estimates, PRECODE_TYPE_t precode_type, int nb_ant, int nb_freq) {
void compute_BF_weights(int32_t **beam_weights, int32_t **calib_dl_ch_estimates, PRECODE_TYPE_t precode_type, LTE_DL_FRAME_PARMS *frame_parms) {
int aa, re;
switch (precode_type) {
//case MRT
case 0 :
case MRT :
for (aa=0 ; aa<frame_parms->nb_antennas_tx ; aa++) {
for (re=0; re<frame_parms->ofdm_symbol_size; re++) {
((int16_t*)(&beam_weights[aa][re]))[0] = ((int16_t*)(&calib_dl_ch_estimates[aa][re]))[0];
((int16_t*)(&beam_weights[aa][re]))[1] = -((int16_t*)(&calib_dl_ch_estimates[aa][re]))[1];
//Normalisation not implemented
}
}
break ;
//case ZF
case ZF :
break;
case 1 :
//case MMSE
case MMSE :
break;
case 2 :
break;
default :
break;
}
}
}
// temporal test function
//unitary test function
/*
void main(){
// initialization
// compare
printf("Hello world!\n");
void main() {
printf("Test Compute BF weights.\n");
int32_t **tdd_calib_coeffs, **calib_dl_ch_estimates, **ul_ch_estimates, **beam_weights;
int nb_ant, nb_freq, aa, re;
char calibF_fname[] = "calibF.m";
char BF_fname[] = "BF_weights.m";
FILE *BF_weights_fd;
nb_ant = 8;
nb_freq = 300;
// memory allocation
tdd_calib_coeffs = (int32_t **)malloc(nb_ant*sizeof(int32_t *));
calib_dl_ch_estimates = (int32_t **)malloc(nb_ant*sizeof(int32_t *));
ul_ch_estimates = (int32_t **)malloc(nb_ant*sizeof(int32_t *));
beam_weights = (int32_t **)malloc(nb_ant*sizeof(int32_t *));
for (aa=0; aa<nb_ant; aa++) {
tdd_calib_coeffs[aa] = (int32_t *)malloc(nb_freq*sizeof(int32_t));
calib_dl_ch_estimates[aa] = (int32_t *)malloc(nb_freq*sizeof(int32_t));
ul_ch_estimates[aa] = (int32_t *)malloc(nb_freq*sizeof(int32_t));
beam_weights[aa] = (int32_t *)malloc(nb_freq*sizeof(int32_t));
}
// ul channel estimation initilisation
for (aa=0; aa<nb_ant; aa++)
for (re=0; re<nb_freq; re++)
ul_ch_estimates[aa][re] = 0x7fff7fff;
// calibration coefficients loading
read_calibration_matrix(calibF_fname, nb_ant, nb_freq, tdd_calib_coeffs);
// DL calib channel estimation
estimate_DLCSI_from_ULCSI(calib_dl_ch_estimates, ul_ch_estimates, tdd_calib_coeffs, nb_ant, nb_freq);
// Beamforming weights calculation
compute_BF_weights(beam_weights, calib_dl_ch_estimates, MRT, nb_ant, nb_freq);
// writing beam_weights into a .m file
BF_weights_fd = fopen(BF_fname,"w");
for (aa=0; aa<nb_ant; aa++) {
for (re=0; re<nb_freq; re++) {
fprintf(BF_weights_fd, "%d", ((int16_t *)&beam_weights[aa][re])[0]);
fprintf(BF_weights_fd, "%s", " ");
fprintf(BF_weights_fd, "%d", ((int16_t *)&beam_weights[aa][re])[1]);
fprintf(BF_weights_fd, "%s", " ");
}
fprintf(BF_weights_fd, "\n");
}
}
*/
......@@ -121,11 +121,11 @@ int beam_precoding(int32_t **txdataF,
int symbol,
int aa);
int f_read(char *calibF_fname, int nb_ant, int nb_freq, int32_t **tdd_calib_coeffs);
int read_calibration_matrix(int32_t **tdd_calib_coeffs, char *calibF_fname, LTE_DL_FRAME_PARMS *frame_parms);
int estimate_DLCSI_from_ULCSI(int32_t **calib_dl_ch_estimates, int32_t **ul_ch_estimates, int32_t **tdd_calib_coeffs, int nb_ant, int nb_freq);
int estimate_DLCSI_from_ULCSI(int32_t **calib_dl_ch_estimates, int32_t **ul_ch_estimates, int32_t **tdd_calib_coeffs, LTE_DL_FRAME_PARMS *frame_parms);
int compute_BF_weights(int32_t **beam_weights, int32_t **calib_dl_ch_estimates, PRECODE_TYPE_t precode_type, int nb_ant, int nb_freq);
int compute_BF_weights(int32_t **beam_weights, int32_t **calib_dl_ch_estimates, PRECODE_TYPE_t precode_type, LTE_DL_FRAME_PARMS *frame_parms);
#endif
......
......@@ -121,8 +121,9 @@ int main(int argc, char **argv)
uint8_t extended_prefix_flag=0,transmission_mode=1,n_tx_port=1,n_tx_phy=1,n_rx=1;
uint16_t Nid_cell=0;
int32_t **cell_spec_bf_weights;
//int32_t **cell_spec_bf_weights;
int32_t *ue_spec_bf_weights;
uint8_t tdd_calib=0;
int eNB_id = 0, eNB_id_i = 1;
unsigned char mcs1=0,mcs2=0,mcs_i=0,dual_stream_UE = 0,awgn_flag=0,round,dci_flag=0;
......@@ -261,7 +262,7 @@ int main(int argc, char **argv)
// num_layers = 1;
perfect_ce = 0;
while ((c = getopt (argc, argv, "ahdpZDe:Em:n:o:s:f:t:c:g:r:F:x:p:y:z:AM:N:I:i:O:R:S:C:T:b:u:v:w:B:PLl:XY")) != -1) {
while ((c = getopt (argc, argv, "ahdpZDe:Em:n:o:s:f:t:c:g:r:F:x:p:y:z:AM:N:I:i:O:R:S:C:T:b:u:v:w:B:PLl:WXY")) != -1) {
switch (c) {
case 'a':
awgn_flag = 1;
......@@ -531,6 +532,10 @@ int main(int argc, char **argv)
break;
case 'W':
tdd_calib=1;
break;
case 'X':
xforms=1;
break;
......@@ -987,9 +992,10 @@ int main(int argc, char **argv)
eNB->UE_stats[1].DL_pmi_single = 0;
}
//TODO: allocate memory for calibration matrix and calib_dl_ch_estimates in init_lte.c
//for first tests initialze calibration matrix with idendity
//read_calibration_matrix(calib_fname, nb_ant, nb_freq, eNB->common_vars.tdd_calib_coeffs[0]);
printf("tdd_calib = %d\n", tdd_calib);
if (tdd_calib == 1)
//for first tests initialze calibration matrix with idendity
read_calibration_matrix(eNB->common_vars.tdd_calib_coeffs[0], "calibF.m", frame_parms);
if (input_fd==NULL) {
......@@ -2140,32 +2146,33 @@ int main(int argc, char **argv)
hold_channel = 0;//(round==0) ? 0 : 1;
PMI_FEEDBACK:
//make sure dlsim is called with perfect channel estimation option (for freq_channel)
//fill drs_ch_estimates with data from eNB2UE->chF
for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
for (i=0; i<frame_parms->N_RB_DL*12; i++) {
for (l=0; l<frame_parms->symbols_per_tti; l++) {
((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
//printf("x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP);
((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
}
if (tdd_calib == 1) {
//make sure dlsim is called with perfect channel estimation option (for freq_channel)
//fill drs_ch_estimates with data from eNB2UE->chF
for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
for (i=0; i<frame_parms->N_RB_DL*12; i++) {
for (l=0; l<frame_parms->symbols_per_tti; l++) {
((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
//printf("x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP);
((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
}
}
}
}
}
estimate_DLCSI_from_ULCSI(eNB->dlsch[0][0]->calib_dl_ch_estimates,
&eNB->pusch_vars[0]->drs_ch_estimates[0][0/*position of second DMRS*/],
eNB->common_vars.tdd_calib_coeffs[0],
frame_parms->nb_antennas_tx,
frame_parms->N_RB_DL*12);
estimate_DLCSI_from_ULCSI(eNB->dlsch[0][0]->calib_dl_ch_estimates,
&eNB->pusch_vars[0]->drs_ch_estimates[0][0],//position of second DMRS
eNB->common_vars.tdd_calib_coeffs[0],
frame_parms);
compute_BF_weights(eNB->dlsch[0][0]->ue_spec_bf_weights[0],
eNB->dlsch[0][0]->calib_dl_ch_estimates,
MRT,
frame_parms->nb_antennas_tx,
frame_parms->N_RB_DL*12);
/*compute_BF_weights(eNB->dlsch[0][0]->ue_spec_bf_weights[0],
eNB->dlsch[0][0]->calib_dl_ch_estimates,
MRT,
frame_parms);*/
}
//printf("Trial %d : Round %d, pmi_feedback %d \n",trials,round,pmi_feedback);
for (aa=0; aa<NB_ANTENNA_PORTS_ENB; aa++) {
......@@ -2831,15 +2838,19 @@ PMI_FEEDBACK:
}
*/
do_OFDM_mod_symbol(&eNB->common_vars,
eNB_id,
(subframe*2),
&eNB->frame_parms);
for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
do_OFDM_mod_symbol(&eNB->common_vars,
eNB_id,
(subframe*2),
&eNB->frame_parms,
aa);
do_OFDM_mod_symbol(&eNB->common_vars,
eNB_id,
(subframe*2)+1,
&eNB->frame_parms);
do_OFDM_mod_symbol(&eNB->common_vars,
eNB_id,
(subframe*2)+1,
&eNB->frame_parms,
aa);
}
stop_meas(&eNB->ofdm_mod_stats);
stop_meas(&eNB->phy_proc_tx);
......@@ -2849,6 +2860,13 @@ PMI_FEEDBACK:
(subframe*2)+2,
&eNB->frame_parms); */
for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++)
do_OFDM_mod_symbol(&eNB->common_vars,
eNB_id,
(subframe*2)+2,
&eNB->frame_parms,
aa);
if (n_frames==1) {
if (transmission_mode<7)
write_output("txsigF0.m","txsF0", &eNB->common_vars.txdataF[eNB_id][0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],
......
......@@ -1329,8 +1329,8 @@ void init_openair0() {
openair0_cfg[card].num_rb_dl=frame_parms[0]->N_RB_DL;
openair0_cfg[card].tx_num_channels=min(2,((UE_flag==0) ? PHY_vars_eNB_g[0][0]->frame_parms.nb_antennas_tx : PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_tx));
openair0_cfg[card].rx_num_channels=min(2,((UE_flag==0) ? PHY_vars_eNB_g[0][0]->frame_parms.nb_antennas_rx : PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_rx));
openair0_cfg[card].tx_num_channels=min(4,((UE_flag==0) ? PHY_vars_eNB_g[0][0]->frame_parms.nb_antennas_tx : PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_tx));
openair0_cfg[card].rx_num_channels=min(4,((UE_flag==0) ? PHY_vars_eNB_g[0][0]->frame_parms.nb_antennas_rx : PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_rx));
for (i=0; i<4; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment