How does MINPEAKDISTANCE work?

28 Ansichten (letzte 30 Tage)
med-sweng
med-sweng am 30 Sep. 2014
Beantwortet: Jeremy Young am 18 Jan. 2019
I'm trying to understand how `MINPEAKDISTANCE` works. I returned to the documentation, here , but it wasn't very clear how this parameter works.
Can you kindly clarify it a bit?
Thanks.

Antworten (1)

Jeremy Young
Jeremy Young am 18 Jan. 2019
Hi, I also had this question and noted that it is not well documented in the standard documentation as you have seen.
As a tip, you can directly open most MATLAB functions to see how they operate: use
open functionname
e.g.
open findpeaks
There will be a lot of code there for efficiency, but you should be able to extrude meaning from necessary parts.
In this case, you can find the part regarding minpeakdistance here:
%--------------------------------------------------------------------------
function idx = findPeaksSeparatedByMoreThanMinPeakDistance(y,x,iPk,Pd)
% Start with the larger peaks to make sure we don't accidentally keep a
% small peak and remove a large peak in its neighborhood.
if isempty(iPk) || Pd==0
IONE = ones('like',getIZERO);
idx = (IONE:length(iPk)).';
return
end
% copy peak values and locations to a temporary place
pks = y(iPk);
locs = x(iPk);
% Order peaks from large to small
if coder.target('MATLAB')
[~, sortIdx] = sort(pks,'descend');
else
sortIdx = coder.internal.sortIdx(pks,'d');
end
locs_temp = locs(sortIdx);
idelete = ones(size(locs_temp))<0;
for i = 1:length(locs_temp)
if ~idelete(i)
% If the peak is not in the neighborhood of a larger peak, find
% secondary peaks to eliminate.
idelete = idelete | (locs_temp>=locs_temp(i)-Pd)&(locs_temp<=locs_temp(i)+Pd);
idelete(i) = 0; % Keep current peak
end
end
% report back indices in consecutive order
idx = sort(sortIdx(~idelete));
You can trace the code, but what it does is find the largest peaks first and then searches the sorrounding neighborhood around it (i.e. +/- meanpeakdistance) for any peaks then deletes those. The neighborhood around the deleted peaks are not searched. And as mentioned, this is done from largest to smallest peak.
An alternative method to figuring this out would have been to try a number of examples to see if you're getting what you expect. However, looking at the code, you can see clearly what is going on.
I see you asked this question many years ago, I hope you were able to find your answer before this.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by