LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Heart rate monitor from ekg data

We're trying to develop a heart rate monitor using EKG data but are having issues connecting all of the components using analogue signal (from DAQ). The first VI is our attempts at getting a heart rate monitor by following the peak detector example from Labview (we attached that as the 2nd VI) but are still having problems. We've tried following other threads on heart rate monitors but haven't been able to get it to work. The current problem is getting the VI to calculate the time between 2 consecutive R peaks while taking in dynamic data from the DAQ.

Download All
0 Kudos
Message 1 of 8
(9,820 Views)

Hi,

 

What you are trying to do should be easy. We do it all the time as an "add-on" benefit for my company's other medical applications - all using labview.  I don't want to send the actual code since it is proprietary, but I think I can help with advice.  You might have considered some of these things already, but I will list the primary considerations.  Hopefully that will help you solve your problem. Once you have done the peak finding correctly the rest is easy, but I will review that at the end at well. To do an excellent heart rate monitor you only need 3 vis - "collector" "filter" and "peak finder".

 

Peak finding:  with the ECG there are two problems with setting the peak finding parameters - wandering baseline and different shapes of the individual waveforms for different individuals (and to a much lesser extent, the same individual).


Wandering baseline: the ECG tends to have a wandering baseline, even ECG with a good analog high pass. The "high end" recommended high pass cut off for medical diagnostic purposes is about 0.05 Hz, and typically this will still allow for enough baseline wander to mess with your peak finding occasionally.  So digitally filter your signal beforehand with a high pass filter with a much high frequency - like 1 Hz (use the pre-fabed "filter.vi" in the signal analysis pallet, or any of the many lower level filters vis). 


Different Shapes:  The other issue is that different people will have different shaped PQRST complexes. Since you want to set the peak threshold below the R-peak but above the other features that might trigger the peak finder - mainly the P as T waves.­­ The thing to remember is that if you are going for a heart rate monitor ONLY you are allowed to filter the hell out of the signal since you don't care about the exact shape of the PQRST.  In fact you really are looking for a filter that removes as much of the lower frequency P and T waves leaving mostly R peaks to do the peak finding. You might try razing the high pass cut off until you are satisfied that both the drift and the shapes are best for peak finding.Yry it. It goes without saying that depending on your high frequency noise you may ALSO want to low pass filter your signal before peak finding, though this may not be as crucial.. If you have prominent 60 Hz interference you may want to low pass as a frequency below 60 Hz.

 

Also remember to set the number of peak samples in the peak finder to be enough to prevent multiple peak detections - something like 1/4 or thereabouts of the width of the R-wave (in samples).

 

After filtering the signal you then need to set the threshold.  Since everybody has different R-wave peak magnitudes, you can't unusually just fix the value. The way to do this is to fix some percentage of the MAXIMUM value in a give window of say 15 second or more.  If you are doing you filtering correctly then this will give you the approximate (max) value of the (filtered) R-wave. Once you have your max value you then set the threshold at a certain fraction (you decide) of this value.  Try 0.6 for example.  Then you will always "cut" only the R-waves, and only once each if you set your peak samples like I said. There are alway going to be "mutant" ECGs that are "pathelogical" - such as a lead I that has a prominent NEGATIVE R-wave "peaks". You can decide how to deal with these case on your own. The resulting output of the peak finder will then work for just about any person, For about %95 of ECGs what I described will work fine, and I believe once you do it once correctly, dealing with the rare cases will be easy for you to pick up without handholding

 

Heart Rate calculation (easy part once you have the peak locations).  The size of the location vector (output of the peak finder) is the number of peaks. I think there is also an output that has just this number too. The net sample separation (call it delta S) is the sample value of the last peak minus the sample value of the first peak. The corresponding time separation is delta S x delta t (where delta t is the sampling time) or delta S/(sampling rate). The heart rate is the number of beats per minute.  Use the time calculated above, and the number of detected beats minus 1 as the number of beats in that time interval and make sure you convert to beats per minute dimensions.  All of the above should be done on a rolling window of many seconds since you usually want an average heart rate over several second - you can use the "collect" vi to do this. If you don't care about beat to beat fluctuations you can just calculate the heart rate from each peak separation time (be sure you know your sampling rate, of course).  The way it would be done on a hospital monitor is the first way - using a longish moving window, say 15-30 seconds,  It should be no problem for a modern PC to keep up. Alternatively you could do the calculation on consecutive 15-30 second intervals instead of a rolling window.

 

So to do this right you only need the collect vi, the filter vi and the peak finder vi. I hope this helped in some way.

 

Marko

CardioPrint Biometrics

 

0 Kudos
Message 2 of 8
(9,808 Views)

I took a look at your program (the first one).  For one thing you didn't have the "width" or "threshold" inputs wired into the peak finder vi, so you may not really unerstand how the peak finder works. Read the help file for the peak finder - carefully. However, you did have the right peak finder vi in the first program. Toss out the seecond vi you posted.

 

I have taken the liberty of re-writing your vi to implement something like I was talking about in the previous post, and this file is attached below.  Hopefully you can look at this one carefully and use it as a starting point for how to do things. Once you understand things based on this one there are a few things you might want to do to make it a bit fancier, especially at the point where the actual heart rate is calculated - more precise, the way I described in the first post.  But this should get you over the labview-related hump, I hope.

 

You will of course want to adjust the actual parameters to fit the real ECG data you are using, but this vi should probably work, more or less, if you substitude your data acquuistion vi (assuing you are sampling at 1 kHz) without any major changes, You should then play with the partmater until you understand what is going on, and can make your  own judgment on how to improve things to fit your own goals.

 

Good luck.

 

Marko

CardioPrint Biometrics

0 Kudos
Message 3 of 8
(9,779 Views)

Please also visit our NI Biomedical User group located here:  www.ni.com/biomedusers

 

There is good reference information about using LabVIEW in biomedical applications plus information on our Biomedical Starter Kit, a free download with additional biosignal processing tools.

 

Thanks,

Steve

0 Kudos
Message 4 of 8
(9,732 Views)

Thank you for the well detailed responses as well as help with the VI. Unfortunately our Labview is only running at 8.5, is there any chance you could post the script in that version? Thanks again

0 Kudos
Message 5 of 8
(9,674 Views)

Here is a version I saved as 8.5. Let me know if you still have problems.

0 Kudos
Message 6 of 8
(9,623 Views)

i want more information about this can you send it to my mail(srinivaskalluri143@gmail.com)

how can we do  software of Heart rate monitor from ekg data of ni block diagram

0 Kudos
Message 7 of 8
(5,662 Views)

Kalluri, 

 

Since this thread has not been touched in a while, it might be a better idea to direct message this person.

 

Eric

Applications Engineer

0 Kudos
Message 8 of 8
(5,589 Views)