1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>h>
#define B 20000000 //la bande passante totale (Hz)
#define T 295 //la température du système
#define U 4 //Le nombre des utilsateurs
#define S 16
int main()
{
FILE *oFile, *pFile;
double Pn;
double N0;
int i, j;
double Pr; //La puissance reçue
double *SNR;
char tmp[40];
double kb = 1.38e-23;
//Calcul la puissance du bruit en Watt
N0 = kb*T;
Pn = N0*B;
pFile = fopen("campus_poitiers_1R_1D_0T_mimo.RI_simplifier", "r");
oFile = fopen("data.txt", "w+");
//Pr = (double *)malloc(U*S*sizeof(double));
SNR = (double*)malloc(U*S*sizeof(double));
if ( SNR == NULL )
{
fprintf ( stderr, "\nErreur d allocation memoire\n");
return EXIT_FAILURE ;
}
//kb = 138e-25;
printf("Calcul le SNR :\n");
//printf("kb = %f, T = %d\n",kb, T);
//printf("N0 = %f\n", N0);
//printf("Pn = %f\n", Pn);
for(i=0; i<U; i++)
{
for(j=0; j<S; j++)
{
strcpy(tmp,"");
printf("itération u = %d s = %d \n",i,j);
fscanf(pFile, "%s", tmp);
Pr = atof(tmp);
printf("Pr = %f\n", Pr);
SNR[i*S+j] = 10.0*log10(Pr/Pn);
printf("SNR = %f\n", SNR[i*S+j]);
strcpy(tmp,"");
sprintf(tmp, "%f", SNR[i*S+j]);
printf(" tmp = %s\n",tmp);
fwrite(tmp,8,1,oFile);
}
}
getchar();
fclose(oFile);
fclose(pFile);
free(SNR);
return EXIT_SUCCESS;} |
Partager