Traitement-signal-plantes/Code-C/power.c

49 lines
1.5 KiB
C
Raw Normal View History

2022-06-01 12:32:04 +02:00
#include "power.h"
#include "getArray.h"
2022-06-02 14:29:21 +02:00
#include "fileGestion.h"
2022-06-10 17:22:01 +02:00
#include "initialParameters.h"
#include "queue.h"
2022-06-01 12:32:04 +02:00
2022-06-14 10:46:12 +02:00
/**
* @brief realize the power calcul
*
* @param p array with all the values that will be used for the calcul
* @param powerArray array where results are stocked
* @param N number of rows in p
* @param M number of columns in p
*/
2022-06-09 17:34:24 +02:00
void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){
2022-06-07 14:28:32 +02:00
for(int i = 0; i < M-1; i++){
2022-06-01 12:32:04 +02:00
int j = 0;
2022-06-09 17:34:24 +02:00
powerArray[i] = 0;
2022-06-07 14:28:32 +02:00
while(j < N-1){
double aire = ( pow(p[j][i+1],2) + pow(p[j+1][i+1],2) ) / 2 * period;
//printf("aire [%d,%d] : %f\n",j,i,aire);
2022-06-09 17:34:24 +02:00
powerArray[i] += aire;
2022-06-01 12:32:04 +02:00
j++;
}
2022-06-09 17:34:24 +02:00
powerArray[i] *= invTimeBandwidth;
//printf("%f\n", powerArray[i]);
2022-06-01 12:32:04 +02:00
}
}
2022-06-14 10:46:12 +02:00
/**
* @brief function that realize all the action to write one lign in the file powerData.csv
*
* @param rawDataFileName name of the raw data file to use to realize the calcul
* @param N number of rows in the file
* @param M number of columns in the file
*/
2022-06-10 17:22:01 +02:00
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){
long **p = getRawDataArray(rawDataFileName,N, M);
double pw[8];
2022-06-07 14:28:32 +02:00
if(p !=NULL){
2022-06-09 17:34:24 +02:00
powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
2022-06-14 10:24:59 +02:00
writeDataInFile("powerData.csv",pw,8);
2022-06-07 14:28:32 +02:00
freeArray(p,N);
2022-06-09 17:56:45 +02:00
return true;
2022-06-07 14:28:32 +02:00
}
else{
2022-06-09 17:56:45 +02:00
return false;
2022-06-07 14:28:32 +02:00
}
2022-06-01 12:32:04 +02:00
}