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

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    3

    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. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    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. #3
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    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. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    Quote Originally Posted by Tclausex View Post
    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.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Threshold and Blank Algorithm
    By ILLiad in forum C Programming
    Replies: 20
    Last Post: 11-17-2010, 01:59 PM
  2. Cycling variable, threshold
    By C+/- in forum C Programming
    Replies: 2
    Last Post: 03-01-2009, 03:15 AM
  3. help de-noise algorithm (fixed form threshold)
    By neoideo in forum C Programming
    Replies: 12
    Last Post: 01-08-2008, 03:22 PM
  4. Fill the blanks in the program...
    By sreeramu in forum C Programming
    Replies: 19
    Last Post: 10-18-2007, 05:26 AM
  5. Fill in the blanks
    By Prelude in forum C++ Programming
    Replies: 22
    Last Post: 09-17-2006, 08:08 AM

Tags for this Thread