Commit f62095fb authored by Sakthivel Velumani's avatar Sakthivel Velumani

Updated nr_dlsim to generate matlab files

Updated matlab file write function to write multiple vectors to a single file.
parent 3776379e
...@@ -88,7 +88,8 @@ int write_file_matlab(const char *fname, ...@@ -88,7 +88,8 @@ int write_file_matlab(const char *fname,
void *data, void *data,
int length, int length,
int dec, int dec,
char format) char format,
int multiVec)
{ {
FILE *fp=NULL; FILE *fp=NULL;
int i; int i;
...@@ -98,7 +99,7 @@ int write_file_matlab(const char *fname, ...@@ -98,7 +99,7 @@ int write_file_matlab(const char *fname,
//printf("Writing %d elements of type %d to %s\n",length,format,fname); //printf("Writing %d elements of type %d to %s\n",length,format,fname);
if (format == 10 || format ==11 || format == 12 || format == 13 || format == 14) { if (format == 10 || format ==11 || format == 12 || format == 13 || format == 14 || multiVec) {
fp = fopen(fname,"a+"); fp = fopen(fname,"a+");
} else if (format != 10 && format !=11 && format != 12 && format != 13 && format != 14) { } else if (format != 10 && format !=11 && format != 12 && format != 13 && format != 14) {
fp = fopen(fname,"w+"); fp = fopen(fname,"w+");
...@@ -109,7 +110,7 @@ int write_file_matlab(const char *fname, ...@@ -109,7 +110,7 @@ int write_file_matlab(const char *fname,
return(-1); return(-1);
} }
if (format != 10 && format !=11 && format != 12 && format != 13 && format != 14) if ((format != 10 && format !=11 && format != 12 && format != 13 && format != 14) || multiVec)
fprintf(fp,"%s = [",vname); fprintf(fp,"%s = [",vname);
switch (format) { switch (format) {
...@@ -216,7 +217,7 @@ int write_file_matlab(const char *fname, ...@@ -216,7 +217,7 @@ int write_file_matlab(const char *fname,
break; break;
} }
if (format != 10 && format !=11 && format !=12 && format != 13 && format != 15) { if ((format != 10 && format !=11 && format !=12 && format != 13 && format != 15) || multiVec) {
fprintf(fp,"];\n"); fprintf(fp,"];\n");
fclose(fp); fclose(fp);
return(0); return(0);
......
...@@ -335,8 +335,9 @@ typedef struct { ...@@ -335,8 +335,9 @@ typedef struct {
@param length length of data vector to output @param length length of data vector to output
@param dec decimation level @param dec decimation level
@param format data format (0 = real 16-bit, 1 = complex 16-bit,2 real 32-bit, 3 complex 32-bit,4 = real 8-bit, 5 = complex 8-bit) @param format data format (0 = real 16-bit, 1 = complex 16-bit,2 real 32-bit, 3 complex 32-bit,4 = real 8-bit, 5 = complex 8-bit)
@param multiVec create new file or append to existing (useful for writing multiple vectors to same file. Just call the function multiple times with same file name and with this parameter set to 1)
*/ */
int32_t write_file_matlab(const char *fname, const char *vname, void *data, int length, int dec, char format); int32_t write_file_matlab(const char *fname, const char *vname, void *data, int length, int dec, char format, int multiVec);
/*----------------macro definitions for reading log configuration from the config module */ /*----------------macro definitions for reading log configuration from the config module */
#define CONFIG_STRING_LOG_PREFIX "log_config" #define CONFIG_STRING_LOG_PREFIX "log_config"
...@@ -396,7 +397,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int ...@@ -396,7 +397,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
/* bitmask dependent macros, to generate debug file such as matlab file or message dump */ /* bitmask dependent macros, to generate debug file such as matlab file or message dump */
# define LOG_DUMPFLAG(D) (g_log->dump_mask & D) # define LOG_DUMPFLAG(D) (g_log->dump_mask & D)
# define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)/* */ # define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format, 0);} while(0)/* */
/* define variable only used in LOG macro's */ /* define variable only used in LOG macro's */
# define LOG_VAR(A,B) A B # define LOG_VAR(A,B) A B
# else /* T_TRACER: remove all debugging and tracing messages, except errors */ # else /* T_TRACER: remove all debugging and tracing messages, except errors */
...@@ -413,7 +414,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int ...@@ -413,7 +414,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
# define LOG_DUMPFLAG(D) (g_log->debug_mask & D) # define LOG_DUMPFLAG(D) (g_log->debug_mask & D)
# define LOG_DUMPMSG(c, f, b, s, x...) do { if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x) ;} while (0) /* */ # define LOG_DUMPMSG(c, f, b, s, x...) do { if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x) ;} while (0) /* */
# define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0) # define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format, 0);} while(0)
# define LOG_VAR(A,B) A B # define LOG_VAR(A,B) A B
# endif /* T_TRACER */ # endif /* T_TRACER */
/* avoid warnings for variables only used in LOG macro's but set outside debug section */ /* avoid warnings for variables only used in LOG macro's but set outside debug section */
...@@ -421,9 +422,10 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int ...@@ -421,9 +422,10 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B #define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B
/* unfiltered macros, useful for simulators or messages at init time, before log is configured */ /* unfiltered macros, useful for simulators or messages at init time, before log is configured */
#define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0) #define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format, 0);} while(0)
#define LOG_UI(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ; } while(0) #define LOG_UI(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ; } while(0)
#define LOG_UDUMPMSG(c, b, s, f, x...) do { log_dump(c, b, s, f, x) ;} while (0) /* */ #define LOG_UDUMPMSG(c, b, s, f, x...) do { log_dump(c, b, s, f, x) ;} while (0) /* */
# define LOG_MM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format, 1);} while(0)
/* @}*/ /* @}*/
......
...@@ -235,7 +235,10 @@ int main(int argc, char **argv) ...@@ -235,7 +235,10 @@ int main(int argc, char **argv)
int i,aa;//,l; int i,aa;//,l;
double sigma2, sigma2_dB=10, SNR, snr0=-2.0, snr1=2.0; double sigma2, sigma2_dB=10, SNR, snr0=-2.0, snr1=2.0;
uint8_t snr1set=0; uint8_t snr1set=0;
float roundStats[50]; double roundStats[500] = {0};
double blerStats[500] = {0};
double berStats[500] = {0};
double snrStats[500] = {0};
float effRate; float effRate;
//float psnr; //float psnr;
float eff_tp_check = 0.7; float eff_tp_check = 0.7;
...@@ -1101,7 +1104,9 @@ int main(int argc, char **argv) ...@@ -1101,7 +1104,9 @@ int main(int argc, char **argv)
if (UE_harq_process->harq_ack.ack==1) effRate += ((float)TBS)/round; if (UE_harq_process->harq_ack.ack==1) effRate += ((float)TBS)/round;
} // noise trials } // noise trials
blerStats[snrRun] = (float) n_errors / (float) n_trials;
roundStats[snrRun]/=((float)n_trials); roundStats[snrRun]/=((float)n_trials);
berStats[snrRun] = (double)errors_scrambling/available_bits/n_trials;
effRate /= n_trials; effRate /= n_trials;
printf("*****************************************\n"); printf("*****************************************\n");
printf("SNR %f, (false positive %f)\n", SNR, printf("SNR %f, (false positive %f)\n", SNR,
...@@ -1109,7 +1114,7 @@ int main(int argc, char **argv) ...@@ -1109,7 +1114,7 @@ int main(int argc, char **argv)
printf("*****************************************\n"); printf("*****************************************\n");
printf("\n"); printf("\n");
dump_pdsch_stats(gNB); dump_pdsch_stats(gNB);
printf("SNR %f : n_errors (negative CRC) = %d/%d, Avg round %.2f, Channel BER %e, Eff Rate %.4f bits/slot, Eff Throughput %.2f, TBS %u bits/slot\n", SNR, n_errors, n_trials,roundStats[snrRun],(double)errors_scrambling/available_bits/n_trials,effRate,effRate/TBS*100,TBS); printf("SNR %f : n_errors (negative CRC) = %d/%d, Avg round %.2f, Channel BER %e, BLER %.2f, Eff Rate %.4f bits/slot, Eff Throughput %.2f, TBS %u bits/slot\n", SNR, n_errors, n_trials,roundStats[snrRun],berStats[snrRun],blerStats[snrRun],effRate,effRate/TBS*100,TBS);
printf("\n"); printf("\n");
if (print_perf==1) { if (print_perf==1) {
...@@ -1174,15 +1179,19 @@ int main(int argc, char **argv) ...@@ -1174,15 +1179,19 @@ int main(int argc, char **argv)
break; break;
} }
//if ((float)n_errors/(float)n_trials <= target_error_rate) {
if (effRate > (eff_tp_check*TBS)) { if (effRate > (eff_tp_check*TBS)) {
printf("PDSCH test OK\n"); printf("PDSCH test OK\n");
break; break;
} }
snrStats[snrRun] = SNR;
snrRun++; snrRun++;
} // NSR } // NSR
LOG_M("dlsimStats.m","SNR",snrStats,snrRun,1,7);
LOG_MM("dlsimStats.m","BLER",blerStats,snrRun,1,7);
LOG_MM("dlsimStats.m","BER",berStats,snrRun,1,7);
LOG_MM("dlsimStats.m","rounds",roundStats,snrRun,1,7);
/*if (n_trials>1) { /*if (n_trials>1) {
printf("HARQ stats:\nSNR\tRounds\n"); printf("HARQ stats:\nSNR\tRounds\n");
psnr = snr0; psnr = snr0;
......
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