How can I find adjacent identical values in a vector, flanked on either side by outliers?
Show older comments
I am trying to find adjacent identical values in a vector, since they represent artifacts in heart rate data. So imagine 1Hz sample rate and we have a steadily climbing HR, then a stop, then it jumps to where it should be. I want to identify the suspect slope and the numbers before (and sometimes after) that value, so:
HR=[136 137 138 140 140 140 140 140 140 140 145 146 145 147]
according to certain literature, a slope over 2.6 bpm change/second is suspect, so I use diff...
a=diff(HR); %grabs the differences
b=a>2.6; %shows which ones are suspect
c=find(a==0); %shows where the slope is zero
and get
a =
1 1 2 0 0 0 0 0 0 5 1 -1 2
and
b =
0 0 0 0 0 0 0 0 0 1 0 0 0
and
c =
4 5 6 7 8 9
So the 10th element in the vector is my target, and the zero difference values (elements 4-9) in between are numbers that need to be replaced.
Is there some kind of way that I can use diff here? Is there a better solution?
Any thoughts would be welcome.
4 Comments
the cyclist
on 8 May 2015
You have done a pretty nice job of laying out your problem. However, I think you need just a bit more specificity. Given the input of HR, what exactly do you expect the output to be? You might also want to provide another couple input/output examples, so that we are not guessing how to handle different cases. Wanting to find "the numbers before (and sometimes after)" is not a good enough spec to work with.
Star Strider
on 8 May 2015
I don’t understand ‘1Hz sample rate’ with heart rate (EKG) data. Wouldn’t you get significant aliasing?
Blake
on 8 May 2015
Blake
on 8 May 2015
Accepted Answer
More Answers (0)
Categories
Find more on 3-D Scene Control in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!