Determine Threshold in Graph
22 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149724/image.jpeg)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149726/image.jpeg)
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
0 Commenti
Risposta accettata
Image Analyst
il 5 Ott 2015
To process lots of files, see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
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 Commenti
Andrew Park
il 28 Set 2020
Modificato: Andrew Park
il 28 Set 2020
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
il 28 Set 2020
Modificato: Image Analyst
il 28 Set 2020
Yes, post separately after reading this link so you'll know to do certain things, like including any scripts and data, and a screenshot.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!