Skip to main content
2 of 6
added example data for download
Aart Goossens
  • 1.6k
  • 12
  • 21

Filtering beat-to-beat heart rate data

From an experiment i have a dataset of beat-to-beat heart rate data: a list of the time between each heart beat in [ms]. The data is measured using an infrared optic sensor at the finger tip. The sensor frequently misinterprets a slight movement of the finger as an heart beat. Data therefore often looks somewhat like this:

{1000, 1000, 1000, 1000, 500, 500, 1000, 1000, 1000, 600, 400, 1000}

In this exaple one can easily see that the 5th and 6th element should be one, same for the 10th and 11th. However, in real life the data looks more like this:

data={981, 870, 1099, 1105, 650, 397, 920, 917, 1015, 1085, 210, 344, 457,
950}

Where the 5-6 (650,397) and 11-12-13 (210,344,457) should be taken together. It is easy to just delete the incorrect data by using someting like:

DeleteCases[data,
x_ /; x < Mean[data] - StandardDeviation[data] || 
x > Mean[data] + StandardDeviation[data]]

...but i want to make a function that recognizes when multiple elements should be added to one.

One could just add every two, three or four (=length) elements and select the Cases where the result lies (for example) in the range Mean[data]-/+StandardDeviation[data]:

length = 2;
Position[Total[data[[# ;; # + length]]] & /@ 
  Range[Length[data] - length], 
 x_ /; x > Mean[data] - StandardDeviation[data] && 
   x < Mean[data] + StandardDeviation[data]]

Result:

{{5}, {11}, {12}}

This gives me an idea of where the incorrect data is. Unfortunately, after having this result, i don't know what to do with it... For example, i get confused by the fact that elements 11-12-13 return 2 cases of incorrect data when i use length=1. And maybe there are more (simple) ways to filter this data.

Question: can anyone give me a kick-start?

Edit: You can download an example of actual data here. Just Import[] the file.

Aart Goossens
  • 1.6k
  • 12
  • 21