Thread: Need help for program that uses threshold and blanks!

1. Need help for program that uses threshold and blanks!

Hey everyone,

I have an assignment for my biomedical engineering programming class that requires me to calculate the instantaneous heart rate of a given input text file. The professor suggested we use "Threshold and Blanking". My program currently finds the first period's instantaneous heart rate, but how do I make it continue throughout the whole data set?

Any Help is appreciated!

2. Code:
```#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

FILE *fp;
char fn[100];

int main(int argc, char *argv[]) {

//declare variables
int i,j,n;
float t[10000],b[10000];
float t1;
float t2;
float threshold;
float blank;
float tim[20];

threshold = 120.0;
blank = 60;

if(argc!=2) {
printf("you didn't include the filename silly\n");
}

else {
strcpy(fn,argv[1]);  //put filename on command line
fp = fopen(fn,"r");
if(fp==NULL) {
printf("error opening file\n");
}
else {
//insert functionality here
//first find out how many points
i = 0;
j = 0;
while(fscanf(fp,"%g %g",&t[i],&b[i])!=EOF) {
i++;
}
n = i;
fclose(fp);

i = 0;
j = 0;
while(b[i]<threshold) {
i++;
}
tim[j] = t[i];

printf("t%d = %f\n",j+1,tim[j]);
//how do i skip over 60 points?
i = i + blank;
while(b[i]<threshold) {
i++;
}
tim[j+1] = t[i];
printf("t%d = %f\n",j+2,tim[j+1]);
printf("instantaneous HR for the period %d = %f\n",j+1,60/(tim[j+1]-tim[j]));

}
}

return 0;
}```

3. The body of your code, at the end, where you're trying to find values in b over your threshold is outside of any loop construct. You'll only find the first instance of b[i] > threshold.

4. Originally Posted by Tclausex
The body of your code, at the end, where you're trying to find values in b over your threshold is outside of any loop construct. You'll only find the first instance of b[i] > threshold.
how would i go about reconstructing the bottom loop so the program continues to run throughout the data set? I attached the data set file we have to use with the program.

5. Well, you saved the last index to n after you read in the file contents. Surely you could make use of that in a while loop to evaluate the data and print your statements.