Threshold in my plot.
Show older comments
I have a plot (Amplitude vs time), and I want to obtain the first time determined amplitude appears in my plot. Let's say I have my plot, and the amplitude ranges from -1 to 1, and I decide that the threshold is 0.5, it means that I want to know the time (x-value) that this amplitude was first recorded. How can I do it?
Accepted Answer
More Answers (1)
Joseph Cheng
on 10 Jun 2015
Edited: Joseph Cheng
on 10 Jun 2015
use the function find and any logical operators to determine the position in the array you are at/above/below the threshold.
amp = -1:.1:1;
time = 1:numel(amp);
thres = .5;
tsample = find(amp==thres);
figure,plot(time,amp,time(tsample(1)),amp(tsample(1)),'rx')
you didn't mention crosses, above, and/or below in your question but at the threshold. so i used the == to determine when you are at the threshold. If there is more to the question about detecting rising and falling edges threshold the signal using the threshold and then use diff() to determine positive or negative transitions.
3 Comments
Image Analyst
on 10 Jun 2015
This will work for powers of 2 or inverse powers of 2. For other floating point numbers you need to use a tolerance if you want to check for "equality", see the FAQ. Also, time is a built-in function so you would not want to use that as a variable name.
Joseph Cheng
on 10 Jun 2015
Edited: Joseph Cheng
on 10 Jun 2015
very true, but is time() a built in function? I air coded the above and just opened matlab to check the doc on time() but found nothing. Which toolbox is it in?
Image Analyst
on 11 Jun 2015
It's in base MATLAB, at least it's in the R2015a version:

Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!