0

I'm trying to create a heart beat monitor and need some false information to feed into my program to check it works.

One of the requirements of my program is to set off an alarm if the heart rate integer drops below a certain figure.

However the problem I have is, if the heart rate drops below the minimum heart rate integer before it sets off the alarm and then bounces straight back up again, that's not a test for the alarm, see pseudo code:

If heart_rate < 60:
    Count = Count + 1
If heart _rate > 60:
     Reset Count variable 
If Count = 10:
     Set off alarm

So I need to generate data where it simulates a heart rate dropping below 60 (patient dieing). Would the quickest way to do this create a list or text file that the program reads from to simulate the situation or is there a funky way that can simulate random numbers that can set off the alarm and will stay around that integer once the alarm has been set off?

Sorry if this sounds super confusing, I'm a python programmer, having to program in C#.

4
  • 6
    How would you do this in python? Commented Oct 12, 2015 at 11:26
  • I would probably get the program to pump out random numbers into a variable and have it check to see if that number is 60 or less. When it is 60 or less, I would have a second random number generator create numbers between 50 and 60 into the same variable to keep the HR under 60. Just seems super long winded. Commented Oct 12, 2015 at 11:31
  • 1
    Are you just trying to simulate the heartbeat or do you want to incorporate the logic for firing the alarm? Commented Oct 12, 2015 at 11:46
  • Trying to simulate a heart beat that will simulate someone's heart rate dropping below 60 and staying there for at least 10 heart beats which will set off the alarm. Commented Oct 12, 2015 at 12:16

3 Answers 3

1

Your problem seams to be a "data stream testing" one. Manually generating data streams is not something I would personally characterize as "quick" (or even "sane"...). You either get an existing data set or you generate it (but not manually, unless it's a relatively small number of data points: 20~30).

That being said, you need to test something, which means you need to know that when a target case (heart rate below 60), your system correctly catches the "exception". This, in turn, means that you need to know where it happens, i.e. the exact moment in time.

My advice is: automatically generate a data set, full of "normal" values. At different time point (i.e. position in the data stream) manually insert "exception" values (59), with different frequencies, to see if the system resets the counter (less than 10 occurrences) or if it raises an alarm (at least 10 occurrences).

You would then have the following initial data stream:

  80 78 78 81 80 81 ... 75 76 80 // say 100 values ("data points")
// 0  1  2  3  4  5     97 98 99 -> indices ("time points")

If you insert a "false alarm" (80 78 59 59 78) at index 2, for example, you know that your system should reset the counter. You would do the same for the "alarm"; you'll know the index (time point) when the alarm should be raised.

Edit: the part about "manually" inserting the targeted values should be interpreted as "empirically selecting an index of an array (or a list) filled with random data, where the data should be inserted".

Sign up to request clarification or add additional context in comments.

Comments

0
public static class HeartrateGenerator
{
    static Random random = new Random();

    public static IEnumerable<int> GenerateHeartrate(
        int totalSequenceLength,
        int dropsBelow60After, 
        int bouncesBackAfter = -1)
    {
        // NOTE: check input data

        int i = 0;

        // return values > 60
        while (i < dropsBelow60After)
        {
            i++;
            yield return 60 + random.Next() % 60;
        }

        if (bouncesBackAfter > 0)
            // return values < 60
            while (i < bouncesBackAfter)
            {
                i++;
                yield return random.Next() % 60; 
            }

        // return normal values again
        while (i < totalSequenceLength)
        {
            i++;
            yield return 60 + random.Next() % 60;
        }
    }
}

example usage:

HeartrateGenerator.GenerateHeartrate(100, 20, 28);

Comments

0

Try this: you might want to change the rand.Next(min,max) to use normal range of heartbeat or whatever range you want to see for a heartbeat value.

public class Program
{
    public void Main(string[] args)
    {
        Random rand = new Random();
        bool flag = true;
        int count = 0;
        while (flag)
        {

            if(count==10)
            {
                Console.WriteLine ("dead");
                flag = false;
                break;
            }
            Thread.Sleep(1000);
            var heart_rate = rand.Next(50,70);
            Console.WriteLine (heart_rate);
            if (heart_rate < 60)
            {
                count++;
            }
            else if(heart_rate > 60)
            {
                count=0;
            }
        }
    }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.