Finding peaks with a set amplitude range?

2 ビュー (過去 30 日間)
HC98
HC98 2023 年 2 月 10 日
回答済み: Star Strider 2023 年 2 月 12 日
I'm findint the peaks in a signal wich have an amplitude between 0.2 and 1. Trouble is when I call findpeaks via
[pks,locs] = findpeaks(data(1, :),x); %,x);
logicalIndexes = (pks > 0.8) & (pks < 1);
It just returns a bunch of zeros even though I told it not to. Any ideas?
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 2 月 10 日
If you have to finding amplitudes between 0.2 and 1, why are you using 0.8?

サインインしてコメントする。

回答 (2 件)

Mathieu NOE
Mathieu NOE 2023 年 2 月 10 日
hello
see the demo code below :
n = 100;
x= 1:n;
y = rand(1,n);
[pks,locs] = findpeaks(y,x);
logicalIndexes = (pks > 0.8) & (pks < 1);
ind = locs(logicalIndexes);
plot(x,y,x(ind),y(ind),'dr');
  4 件のコメント
HC98
HC98 2023 年 2 月 10 日
How can I get the corresponding x value for the peaks?
Mathieu NOE
Mathieu NOE 2023 年 2 月 12 日
hello again
the x and y values of the peaks as shown above in my demo code are x(ind),y(ind)
n = 100;
x= 1:n;
y = rand(1,n);
[pks,locs] = findpeaks(y,x);
logicalIndexes = (pks > 0.8) & (pks < 1);
ind = locs(logicalIndexes);
plot(x,y,x(ind),y(ind),'dr');

サインインしてコメントする。


Star Strider
Star Strider 2023 年 2 月 12 日
It just returns a bunch of zeros even though I told it not to. Any ideas?
It may seem that a logical vector is returning zeros (false values, and there may be many zeros in it), however if you use:
NonZeroNr = nnz(logicalIndexes)
to find the number of true values, or:
NumericalIndices = find(logicalIndexes)
to return the subscript indices associated with the true values.
.

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by