フィルターのクリア

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 Center および File ExchangeDescriptive Statistics についてさらに検索

製品


リリース

R11.1

Community Treasure Hunt

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

Start Hunting!

Translated by