Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect the two highest Peaks from Histogram

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?

enter image description here

like image 481
Wajih Avatar asked Apr 24 '12 16:04

Wajih


2 Answers

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.

like image 89
slayton Avatar answered Sep 20 '22 07:09

slayton


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.

like image 30
yuk Avatar answered Sep 20 '22 07:09

yuk