How do I pick the largest peaks in a region?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bearbeitet: Bharath Lohray am 21 Jun. 2017
The following MATLAB code takes in multiple peak coordinates and heights and eliminates lesser peaks that are within a certain distance threshold of the highest peak of the vicinity. Is there a better way to implement this code? Does a more efficient algorithm exist?
function [ the_peaks ] = max_peaks( peak_list, vicinity_threshold )
%MAX_PEAKS(peak_list, vicinity_threshold) returns the highest peaks within
%the vicinity specified by the vicinity_threshold.
% peak_list is an array with rows defined by [x,y, amplitude]
% vicinity_threshold is the distance within which all lesser peaks are
the_peaks=zeros(size(sorted_peaks)); % Preallocate
the_peaks(peak_idx,:)=sorted_peaks(1,:); %The greatest peak.
D=pdist2(sorted_peaks(1:end,1:2),sorted_peaks(1,1:2)); %Distance to other peaks
np=D<vicinity_threshold; % Peaks in the vicinity
sorted_peaks(np,:)=; % Kill peaks in the vicinity
the_peaks(~any(the_peaks,2),:)=; % clear preallocated extras
test_peaks=[1,1,0.5; 5,5,0.9; 5,1,0.6; 300,300,0.2; 303,303,0.7; 1,100,0.9; 1,104,0.95; 1,250,.7; 1,200,.75];
Michelle Hirsch am 21 Jun. 2017
If you are up for replacing the peak finding, and have Signal Processing Toolbox, you could consider trying findpeaks. The MinPeaksDistance option keeps just the highest peak in a neighborhood of peaks.
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!