Logic of find peaks function
조회 수: 6 (최근 30일)
이전 댓글 표시
I have the following time series. I would like to find the peaks in the series that are above 0.79 in magnitude and are three samples away from each other. The time series is below
sigSG = [0 0 0 0 1 0 0 0 1 0.6 0 0 0 0 0.9 0.8 0.7 2 0.9 0 0 0 0 0 0.9 1.5 0.9 0.6 2 0 0 0 0 0.45 0.80 0.86 0.78 1 0.61 0.84 1.015 0.63 0.47 0]
For finding the peaks that are above 0.79 in magnitude and three samples away from each other, I am using the following code
findpeaks(sigSG,'MinPeakDistance',3,'MinPeakHeight',0.79);
This is the result I get
Peaks 1 and 2 are as expected. The findpeaks function finds the peak that is greater that 0.79.
Peaks 3 and 4 are interesting. After the second peak, there is a peak that is above 0.79. But Matlab searches for 3 samples after that peak and selects the third peak. Same is the case for the 4th peak.
Peak 5 is very interesting. At the fifth peak, the conditions are similar to the fourth peak. But the peak selection is very different. I am looking for the logic behind this. Is this random or is there any reason to this?
Peak 6 is similar to the peak 4.
In conclusion, I would like to understand how the findpeaks function finds the peaks.
Please run the two lines of code to understand what I am talking about.
Regards,
Sasank.
댓글 수: 1
Adam Danz
2019년 9월 27일
" I would like to find the peaks in the series that are above 0.79 in magnitude and are three samples away from each other. "
That's a well defined rule that would be easy to code up in a few lines. Findpeaks() is more useful when there is no clear cut, easy implementation to define a peak.
You just need to find which coordinates are y>0.79, get their indices, and make sure the indices are >3 values appart. That's cake! Findpeaks will slow you (and the code) down.
I realize you're asking a more general question about the inner workings of findpeaks (which is explained in the documentation, by the way) so I decided to leave a comment rather than an answer.
채택된 답변
dpb
2019년 9월 27일
As Adam says, the doc does explain...
"When you specify a value for 'MinPeakDistance', the algorithm chooses the tallest peak in the signal and ignores all peaks within 'MinPeakDistance' of it. The function then repeats the procedure for the tallest remaining peak and iterates until it runs out of peaks to consider."
So, in other words, it doesn't work from left to right as you're presuming but by eliminating peaks largest down until it can't find any more that aren't within the distance from one already located.
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!