Finding peaks with a set amplitude range?

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 rewrite this to get peak locations?
I have this
amps = arrayfun(@(h2) max((findpeaks(udata(h2, :), x) < 0.99)...
.* findpeaks(udata(h2, :), x)), 1:size(udata, 1));
And I want to rewrite it to get peak locations. When I call x(amps) it gives a logic error...
Mathieu NOE
Mathieu NOE 2023년 2월 10일
I am not sure to understand what you are trying to do
what is the context
how is the data / code that you are using here ?
HC98
HC98 2023년 2월 10일
How can I get the corresponding x value for the peaks?
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일

0 개 추천

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.
.

카테고리

도움말 센터File Exchange에서 Get Started with Signal Processing Toolbox에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 2월 10일

답변:

2023년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by