MATLAB Answers

How do I pick the largest peaks in a region?

Bharath Lohray 님이 질문을 제출함. 21 Jun 2017
최근 활동 Bharath Lohray 님이 편집함. 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
% killed.
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];
scatter (test_peaks(:,1),test_peaks(:,2),'o');
hold on
scatter (mP(:,1),mP(:,2),'*');

  댓글 수: 0

로그인 to comment.


답변 수: 1

Michelle Hirsch 님의 답변 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.

  댓글 수: 1

I just tried and discovered that findpeak() does not work on matrices. It needs a vector :-(

로그인 to comment.

Translated by