Clear Filters
Clear Filters

I am trying to translate a find_peaks function call in python to matlab and they use a max threshold

10 views (last 30 days)
Hi,
I am using matlab to recreate a script done in python. They use the python function find_peaks, which is very similar as the Matlab function.
One major difference is that when using the threshold specification, Matlab only has a minimum threshold option, whilst in python it is also possible to insert a max threshold.
Does anybody know how to implement using a max threshold in findpeaks in matlab?
Python example: find_peaks(sig, distance=distance, threshold=(None, 5.0), prominence=(20, None))
Thanks a lot in advance!!

Accepted Answer

Star Strider
Star Strider on 28 Mar 2022
There is no 'MaxPeakHeight' so impose the maximum condition after the findpeaks call to limit the maximum peak values considered.
t = linspace(0, 10);
sig = sum(sin((1:2:9)'*2*pi*t));
[pks1,locs1] = findpeaks(sig);
figure
plot(t, sig)
hold on
plot(t(locs1), pks1, '^r')
hold off
grid
title('Plot All Peaks')
Lv = (pks1 <= 3); % Logical Vector To Keep Peaks <= 3
figure
plot(t, sig)
hold on
plot(t(locs1(Lv)), pks1(Lv), '^r')
hold off
grid
title('Plot Only Peaks <= 3')
There may be other ways to do this. I chose the ‘logical vector’ approach.
.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!