MATLAB Answers

How to detect peaks above a given threshold value?

37 views (last 30 days)
findpeaks() can detect multiple peaks if there is/are change in direction(s) even if the values are above the specified threshold (see arrows in the attached pdf file).
J=a vector;
findpeaks(J,'MinPeakHeight',Threshold);hold on;
yline(Threshold,'--','LineWidth',3);
hold off

  4 Comments

Show 1 older comment
Sudip Paudel
Sudip Paudel on 20 Jul 2020
Hi Madhan, thank you for asking.
In this specific example, I was using 5, but this threshold can vary.
Sudip Paudel
Sudip Paudel on 20 Jul 2020
Hi Madhan, we will not detect other peaks if I change the threshold value to 20. My goal is to count it only once if the signal goes above the threshold value until it goes below the specified threshold.

Sign in to comment.

Accepted Answer

Rashedur Rahman
Rashedur Rahman on 20 Jul 2020
Hi Sudip.
The function 'findpeaks' can take several input arguments for finding peaks according to criteria. You can use multiple arguments to adjust your peak finding algorithm. I will suggest you to read the description of 'findpeaks'. ('https://www.mathworks.com/help/signal/ref/findpeaks.html').
Another way is to apply a filter to smoothen the signal and then apply 'findpeaks'.

  0 Comments

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 20 Jul 2020
Edited: Image Analyst on 20 Jul 2020
Try flattening the signal by subtracting that red trend line. Then set the values of the signal below the threshold to zero and then call findpeaks()
smoothedSignal = movmean(signal, 101);
flattenedSignal = signal - smoothedSignal;
flattenedSignal(flattenedSignal < someThreshold) = 0;
[peakValues, indexesOfPeaks] = findpeaks(flattenedSignal);
Attach your data in a .mat file if you need more help.

Community Treasure Hunt

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

Start Hunting!