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 2and
b =
0 0 0 0 0 0 0 0 0 1 0 0 0and
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.
Best Answer