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 example, 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 something 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 Flatten[Import[filename,"Table"]]
Comments
Post a Comment