필터 지우기
필터 지우기

Max Peak Distance (findpeaks)

조회 수: 43 (최근 30일)
Stefano Francavilla
Stefano Francavilla 2017년 10월 4일
댓글: Devendra 2024년 4월 6일
Hi, I'm using the 'findpeaks' function and i want to insert a min and max limit to the distance between the peaks. In the function there is only the parameter 'MinPeakDistance' and i need the equivalent "maxpeakdistance" too. Any suggestions? Thanks
  댓글 수: 1
Janak Thotakura
Janak Thotakura 2017년 10월 12일
Can you explain what exactly do you mean by 'maxpeakdistance' in finding peaks? An example would be helpful.

댓글을 달려면 로그인하십시오.

답변 (2개)

The Matlabinator
The Matlabinator 2017년 10월 14일
I'm wondering about this too. There's a 'MinPeakDistance' that rejects peaks which are located within some specified distance. Is there an equivalent for peaks located above some threshold value?

Stefano Francavilla
Stefano Francavilla 2017년 10월 14일
I wrote this code, it isn't elegant but I hope could be helpful.
%%1st step - Find a large amount of peaks with non-stringent constraints
x = zeros(N,1); % x-vector (what you want)
y = zeros(N,1); % y-vector (what you want)
minpeakheight = 0; % what you want (fairly small value)
minpeakdistance = 0; % what you want (fairly small value)
[peak_vals,peak_locs] = findpeaks(y,x,'MinPeakHeight',minpeakheight,'MinPeakDistance',minpeakdistance);
ref = 0; % reference (what you want)
mpd = ref*0.9; % min peak distance (what you want)
MPD = ref/0.9; % Max Peak Distance (what you want)
%%2nd step - Find 1st peak
[~,index] = max(peak_vals(peak_locs<peak_locs(1)+mpd)); % index of the 1st peak
new_peak_locs = peak_locs(index); % position of the 1st peak
new_peak_vals = peak_vals(index); % value of the 1st peak
%%3rd step - Find other peaks
while peak_locs(end)>new_peak_locs(end)+mpd
index = find(peak_locs>new_peak_locs(end)+mpd & peak_locs<new_peak_locs(end)+MPD);
[~,jj] = max(peak_vals(index));
new_peak_locs(end+1) = peak_locs(index(jj)); % peaks position vector
new_peak_vals(end+1) = peak_vals(index(jj)); % peaks value vector
end
  댓글 수: 1
Devendra
Devendra 2024년 4월 6일
Thank you very much for providing very helpful matlab code to matlab community. I am very much eager to use your code on my NDVI time series data. I am attaching the NDVI data and my humble request to you please suggest me how to use your code on my data file. Further my thresholds for peaks height is 0.4 (NDVI value greater than 0.4) and distance is 60 days. With these constraints I want to find out number of peaks and they must be stored in a vector.
I would be highly obliged to you for your kind cooperation. Devendra

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by