I was trying to understand on how to detect the two peaks from the histogram. There can be multiple but I need to pick the two highest. Basically what I need to to is that although I will have these peaks shifted left or right, I need to get hold of them. Their spread can vary and their PEAK values might change so I have to find a way to get hold of these two peaks in Matlab.
What I have done so far is to create a 5 value window. This window is populated with values from the histogram and a scan is performed. Each time I move 5-steps ahead to the next value and compare the previous window value with current. Which ever is greater is kept.
Is there a better way of doing this?
The simplest way to do this would be to first smooth the data using a gaussian kernel to remove the high frequency variations.
Then use the function localmax
to find the local maximums.
Return data from hist (or histc) function to a variable (y = hist(x,bin);
) and use PEAKFINDER FileExchange submission to find local maximums.
I have also used PEAKDET function from Eli Billauer. Works great. You can check my answer here with code example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With