Hello,
I have the following data
data = [9 12 8 11 10 10 11 12 11 11 12 8 11 9 9 12 8 11 10 12 8 11 12 8 11 10 18 20 10 18 20 24 28 30 31 32 33 33 34 33 32 34 35 32 33 31 30 37 38 39 40 39 40 38 37 40 41 38 37 36 33 32 34 35 32 33 31 30 32 34 31 30 28 26 25 23 20 18 15 12 11 10 10 11 12 11 11 9 12 8 11 10 12 8 9 11 7 9 10 7 3 4 2 1 5 4 3 7 8 9 10 5 4 6 11 12 8 11 12 12 13 14 15 12 13 15 15 16 17 18 19 17 16 15 19 20 21 20 18 17 16 19 21 18 20 24 28 30 31 32 33 30 31 35 36 38 40 42 41 41 42 46 48 47 45 42 40 41 43 40 39 39 38 36 32 34 31 30 28 26 25 23 20 18 15 12 11 10 12 8 9 11 7 9 10 12 11 10 11 10 11 12 11 11 9 12 8 11 10 10 11 12 11 11 9 12 8 11 10 14 15 18 17 16 15 18 19 14 15 17 18 19 20 21 19 18 17 16 15 14 12 15 15 15 16 17 18 18 19 20 20 20 21 19 17 16 17 18 19 22 24 26 29 30 35 37 40 42 44 44 46 48 48 49 50 50 51 52 53 51 52 55 58 57 51 56 57 52 50 49 52 52 51 49 48 46 46 42 43 45 41 42 40 41 43 40 38 37 34 32 28 25 19 15 14 13 12 8 5 3 7 8 9 11 12 10 7 9 14 13 11 10 8 5 4 3 5 7 8 9 10 12 11 6 8 10 7 6 8];
and I need to find exactly 3 peaks in these data, for example:
How can I do that?
Note 1: I always need to find 3 peaks (this value doesn't change), but the X and Y axis range may change.
Note 2: The last peak/curve will always be higher than the other two.
Note 3: I don't need to get the value itself, I need to get the index of the value.

 채택된 답변

Star Strider
Star Strider 2017년 1월 30일

2 개 추천

If you have the Signal Processing Toolbox, use the findpeaks function. It will do what you want. You will have to experiment with its name-value pair arguments to get the ‘correct’ result.

댓글 수: 6

Kelvin Prado
Kelvin Prado 2017년 2월 1일
편집: Kelvin Prado 2017년 2월 1일
Thanks a lot Star Strider. It worked:
findpeaks(data,'MinPeakDistance',20,'NPeaks',3,'MinPeakHeight',mean(data))
But I need to manually set the 'MinPeakDistance' argument based on a previous knowledge of my data.
Do you know if there's some another way that I can find these peaks without using this argument?
Star Strider
Star Strider 2017년 2월 1일
My pleasure.
There are two possible ways to do what you want, depending on how involved you want your code to get. The main peaks look periodic, so taking the fft (link), finding the dominant peak, determining the period from it (inverse of the frequency), and using that as 'MinPeakDistance' is one way I can imagine to automate it. If you subtract the mean of your data from the rest of your data before calculating the fft, you will eliminate the d-c (constant) offset ‘0 Hz’ peak, making it easier to find the lowest-frequency dominant peak.
A slightly more involved option (and the one I would use) is to take the fft to identify the dominant frequency and create a FIR bandpass filter or IIR (Chebyshev Type II) bandpass filter to eliminate the d-c offset and high-frequency noise. If all your data have the same sampling frequency and the same essential spectrum, the bandpass filter approach could (no promises) eliminate the need for any name-value pair arguments.
Image Analyst
Image Analyst 2017년 2월 1일
Not sure I understand why you don't want to use the 'MinPeakDistance' argument. What's wrong with using that to pass in some argument value based on previous knowledge? Why do you need some other way?
Adam
Adam 2017년 2월 1일
Have you tried experimenting with the 'MinPeakProminence' attribute? These 3 peaks should all be quite identifiable by that and maybe a more simple measure to work out a prominence. based on the mean of your data or some percentile value.
Kelvin Prado
Kelvin Prado 2017년 2월 2일
  • Thanks again Star Strider, I will try to use the fft to find the dominant peak and determine the 'MinPeakDistance'. It seems to be relatively easy (in Matlab) and I think it solves my problem.
  • Image Analyst, cause I need to create an algorithm that automatically finds the peaks. The user of my algorithm doesn't need to have a previous knowledge about the data it self, just need to know what time (X axis) each peak occurs.
  • Thanks Adam, I will take a look at the 'MinPeakProminence' attribute. I didn't know about that.
Star Strider
Star Strider 2017년 2월 2일
Our pleasure!

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

추가 답변 (0개)

카테고리

제품

태그

질문:

2017년 1월 30일

댓글:

2017년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by