Determining Period of Signal

29 Sep 2010 . Edited: 29 Sep 2010

Essentially trying to determine heart rate. Current Test input signal being used is a rectified triange wave. The code below makes sense in my mind, however the values being printed to the putty terminal are all over the place, and coming in alot faster than the actual frequency of the signal. At first i thought it might be noise in the signal triggering above and below a threshold, changing the flag. However introduction of noise margins ie 0.7 on rising and 0.5 on negative edge.

 

Any alternate suggestions? kind of stumped.

 

#include "mbed.h"              

Serial pc(USBTX, USBRX); // tx, rx

#define UPPER_THRESHOLD 0.7
#define LOWER_THRESHOLD 0.5

int main() {
    pc.printf("Hello World!\n");
    
    Timer t;
    AnalogIn ain(p19);
    DigitalOut led1(LED1);
    DigitalOut led2(LED2);
    DigitalOut led3(LED3);
    DigitalOut led4(LED4);
    int flag=0;
    
    float interval;
    double BPM;
    
    
    while (1){
        if (ain>UPPER_THRESHOLD && flag==0){
            t.stop();
            interval=t.read();
           /// record time 
           BPM=60/interval;
           pc.printf("BPM: %f \n", BPM);
            t.reset();
            t.start();
            flag=1;
        }
        if (ain


if (ain<LOWER_THRESHOLD && flag==1){
flag = 0;
}    
}

}

29 Sep 2010 . Edited: 29 Sep 2010

The usual technique is to condition the R wave, and use the pulse to start and stop a timer, giving the inter-beat interval. You can then calculate the heart rate.

Don't attach electrodes to anyone unless you have plenty of insurance, and the system is electrically isolated using a medically-approved technique.

29 Sep 2010

 

user avatar Leon Heller wrote:

The usual technique is to condition the R wave, and use the pulse to start and stop a timer, giving the inter-beat interval. You can then calculate the heart rate.

Don't attach electrodes to anyone unless you have plenty of insurance, and the system is electrically isolated using a medically-approved technique.

 

 

Essentially that is what the code is trying to do, to detect the peak of the R

http://www.vanth.org/vibes/images/normalECG2.PNG

and measure the time until the same location of the next rising R edge