How to find the peaks in the signal with descending order only?

3 visualizaciones (últimos 30 días)
The following code find the peaks in my signal perfectly.
[pks,locs] = findpeaks(Power,depth,'MinPeakDistance',100,'MinPeakProminence',4);
But I am more interested in the descending order peaks and the code should exclude the values not following the desceding order pattern.
For instance at locs = [1,2,3,4,5,6,7], pks are [100,80,60,70,50,80].
Required: [pks1,locs1] = function_descending(pks,locs);
I only need pks and corresponding locs which are only in descending order like the result should be locs1=[1,2,3,5] and pks1=[100,80,60,50]. It should exclude the values which contradicts the descending phenomena. The values of 70 at position 4 and 80 at position 6 are excluding because they are higher then all preceeding numbers.
  1 comentario
Syed Abdul Salam
Syed Abdul Salam el 28 de Ag. de 2019
Example 2:
pks = [100,80,60,70,50,80,90,100,51];
locs = [1,2,3,4,5,6,7,8,9];
result should be
pks1 = [100,80,60,50];
locs1 = [1,2,3,5]

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 28 de Ag. de 2019
This works, with the example you provided:
pks = [100,80,60,70,50,80]';
locs = [1,2,3,4,5,6]';
dpks = diff([pks(1); pks]); % Non-Descending Will Be Positive
Lv = dpks <= 0; % Logical Vector Mask
pks1 = pks(Lv); % New Peaks
locs1 = locs(Lv); % New Locs
figure
plot(locs, pks, '^')
hold on
plot(locs1, pks1, 's')
hold off
It does not do any rigorous checking, and just looks ad adjacent peaks.
You can easily wrap it in a function:
function [pks1,locs1] = descending_peaks(pks,locs)
dpks = diff([pks(1); pks]); % Non-Descending Will Be Positive
Lv = dpks <= 0; % Logical Vector Mask
pks1 = pks(Lv); % New Peaks
locs1 = locs(Lv); % New Locs
end
Experiment to get the result you want.
  3 comentarios
Syed Abdul Salam
Syed Abdul Salam el 28 de Ag. de 2019
Thanks I have done it with the help of your code, just repeating it many times.
function [pks1,locs1] = descending_peaks(pks,locs)
for i = 1:length(pks)-1
dpks = diff([pks(1); pks]); % Non-Descending Will Be Positive
Lv = dpks <= 0; % Logical Vector Mask
pks = pks(Lv); % New Peaks
locs = locs(Lv); % New Locs
end
pks1 = pks;
locs1 = locs;
end
Star Strider
Star Strider el 28 de Ag. de 2019
As always, my pleasure!
I was considering that option as well, although I was considering a one-pass solution. If I develop one, I will post back here.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R11.1

Community Treasure Hunt

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

Start Hunting!

Translated by