필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Syed Abdul Salam
Syed Abdul Salam 2019년 8월 28일
댓글: Star Strider 2019년 8월 28일
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
Syed Abdul Salam
Syed Abdul Salam 2019년 8월 28일
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]

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2019년 8월 28일
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
Syed Abdul Salam
Syed Abdul Salam 2019년 8월 28일
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 2019년 8월 28일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R11.1

Community Treasure Hunt

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

Start Hunting!

Translated by