From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating Heart Rate from the incoming serial data on VISA

Hello,

I want to accomplish a task in which i have to calculate the heart rate of incoming ECG signal which is sent on the serial port.

I have developed an array of some length in which i gather the data, from this i calculate the # of peaks in it and then calculate the heart rate from it.

The problem is that there is very much fluctuations in heart rate values.

I am therefore searching for some reliable technique to calculate the Heart Rate.

Kindly guide me what should i do.

Thanks

0 Kudos
Message 1 of 34
(4,308 Views)

Dear Abuzar,

 

can it be that you need to average a little bit more? In a previous project I used a sub VI to create a moving average just like the stacked shift register you are using. However instead of stacking shift registers an array is used. Elements are put into the array (at the last position) until a maximum (specified by the main VI) is reached. At that time the first element wil deleted. 

Just initialize the sub VI from your main VI (boolean in), write to the value control and specify over how many samples you want to average. I created a small example.

 

I hope it ithis helps you further,

 

Best regards,

 

Martijn

 

 

Download All
0 Kudos
Message 2 of 34
(4,231 Views)

Hi Abuzar,

 

What acquisition system are you using? Which sensor are you employing to measure heart pulse? 

The term "fluctuations" can refer to a several stuff in a signal. What is the noise floor of your system? You will need to "define" your fluctuations. The fluctuations or 'noise' can have several sources. It can be analog interference or digital communication lags. 

 

In order to employ certain technique (signal processing) you will have to sweep Internet, gather literature, and try coding it in LabVIEW. And when you're stuck, just point out the precise location of your code where you find yourself helpless. We'll help then Smiley Happy

 

 

Regards. 


0 Kudos
Message 3 of 34
(4,224 Views)

Dear NapDynamite

By Fluctuation i mean the continuous change in the measured Heart Rate, while the generated Heart Rate from the Simulator in fix.

0 Kudos
Message 4 of 34
(4,200 Views)

Hi Abuzar,

 

just a guess since I'm not familiar with your device. But can it be that we also need to take timing in considiration? You need to calculate the heart rate over a certain period of time? Are thos 5000 elements taken at exact the same dt from each other? Also you are adding elements to an array (build array function), so your array becomes bigger and bigger. Maybe it is also an idea to delete from the array (above a number of samples, just like I showed you in the sub vi I send you)

0 Kudos
Message 5 of 34
(4,171 Views)

Have you looked at the LabVIEW Biomedical Toolkit?  I haven't used it, myself, but I know that it has routines for ECGs.

 

Bob Schor

0 Kudos
Message 6 of 34
(4,156 Views)

Thanks alot msmeulers

Yes. I am not considering any timmings value.

My baudrate is 9600. Getting serial data just from an ordionary microcontroller.

I will try to limit the size of array and will update you its results.

Meanwhile pls let me know if i need to address the issue of timings.

One last request, the VI you sent in first reply was in 2014 version but i have 2013. Kindly send me in 13 version.

I shall be thankful to you.

 

0 Kudos
Message 7 of 34
(4,144 Views)

Dear Abuzar,

 

     Did you see my earlier post?

 

     I'm curious about the data you are acquiring.  It appears that you are getting single bytes (your Byte Count is 1) from some device and processing it in your Consumer loop.  I understand that your device is running at 9600 Baud, which means you are getting about 960 Bytes/second.  What are these data?  Are you acquiring an analog signal (at roughly 1 KHz) representing an EKG?

 

     What are you trying to do in the Consumer loop?  I can see your code, of course, but I cannot "read your mind" to decide what it is you are trying to compute, particularly with feedback loops, multiple shift registers, creating arrays, and doing Statistics.  A verbal description of your intended algorithm would be helpful.  Note that without knowing what the data represents, it is impossible to make any assessment on the validity of the code in the Consumer loop, even if it were more transparent.

 

     A word about Queues -- the Consumer loop does not need to carry the Queue in a Shift Register, and doesn't need to bring it to the right-hand shift register terminal.  A Queue wire is a reference to the Queue -- once the Dequeue function reads it, it knows everything it needs to know to use the Queue.  So the input terminal can be a simple tunnel.  The same is true for the tunnel type in the Producer Loop -- ordinary tunnels will suffice, though you do need the output tunnel here because you use it to release the Queue.  Note that if you had used a For loop as your Producer and had driven it with an Array, you should use a Shift Register instead of simple tunnels for the Queue -- do you know why?  It's because a For loop, if an empty Array is used to "drive" it, will not execute, and hence the output tunnel will have no data passed to it from within the loop (but a Shift Register will still "shift" from input to output).

 

Bob Schor

 

 

0 Kudos
Message 8 of 34
(4,132 Views)

Dear Abuzar,

 

Let me get few things straight. You have connected an ECG sensor, giving analog signal, to a Microcontroller. Obviously it will be connected to its Analog Input, having some ADC resolution. You then would've done few maths inside to get bytes changed to some Double integer or Floating Point and then feeding the same value to Serial Bus via UART protocol, with 9600 baud rate. 

Few things I would do to diagnose this issue are:

1. Check if baud rates on both machines are same.

2. Design a simple VISA read application in LabVIEW to fetch correct data. Observe data over waveform graph with different ECG scenarios. 

 

Getting the correct data first is foremost concern of any designer. Many issues arise over communication layer. Which Microcontroller are you using? I would suggest if you use NI-DAQ series with Analog I/Os to robustly design your system.

 

The rest of the case, about which signal Processing technique to use, comes later. You can't serve Orange juice if your juicer has apples in it. 

 

 

Regards. 


0 Kudos
Message 9 of 34
(4,113 Views)

Wow, Dynamite, you got a lot more detail of the hardware than I was able to understand.  No wonder I'm scratching my head ...

 

BS

0 Kudos
Message 10 of 34
(4,102 Views)