Determine Threshold in Graph

22 次查看(过去 30 天)
Hi all, I want to split my data file into two data files. One with the data of the peaks (above the threshold) and one with the remaining data (under the threshold). Like this:
I have got hundreds of data files so I want to split them in a for loop. My problem is that every dataset has a different threshold value:
All data files have got the same shape, so I wonder if it is possible to let matlab determine the threshold value. My problem is that I can't find the good way to determine the threshold value. Can someone help me out with this?
Thanks, Daan

采纳的回答

Image Analyst
Image Analyst 2015-10-5
To threshold a signal where the "baseline" varies, I think you should take the histogram. Then compute the PDF and cdf. Compute the cdf with cumsum(). If you know that the peaks always occupy, say 3% of the signal, then you can find the gray level of that from the cdf.
Histogram has changed recently. What version of MATLAB do you have? If you have the latest one, use histogram() or histcounts(). If earlier than about R2014b then use hist() or histc().
[counts, binCenters] = hist(data, 100);
cdf = cumsum(counts);
cdf = cdf / cdf(end);
thresholdIndex = find(cdf>0.97);
thresholdLevel = binCenters(thresholdIndex);
logicalIndexes = data > thresholdLevel; % Indexes of peaks.
  6 个评论
Andrew Park
Andrew Park 2020-9-28
编辑:Andrew Park 2020-9-28
Thank you for the answer. I'm not sure if I should make this as a whole separate post, so I'll ask you here first.
If I don't know how much percentage of the total signal the peaks occupy, what would be the best method to set the percentage? For instance, I have graphs that have varying number of peaks, so I don't know how many there are until the algorithm scans the signal once to count them - which will take additional time. As of now, I'm just making an assumption that the 100th largest peak height will suffice as the threshold value.
(If you think I should post this separately, I'll do that.)
Image Analyst
Image Analyst 2020-9-28
编辑:Image Analyst 2020-9-28
Yes, post separately after reading this link so you'll know to do certain things, like including any scripts and data, and a screenshot.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by