How can I get rid of neighbour data?

5 views (last 30 days)
This is my derivative from the experiment. I just want to get the number of peaks so I used findpeaks with 'MinPeakHeight' condition.
As you can see in second picture, some of the peaks is not so sharp and it gave me two data instead of one. more problem is I can not use 'Minpeakdistance' since the distance of each experiment can be very different. I was told to make it universal, not to modify this part of my code by hand (unfortunately).
I think it can be done with a loop? delete neighbour data within 0.1 x-axis range condiiton ?
I'm kind of a newbie. appreciate every comment, thank you

Accepted Answer

ME
ME on 5 Nov 2019
So I will preface this by saying there are probably more efficient ways but as you mentione using a for loop you could begin with:
[pks,locs] = findpeaks(data)
You can then find the associated locations on the x-axis using
xlocs = x(locs)
where x is whatever array holds your x-axis data (change as necessary). If you want to use a for loop then you can do:
for i=1:numel(xlocs)-1;
if(abs(xlocs(i+1)-xlocs(i))<=0.1)
if(pks(i+1)>pks(i))
pks(i) = nan;
elseif(pks(i+1)<pks(i))
pks(i+1) = nan;
elseif(pks(i+1)==pks(i))
pks(i+1)=nan;
end
end
end
idx=find(isnan(pks)==1);
pks(idx)=[];
xlocs(idx)=[];
This takes your x locations and your peaks and removes one of the peaks where there are two 0.1 or closer together. The if/elseif statements are for some basic assumptions I made including:
  • if there are two close together peaks then you want the tallest one; and
  • if the two close together peaks are equal height then we take the first one.
  1 Comment
Tipnirin Vajanarat
Tipnirin Vajanarat on 5 Nov 2019
it works! thank you so much. You're a lifesaver

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by