I am trying to translate a find_peaks function call in python to matlab and they use a max threshold
3 views (last 30 days)
Show older comments
Mette Dittmann
on 28 Mar 2022
Commented: Star Strider
on 30 Mar 2022
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!!
0 Comments
Accepted Answer
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.
.
2 Comments
Star Strider
on 30 Mar 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
More Answers (0)
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
