MATLAB: How to find the peaks in the signal with descending order only

descending orderfindpeaksMATLAB C/C++ Math Librarypeaks

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.

Best Answer

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.