graph - Using findpeaks and minpeakdistance in MATLAB to find peaks separated by distance rather than index -
i'm trying x-coordinates of peaks in matlab figure (example attached). i've been using findpeaks
, doesn't seem fact i'm plotting points rather lines.
i won't have 2 peaks. i'll have three, i'll have one. multiple peaks separated @ least 1/4 of range of x, , peaks @ least twice noise level.
here's expect work:
[pks,locs] = findpeaks(ydata,... 'sortstr','descend',... 'minpeakdistance',floor(range(xdata)/4),... 'minpeakheight',floor(max(ydata)/2)... )
instead of getting 2 peaks, 4 bundled around first peak:
>> locs locs = 6774 166785 326792 486799 >> xdata(locs) ans = -96780.787939025 -96770.1800919265 -96770.8959353367 -96771.6117787468
i assume minpeakdistance working on in xdata indices rather data itself. how use distances between peaks instead of distance between indices of peaks?
findpeaks
doesn't know x-coordinates or have plotted. need specify minpeakdistance
in terms of indices. here's example:
xdata = -100:1:-1; ydata = rand(1,100); ydata(10) = 100; % peak ydata(11) = 99; % not peak ydata(50) = 100; % peak ydata(51) = 99; % not peak [pks,locs] = findpeaks(ydata,... 'sortstr','descend',... 'minpeakdistance',floor(length(ydata)/4),... 'minpeakheight',floor(max(ydata)/2)... ); xlocs = xdata(locs); pks = 100 100 locs = 10 50
Comments
Post a Comment