I am trying to translate a find_peaks function call in python to matlab and they use a max threshold
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mette Dittmann
le 28 Mar 2022
Commenté : Star Strider
le 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 commentaires
Réponse acceptée
Star Strider
le 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 commentaires
Star Strider
le 30 Mar 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

