Extract peaks and troughs from a curve

조회 수: 103 (최근 30일)
Mustafa Sobhy
Mustafa Sobhy 2019년 7월 29일
댓글: Star Strider 2019년 7월 29일
How to extract only peaks and troughs from a curve
2.jpg

채택된 답변

Star Strider
Star Strider 2019년 7월 29일
If you want to identify the individual peaks and troughs, use islocalmax and islocalmin, or findpeaks on the positive and negative versions of your signal respectively:
[pks, pklocs] = findpeaks(s);
[troughs,trlocs] = findpeaks(-s);
where ‘s’ is youir signal vector.
  댓글 수: 2
Mustafa Sobhy
Mustafa Sobhy 2019년 7월 29일
So how can I rearrange peaks and troughs consecutively like (peak, trough, peak, trough, ...) ?
Thanks!!
Star Strider
Star Strider 2019년 7월 29일
As always, my pleasure!
Create a matrix of the peaks, troughs and locations, then use sortrows:
[pks, pklocs] = findpeaks(s); % Original Peaks
[troughs,trlocs] = findpeaks(-s); % Original Troughs
pktr = [pklocs(:), pks(:); trlocs(:) -troughs(:)]; % Location, Value Matrix
pktrs = sortrows(pktr); % Location, Value Matrix Sorted By Location
Since with findpeaks the troughs are detected using the negative of the original vector, their amplitudes in the ‘pktr’ matrix are negated to correct for that, presenting the actual values.
The sortrows function sorts by default on the first column. If you use a different configuration for ‘pktr’ you need to specify the column for the locations so that sortrows know which one to sort on.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by