Logic of find peaks function
Mostrar comentarios más antiguos
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 comentario
Adam Danz
el 27 de Sept. de 2019
" 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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Descriptive Statistics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!