How to get a specified number of local maxima?
I have a signal and I only want the top two or three local maxima, I don’t want the 5000 maxima that the findpeaks() function gives me. Is there a way to get this? Thanks.
ANSWER
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
function[val,idx]=nthMaxima(P0,n)
%P0 is the array for searching maximus in there
%n is the number of top maximus to find
val=zeros(1,n); %defining array for reserving value of maximus
idx=zeros(1,n); %defining array for index of maximus for i=1:n
[val(i),idx(i)]=max(P0); %taking maximu value and indexing
P0(idx(i))=-Inf; %replacing maxima index with -Inf to search for maxima again
end%recovering the replaced maxima value
for j=1:n
P0(idx(j))=max(j);
end
%done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end
SEE COMPLETE ANSWER CLICK THE LINK
https://www.matlabsolutions.com/resources/how-to-get-a-specified-number-of-local-maxima-.php