Using findpeaks to find peaks and troughs, how can I make sure that I always find a peak then a trough?

5 views (last 30 days)
[Maxima,MaxIdx] = findpeaks(Peak,'MinPeakHeight',mean(Peak),'MinPeakDistance',10);
Mins=1.01*max(Peak)-Peak;
[Minima,MinIdx] = findpeaks(Mins,'MinPeakHeight',mean(Mins),'MinPeakDistance',10);
Minima = Peak(MinIdx);
So using this code I get indices of the peaks and troughs separately. Sometimes I get two peak indices in a row or two trough indices in a row. I know that I can change the peak distance value to try and correct this but it is not foolproof since my data is not consistent (think random frequency sine wave) so I cannot process the whole set with a single minpeakdistance unless I pick a small one that guarantees it will catch eveything.
Is there a way to combine the two index outputs such that it goes peak-trough-peak-trough..... forever?

Answers (0)

Community Treasure Hunt

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

Start Hunting!