-
September 1st, 2014, 07:28 PM
#1
Heartbeat Calculation Question
Not really a programming ,but below is a heartbeat calculation and I just have a question on one of the calculations
Code:
#include <REG51.H> /* special function register declarations */ #include <stdio.h> /* prototype declarations for I/O
unsigned char sec,sec100;
unsigned int bt,tick,r,bpm;
void msdelay(unsigned int);
void extrint (void) interrupt 0 // external Interrupt to detect the heart pulse
{
bt=tick; // number of ticks are picked
tick=0; // reset for next counting
}
void timer0 (void) interrupt 1 using 1 // Timer 0 for one second time
{
TH0 = 0xdc; //The value is taken for Ssc/100 at crystal 11.0592MHz
sec100++; // It is incremented every Ssc/100 at crystal 11.0592MHz
tick++; // This variable counts the time period of incoming pulse in Sec/100
if(tick>=3500){tick=0;} // tick are limited to less trhan 255 for valid calculation
if(sec100 >=100) // 1 sec = sec100 * 100
{
sec++;
sec100=0;
}
}
void main()
{
msdelay(1000);
msdelay(1000);
printf("Heart beat ");
msdelay(1500);
msdelay(500);
//delay(15000);
bpm=0;bt=0;
while(1)
{
if(sec >=1)
{
sec=0;
/*
The sampling time is fixed 1 sec.
A variable "tick" is incremented with one tick per 100mSc in the timer 0 interrupt routine.
Each on occurring of external interrupt the value in the "tick" is picked up
and it is set to zero for recounting.
The process continues till next external interrupt.
Formula for calculating beats per minutes (microcontroller based heartbeat monitor ) is
as tick is the time period in Sec/100. so extract the frequency of pulses at external interrupt
Frequency = (1/tick)* 100 i.e pulses /sec
Then
bpm = frequency * 60 for one minutes i.e pulses per minute
in short we can do it as
bpm = 6000/ bt
*/
if(bt >=7){
bpm = 6000/bt; // for valid output bt is limited so that it should be greater than 6
msdelay(500);
//printf("Pulse. ");
r=bpm%100;
//printf("bpm: %d\r\n", bpm);
printf(" %d\r\n", bpm);
}
else {
printf("out of range");} // otherwise bpm will be shown zero
}
}
}
void msdelay(unsigned int i)
{
//unsigned int i;
while(i --);
}
Frequency = (1/tick)* 100 i.e pulses /sec
Then
bpm = frequency * 60 for one minutes i.e pulses per minute
in short we can do it as
bpm = 6000/ bt
How is this shortcut working? or what I mean is where did the 6000 figure come from?
-
September 2nd, 2014, 01:27 AM
#2
Re: Heartbeat Calculation Question
Bpm = frequency * 60
Bpm = (1/tick) * 100 * 60
Bpm = (1/tick) * 6000
Bpm = 6000/tick
-
September 2nd, 2014, 08:30 AM
#3
Re: Heartbeat Calculation Question
Originally Posted by PredicateNormative
Bpm = frequency * 60
Bpm = (1/tick) * 100 * 60
Bpm = (1/tick) * 6000
Bpm = 6000/tick
But how come the come the value of tick is never divided into 1 and then multiplied?
Is it canceled out like Bpm = (1/tick) * 6000/1,cancel both the one's out?
-
September 2nd, 2014, 08:57 AM
#4
Re: Heartbeat Calculation Question
bpm = (1/tick) * 6000
bpm = 6000 * (1/tick)
bpm = (6000 * 1)/tick
bpm = 6000/tick
However, if you want to think about it more deeply then, yes, 6000 is implicitly 6000/1, so you are really multiplying (1/tick)*(6000/1) = (1*6000)/(tick*1) = 6000/tick.
-
September 2nd, 2014, 10:16 AM
#5
Re: Heartbeat Calculation Question
Originally Posted by PredicateNormative
bpm = (1/tick) * 6000
bpm = 6000 * (1/tick)
bpm = (6000 * 1)/tick
bpm = 6000/tick
However, if you want to think about it more deeply then, yes, 6000 is implicitly 6000/1, so you are really multiplying (1/tick)*(6000/1) = (1*6000)/(tick*1) = 6000/tick.
I need to work on my maths but thanks
-
September 2nd, 2014, 06:18 PM
#6
Re: Heartbeat Calculation Question
Actually just on this
Is this wrong? I mean is the % operator used for finding remainders e.g 10 % 6 =4
-
September 2nd, 2014, 07:34 PM
#7
Re: Heartbeat Calculation Question
Originally Posted by johnjameson
Actually just on this
Is this wrong? I mean is the % operator used for finding remainders e.g 10 % 6 =4
Write a bit of code and compare the two approaches with some different input values.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|