Heart rate detection in BrainBay

There are several heart rate detection and display designs in the BrainBay example configuration files, but I have found that the technique that they use to detect heart rate — a threshold element that goes into a counter — is a bit problematic. On the sample data I tested with, I wasn’t able to tweak the threshold value so that it would both avoid false positives and catch all of the target signal spikes, because the amplitude of the signal was varying over time.

I tested an alternate design, with a 5-sample delay on a copy of the signal, and then an addition and comparator. This approximately measures the rate of change of the signal, and detects when it is above a certain range, triggering a threshold event and a frequency timer. It seems to be much more robust and capable of detecting the target in a noisy signal than the techniques in the sample BrainBay config files, at least on the data I was testing with. Here’s the .con file if anyone else wants to try it out: openbci_ekg_brainbay_heart_rate5.con (10.3 KB)

Eventually I’d like to include this in a bio/neurofeedback setup, but for now I’m just experimenting and learning about how the signal processing works.

One other issue I ran into is that the threshold element can only be adjusted using a GUI slider. Unfortunately the slider range seems to be set based on the total signal range, so for a signal with some motion artifacts in it, the range was so huge I couldn’t set the slider in increments of less than 375! My work around was to open the BrainBay .con file in a text editor, find the threshold element, and manually set the slider values as text.

What techniques have you used for detecting heart rate?

1 Like

Hello AdamM, I ran into precisely the same problem with the threshold element step size of 375. I suppose this is because of the huge range (+/-187500) of the OpenBCI output element.

I eventually discovered that the range of individual input and output ports of the connected elements can be edited. Just right click on the little orange or yellow circle that represents the connection port, uncheck “Get from port”, and fill in the range boxes. I set the threshold’s input to something reasonable, say +/-500uV, and the slider behaves nicely after that.

I’m planning to try out your design in the next day or so, will let you know how it goes.
-Elliot

Thanks for that excellent tip @elliot! It seemed odd that there wouldn’t be a way of setting the range manually, and I’m glad to hear about this option.

Thanks for the post, and let us know how you make out. I have a newer .con I could upload too, which includes measurement of HRV based on the standard deviation of heart rate. Let me know if you’re interested.

Cheers,
Adam