Commit 73382b82 authored by Elena Lukashova's avatar Elena Lukashova
Browse files

Validating abstraction.c with a hotfix.

parent a5f9c925
......@@ -833,9 +833,9 @@ int main(int argc, char **argv)
else
if (perfect_ce==1)
sprintf(csv_fname,"dout_tx%d_r%d_mcs%d_mcsi%d_ch%d_ns%d_R%d_ab_nofix_pce_sh%d_d2_%d.m",transmission_mode,rx_type,mcs1,mcs2,channel_model,n_frames,num_rounds, interf_unaw_shift, n_ch_rlz);
sprintf(csv_fname,"dout_tx%d_r%d_mcs%d_mcsi%d_ch%d_ns%d_R%d_ab_fix_pce_sh%d_d2_%d.m",transmission_mode,rx_type,mcs1,mcs2,channel_model,n_frames,num_rounds, interf_unaw_shift, n_ch_rlz);
else
sprintf(csv_fname,"dout_tx%d_r%d_mcs%d_mcsi%d_ch%d_ns%d_R%d_ab_nofix_sh%d_d2_%d.m",transmission_mode,rx_type,mcs1,mcs2,channel_model,n_frames,num_rounds, interf_unaw_shift, n_ch_rlz);
sprintf(csv_fname,"dout_tx%d_r%d_mcs%d_mcsi%d_ch%d_ns%d_R%d_ab_fix_sh%d_d2_%d.m",transmission_mode,rx_type,mcs1,mcs2,channel_model,n_frames,num_rounds, interf_unaw_shift, n_ch_rlz);
csv_fd = fopen(csv_fname,"w");
fprintf(csv_fd,"data_all%d=[",mcs1);
......
......@@ -26,7 +26,7 @@
Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
*******************************************************************************/
/*#include <math.h>
#include <math.h>
#include <cblas.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -324,189 +324,5 @@ double pbch_bler(double sinr)
//printf ("sinr %f bler %f\n",sinr,bler);
return(bler);
}*/
#include <math.h>
#include <cblas.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "PHY/TOOLS/defs.h"
#include "defs.h"
void freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) {
double delta_f,freq; // 90 kHz spacing
double delay;
int16_t f;
uint8_t aarx,aatx,l;
delta_f = nb_rb*180000/(n_samples-1);
//write_output("channel.m","a",desc->a[0],desc->nb_taps,1,8);
for (f=-n_samples/2;f<n_samples/2;f++) {
freq=delta_f*(double)f*1e-6;// due to the fact that delays is in mus
for (aarx=0;aarx<desc->nb_rx;aarx++) {
for (aatx=0;aatx<desc->nb_tx;aatx++) {
desc->chF[aarx+(aatx*desc->nb_rx)][n_samples/2+f].x=0.0;
desc->chF[aarx+(aatx*desc->nb_rx)][n_samples/2+f].y=0.0;
for (l=0;l<(int)desc->nb_taps;l++) {
if (desc->nb_taps==1)
delay = desc->delays[l];
else
delay = desc->delays[l]+NB_SAMPLES_CHANNEL_OFFSET/desc->sampling_rate;
desc->chF[aarx+(aatx*desc->nb_rx)][f+n_samples/2].x+=(desc->a[l][aarx+(aatx*desc->nb_rx)].x*cos(2*M_PI*freq*delay)+
desc->a[l][aarx+(aatx*desc->nb_rx)].y*sin(2*M_PI*freq*delay));
desc->chF[aarx+(aatx*desc->nb_rx)][f+n_samples/2].y+=(-desc->a[l][aarx+(aatx*desc->nb_rx)].x*sin(2*M_PI*freq*delay)+
desc->a[l][aarx+(aatx*desc->nb_rx)].y*cos(2*M_PI*freq*delay));
}
// printf("chF(%d) => (%f,%f)\n",n_samples/2+f,
// desc->chF[aarx+(aatx*desc->nb_rx)][f+n_samples/2].x,
// desc->chF[aarx+(aatx*desc->nb_rx)][f+n_samples/2].y);
}
}
}
}
double compute_pbch_sinr(channel_desc_t *desc,
channel_desc_t *desc_i1,
channel_desc_t *desc_i2,
double snr_dB,double snr_i1_dB,
double snr_i2_dB,
uint16_t nb_rb) {
double avg_sinr,snr=pow(10.0,.1*snr_dB),snr_i1=pow(10.0,.1*snr_i1_dB),snr_i2=pow(10.0,.1*snr_i2_dB);
uint16_t f;
uint8_t aarx,aatx;
double S;
struct complex S_i1;
struct complex S_i2;
avg_sinr=0.0;
// printf("nb_rb %d\n",nb_rb);
for (f=(nb_rb-6);f<(nb_rb+6);f++) {
S = 0.0;
S_i1.x =0.0;
S_i1.y =0.0;
S_i2.x =0.0;
S_i2.y =0.0;
for (aarx=0;aarx<desc->nb_rx;aarx++) {
for (aatx=0;aatx<desc->nb_tx;aatx++) {
S += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc->chF[aarx+(aatx*desc->nb_rx)][f].x +
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc->chF[aarx+(aatx*desc->nb_rx)][f].y);
// printf("%d %d chF[%d] => (%f,%f)\n",aarx,aatx,f,desc->chF[aarx+(aatx*desc->nb_rx)][f].x,desc->chF[aarx+(aatx*desc->nb_rx)][f].y);
if (desc_i1) {
S_i1.x += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc_i1->chF[aarx+(aatx*desc->nb_rx)][f].x +
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc_i1->chF[aarx+(aatx*desc->nb_rx)][f].y);
S_i1.y += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc_i1->chF[aarx+(aatx*desc->nb_rx)][f].y -
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc_i1->chF[aarx+(aatx*desc->nb_rx)][f].x);
}
if (desc_i2) {
S_i2.x += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc_i2->chF[aarx+(aatx*desc->nb_rx)][f].x +
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc_i2->chF[aarx+(aatx*desc->nb_rx)][f].y);
S_i2.y += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc_i2->chF[aarx+(aatx*desc->nb_rx)][f].y -
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc_i2->chF[aarx+(aatx*desc->nb_rx)][f].x);
}
}
}
// printf("snr %f f %d : S %f, S_i1 %f, S_i2 %f\n",snr,f-nb_rb,S,snr_i1*sqrt(S_i1.x*S_i1.x + S_i1.y*S_i1.y),snr_i2*sqrt(S_i2.x*S_i2.x + S_i2.y*S_i2.y));
avg_sinr += (snr*S/(desc->nb_tx+snr_i1*sqrt(S_i1.x*S_i1.x + S_i1.y*S_i1.y)+snr_i2*sqrt(S_i2.x*S_i2.x + S_i2.y*S_i2.y)));
}
// printf("avg_sinr %f (%f,%f,%f)\n",avg_sinr/12.0,snr,snr_i1,snr_i2);
return(10*log10(avg_sinr/12.0));
}
double compute_sinr(channel_desc_t *desc,
channel_desc_t *desc_i1,
channel_desc_t *desc_i2,
double snr_dB,double snr_i1_dB,
double snr_i2_dB,
uint16_t nb_rb) {
double avg_sinr,snr=pow(10.0,.1*snr_dB),snr_i1=pow(10.0,.1*snr_i1_dB),snr_i2=pow(10.0,.1*snr_i2_dB);
uint16_t f;
uint8_t aarx,aatx;
double S;
struct complex S_i1;
struct complex S_i2;
avg_sinr=0.0;
// printf("nb_rb %d\n",nb_rb);
for (f=0;f<2*nb_rb;f++) {
S = 0.0;
S_i1.x =0.0;
S_i1.y =0.0;
S_i2.x =0.0;
S_i2.y =0.0;
for (aarx=0;aarx<desc->nb_rx;aarx++) {
for (aatx=0;aatx<desc->nb_tx;aatx++) {
S += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc->chF[aarx+(aatx*desc->nb_rx)][f].x +
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc->chF[aarx+(aatx*desc->nb_rx)][f].y);
if (desc_i1) {
S_i1.x += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc_i1->chF[aarx+(aatx*desc->nb_rx)][f].x +
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc_i1->chF[aarx+(aatx*desc->nb_rx)][f].y);
S_i1.y += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc_i1->chF[aarx+(aatx*desc->nb_rx)][f].y -
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc_i1->chF[aarx+(aatx*desc->nb_rx)][f].x);
}
if (desc_i2) {
S_i2.x += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc_i2->chF[aarx+(aatx*desc->nb_rx)][f].x +
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc_i2->chF[aarx+(aatx*desc->nb_rx)][f].y);
S_i2.y += (desc->chF[aarx+(aatx*desc->nb_rx)][f].x*desc_i2->chF[aarx+(aatx*desc->nb_rx)][f].y -
desc->chF[aarx+(aatx*desc->nb_rx)][f].y*desc_i2->chF[aarx+(aatx*desc->nb_rx)][f].x);
}
}
}
// printf("f %d : S %f, S_i1 %f, S_i2 %f\n",f-nb_rb,snr*S,snr_i1*sqrt(S_i1.x*S_i1.x + S_i1.y*S_i1.y),snr_i2*sqrt(S_i2.x*S_i2.x + S_i2.y*S_i2.y));
avg_sinr += (snr*S/(desc->nb_tx+snr_i1*sqrt(S_i1.x*S_i1.x + S_i1.y*S_i1.y)+snr_i2*sqrt(S_i2.x*S_i2.x + S_i2.y*S_i2.y)));
}
// printf("avg_sinr %f (%f,%f,%f)\n",avg_sinr/12.0,snr,snr_i1,snr_i2);
return(10*log10(avg_sinr/(nb_rb*2)));
}
uint8_t pbch_polynomial_degree;
double a[7];
void load_pbch_desc(FILE *pbch_file_fd) {
int i;
char dummy[25];
fscanf(pbch_file_fd,"%d",&pbch_polynomial_degree);
if (pbch_polynomial_degree>6) {
printf("Illegal degree for pbch interpolation polynomial %d\n",pbch_polynomial_degree);
exit(-1);
}
printf("PBCH polynomial : ");
for (i=0;i<=pbch_polynomial_degree;i++) {
fscanf(pbch_file_fd,"%s",dummy);
a[i] = strtod(dummy,NULL);
printf("%f ",a[i]);
}
printf("\n");
}
double pbch_bler(double sinr) {
int i;
double log10_bler=a[pbch_polynomial_degree];
double sinrpow=sinr;
// printf("log10bler %f\n",log10_bler);
if (sinr<-7.9)
return(1.0);
else if (sinr>=0.0)
return(1e-4);
for (i=1;i<=pbch_polynomial_degree;i++) {
// printf("sinrpow %f\n",sinrpow);
log10_bler += (a[pbch_polynomial_degree-i]*sinrpow);
sinrpow *= sinr;
// printf("log10bler %f\n",log10_bler);
}
return(pow(10.0,log10_bler));
}
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