How to find the time of the max peak in a signal?

조회 수: 6 (최근 30일)
Jan Ali
Jan Ali 2021년 5월 23일
댓글: Star Strider 2021년 5월 23일
I have a signal data (x) which is 2s long. There is a peack on the signal that I can find with the findpeaks(x) function.
I am wondering how to find the conrresponding time?
Thanks in advance,

채택된 답변

Star Strider
Star Strider 2021년 5월 23일
The easiest way is to have findpeaks return the indices in the second output —
t = ...; % Time Vector
s = ...; % Signal Vector
[pks,locs] = findpeaks(y);
peak_time = t(locs)
.
  댓글 수: 2
Jan Ali
Jan Ali 2021년 5월 23일
Thanks for the answer. However, how can I get the max peak and corresponding time in a matrix?
I run the : [s,f,t] = stft(x,fs); where s is 61x1533 complex double
then:
[pks,locs] = findpeaks(s);
Error using findpeaks
Expected Y to be real.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
>> [pks,locs] = findpeaks(abs(s));
Error using findpeaks
Expected Y to be a vector.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Star Strider
Star Strider 2021년 5월 23일
The findpeaks fucntion only operates on vectors, so it will be necessary to iterate through individual rows or columns (since I cannot determine that from what you wrote).
Also, it will be necessary to use the abs function to take calculate the magnitude of the complex elements that you input to findpeaks.
From the documentation for the input data:
Input data, specified as a vector. data must be real and must have at least three elements.
.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by