int main(int argc, char *argv[])
{
/* Pre-Filter */
double time[502]={},amp[502]={};
double var1, var2;
FILE *fp;
fp = fopen("C1mcp&ssd00000.csv","r");
int i=0;
do {
fscanf(fp,"%lf,%lf\n", &var1, &var2);
time[i] = var1;
amp[i] = var2;
//printf("%i \t Time: %e \t",i, time[i]);
//printf("Voltage: %f \n", amp[i]);
i++;
}while(!feof(fp));
//printf("time 3 = %e\n",time[3]);
fclose(fp);
int time_size = sizeof(time)/sizeof(time[0]);
//int amp_size = 6;
/*printf("FIRST Pre - Filtered Time = %e \n", time[0]);
printf("Non-Filtered TIME AND AMPLITUDE: \n");
for(i = 0; i < time_size; i++){
printf("Non - Pre - Filtered Time = %e \n", time[i]);
printf("Non - Pre - Filtered Amp = %f \n", amp[i]);
}*/
//printf("Pre-Filtered TIME AND AMPLITUDE: \n");
double time_2[sizeof(time)/sizeof(time[0])]={};
double amp_2[sizeof(time)/sizeof(time[0])]={};
for(i = 0; i < time_size; i++){
time_2[i]= time[i] - time[0];
amp_2[i] = -amp[i];
//printf("%i \t Pre - Filtered Time = %e \t", i, time_2[i]);
//printf("Pre - Filtered Amp = %f \n", amp_2[i]);
}
/* Pass 1 */
int iStart = 16;
float k1 = 0.25;
float kn = 0.75;
int basePoints = 16;
//int peakPoints = 4;
double v[16]={};
double w[501]={};
float baselineSum;
double mav[502]={};
double Amp_Final[502]={};
for(i=0; i < iStart; i++){
v[i] = amp_2[i];
if(i == 0){
baselineSum = v[i];
mav[i] = baselineSum;
Amp_Final[i] = v[i];
//printf("Mavi = %f \n", mav[0]);
}
else{
if(i<basePoints){
baselineSum = baselineSum + v[i];
}
//printf("Baseline Sum = %f \n", baselineSum);
}
//av[i] = k1*v[i] + kn*mav[0];
//printf("mav [%i] 0 --> 16 = %f \n", i, mav[i]);
}
int length = sizeof(amp_2)/sizeof(amp_2[0]);
//printf("length = %d \n", length);
float baseline = baselineSum/basePoints;
//printf("Baseline = %f \n", baseline);
//printf("mav [0] = %f \t", mav[0]);
//printf("Final Amplitude [0] = %f \n", Amp_Final[0]);
for(i=1; i < length; i++){
w[i] = amp_2[i] ;
mav[i] = k1*w[i] + kn*mav[i-1];
//printf("mav [%i] = %f \t", i, mav[i]);
if(i < 16){
Amp_Final[i] = w[i];
//printf("Final Amplitude [%i] = %f \n", i, Amp_Final[i]);
}
else{Amp_Final[i] = mav[i] - baseline;
//printf("Final Amplitude [%i] = %f \n", i, Amp_Final[i]);
}
}
double Amp_Final2[502]={};
for(i=0; i<length; i++){
Amp_Final2[i]=Amp_Final[i];
//printf("Post Amp Copy [%i] = %f \n",i, Amp_Final2[i]);
}
double vPeaks[4]={Amp_Final[16],Amp_Final[16],Amp_Final[16],Amp_Final[16]};
int iPeaks[4]={16,16,16,16};
int j=0;
int k=0;
for(j=0; j<4; j++){
for(i=iStart; i < length; i++){
if (Amp_Final[i] > vPeaks[j]){
k=i;
vPeaks[j] = Amp_Final[i];
iPeaks[j] = i;
//Amp_Final[i]=0;
//printf("max [%i] = %f \n", i , max[j]);
//printf("Amp_Final [%i] = %f \n", i , Amp_Final[i]);
}
}
Amp_Final[k]=0;
//printf("Amp_Final = %f \n" , Amp_Final[k]);
/*for(i=iStart; i < length; i++){
printf("Amp_Final [%i] = %f \n", i , Amp_Final[i]);
}*/
printf("vPeaks = %f \t", vPeaks[j]);
printf("iPeaks = %i \n" , iPeaks[j]);
}
float vPeakSum=0;
float iPeakSum=0;
float vPeak;
int iPeak;
int lengthvPeaks = sizeof(vPeaks)/sizeof(vPeaks[0]);
for(j=0; j<lengthvPeaks; j++){
vPeakSum += vPeaks[j];
iPeakSum += iPeaks[j];}
vPeak = vPeakSum/lengthvPeaks;
iPeak = iPeakSum/lengthvPeaks;
printf("Pulse Peak = %f \t", vPeak);
printf("Pulse Peak Index = %i \n", iPeak);
/* Pass 2 */
int part1 = 50;
int part2 = 270;
int iCFD = iStart;
float cfdThresh = 0.25;
float vCFD = vPeak * cfdThresh;
double x[]={};
double y[]={};
float integral1 = 0.0;
float integral2 = 0.0;
int q=0;
for(i=iStart; i<iPeak; i++){
x[i] = Amp_Final2[i];
if(x[i] < vCFD){
if(iCFD<i){
x[i] -= Amp_Final2[iCFD];
integral1 += x[i];
//printf("Integral1 = %f", integral1);
integral2 += x[i];
//printf("Integral2 = %f", integral2);
}
q=i;
iCFD += 1;
//printf("iCFD = %i \t", iCFD);
//printf("vCFD = %f \n", x[i]);
}
else{
if(i < (iCFD + part1)){
integral1 += x[i];}
if(i < (iCFD + part2)){
integral2 += x[i];}
}
}
printf("Threshold Crossing Index = %i \t", iCFD);
printf("Threshold Crossing Value = %f \n", x[q]);
int iPart1 = iCFD + part1;
int iPart2 = iCFD + part2;
for(i=iPeak; i<iPart2; i++){
y[i] = Amp_Final2[i];
if(i<iPart1){
integral1 += y[i];
}
if(i<iPart2){
integral2 += y[i];
}
}
printf("Integral1 = %f \t", integral1);
printf("Integral2 = %f \n", integral2);
return 0;
}
No comments:
Post a Comment