MATLAB Answers

How to find the peak/most prevalent values in a set of data (max x-value of histogram)?

21 次查看(过去 30 天)
Naveen
Naveen2015-7-14
回答: Steven Lord ,2015-7-15
I am analyzing acoustic waveforms and I have used MATLAB to make a table for each test that calculates and lists several parameters (amplitude, peak frequency, duration, etc.) for each waveform. I want to compare these signals between different tests, and as a result, I want to summarize each of the parameters for each test. For example, I think it would be useful to compare the average duration of all 83 waveforms in Test 1 with the average duration of all 102 waveforms in Test 2. I can do this, but I've realized that the average isn't very useful for some parameters since the dataset has such a large range and some outliers disproportionately weigh the average.
So now instead of finding the average for each parameter, I want to find the values that are most prevalent.
For example, take this dataset (representing the duration in microseconds for 23 acoustic waveforms that occurred in one test).
duration = [212 61 276 213 188 62 212 275 214 212 32 62 62 250 63 61 96 77 64 32 62 213 64];
The average for this is 133. However, just by looking at the data (and confirmed via a histogram), it's clear that there are two values that are much more prevalent (around 212 and 62) than the rest, so the average of 133 doesn't really reveal much. I'm looking to write a script that automatically picks out these values that occur significantly more often than other values in the dataset. To simplify my question, let's say I only want my script to find the one value that occurs most often (in this case, 62).
To start with, my thought process was to make a histogram and then find the x-axis value of the bin with the highest intensity.
r = round(range(duration));
h = histogram (duration,r/4)
If you plot this histogram, it looks like the most prevalent value is in the bin that represents 60-64 microseconds. From there, I can just split the difference and say that 62 microseconds is the most prevalent duration in this set of waveforms.
I'm looking for the code that will give me this. I know it might not be the most statistically sound since within that bin, there might be an uneven distribution so that splitting it in half and saying 62 microseconds might not be the most accurate. But for my current purposes, that is okay.
  2 个评论
Image Analyst
Image Analyst 2015-7-15
Without seeing your signals and histograms, it's too much of a brain strain tonight (for me at least) to try to imagine what they look like. You'd probably get more answers if you showed some plots of your signals and histogram.

请先登录,再进行评论。

回答(2 个)

the cyclist
the cyclist 2015-7-14
Here is another method that might be helpful. Kernel smoothing methods do that kind of "these values are likely to be from around here", in a non-parametric way.
The ksdensity function from the Statistics and Machine Learning Toolbox implements this. Here is one way to handle your problem.
[peakDensity,xi] = ksdensity(duration)
[maxDensity,peakIndex] = max(peakDensity)
peakLocation = xi(peakIndex)
This shows you what the smoothed density looks like:
figure
ksdensity(duration)

Steven Lord
Steven Lord 2015-7-15
Use HISTCOUNTS instead of HISTOGRAM. HISTCOUNTS returns the bin counts directly (as well as the bin edges) so you can then use MAX or SORT on those counts.

Community Treasure Hunt

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

Start Hunting!

Translated by