Wajih
Wajih

Reputation: 791

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

Upvotes: 17

Views: 16414

Answers (2)

slayton
slayton

Reputation: 20319

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.

Upvotes: 8

yuk
yuk

Reputation: 19870

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.

Upvotes: 7

Related Questions