why the findpeaks function cant find several peaks in my signal ?? as i observed, it only happen when the peak is flat, as i marked the noticed peaks with red circles from the findpeaks function, and it couldnt notice any flat peaks.Screenshot (84).png
i have been struggling like a few days to find the answer in the internet and i got nothing. Please help. I really appreciate any kind of answer. Thank you in advance.

 Accepted Answer

Star Strider
Star Strider on 5 Feb 2020
If you have R2017b or later, use the islocalmax function, specifcially as described in the Flat Maxima Regions documentation section, using the FlatSelection name-value pair.

4 Comments

bzibubab bzibubab
bzibubab bzibubab on 5 Feb 2020
Edited: bzibubab bzibubab on 5 Feb 2020
but I only have a 2009 version. Maybe is it possible to copy / download the function to the older vesion ?
That is not possible. You would need to upgrade to R2017b (or preferably R2019b).
Meanwhile, try this:
t = linspace(0, 4*pi); % Create Independent Variable
y = sin(t);
y(y>=0.8) = 0.8; % Create Dependent Variable
dy = filtfilt([1 0 0 0 -1], 1, y); % Filter — Simple Differentiator
[dypks,dylocs] = findpeaks(dy) % Peaks & Locations Of ‘dy’
figure
plot(t, y)
hold on
plot(t(dylocs), y(dylocs), '+r')
hold off
grid
ylim([-1 1])
Run that code to understand how it works, then adapt it to your signal.
thank you for the responses, i greatly apprecited it. i tried to adapt the code you sent me, and now i got the answer i was looking for. Thank you so much ^^
As always, my pleasure!

Sign in to comment.

More Answers (0)

Products

Release

R2009a

Community Treasure Hunt

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

Start Hunting!