Peak finder - finding major peaks instead of just the smaller ones

I want to use a peak finder to find the major peaks in my spectrum, however, when I use {pks, locs] = peakfinder()
I get all the small peaks as well. I just want the main five

Answers (2)

You can do:
findpeaks(y,'NPeaks',5,'SortStr','descend')
This gets you the five with the largest amplitude. If you want the five with the largest prominence, you can do:
[pks,locs,~,prm] = findpeaks(y);
[~,i] = sort(prm,'descend');
plot(1:numel(y),y,'-',locs(i(1:5)),y(locs(i(1:5))),'o ')

1 Comment

how would you do this to find the five minimum peaks?
i.e. within acceleration data, the most prominent negative peaks

Sign in to comment.

minimum_peak=10 % For example
[pks,locs]=findpeaks(your_signal,'MINPEAKHEIGHT',minimum_peak)

3 Comments

yea I thought of using minpeakheight but my peaks aren't very strong as you can probably see from the plot I included as an attachment. For some reason my peaks are not too good. i think it because I have a large spike at 0Hz which is an error. I dont really know how to get rid of it though. It may be due to g as my data is from an accelerometer?
You need some criterion to get rid of unwanted peaks
You could also transform your data prior to detecting the peaks. Maybe a log transform would be enough?

Sign in to comment.

Asked:

on 16 Jan 2014

Edited:

on 27 Dec 2021

Community Treasure Hunt

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

Start Hunting!