How to find first crossing of a threshold, then ignore n datapoints after?

39 views (last 30 days)
I have a huge amount of data in a 2 column array. The first column corresponds to time, the second to a value at that time. I want to find all of the points at which the data crosses above a certain threshold. I am not interested when it comes back down across the threshold (it always does). This is also somewhat noisy data. My best solution was to find when x>4.7 (or whatever threshold), and then ignore everything for 50 seconds, then repeat (there should be 5 times when there's an ascending threshold cross). Unfortunately I can't get this to work...unsure of how to store these times when there is an ascending threshold cross and also can't seem to figure out a way to ignore for 50s. Any ideas?

Answers (2)

Siddharth Sundar
Siddharth Sundar on 29 Oct 2014
If I understand correctly, you just want to be able to find the indices where your values in a vector cross a certain threshold in the positive direction while excluding the values where the threshold is crossed while moving in the negative direction.
Here is some commented script that does exactly that:
thresh = 1.7; % Specify threshold
x = [1.8 1.3 1.6 1.7 1.2 1.2 1.7 1.8 1.7 1.8 2 2.3 4.1 3 1.2 1.4 1.7 2.1];
% Essentially need to pick out values which exceed threshold with the condition that the previous value
% needs to be below the threshold
idxl = x>=thresh;
idxl(1) = 0;
idx = find(idxl);
yest = x(idx-1)<thresh;
idx(yest) % Final output
  1 Comment
krishna kireeti
krishna kireeti on 7 Mar 2017
Dear sir, I had a huge data in matrix form and I want to know how many times does the data between a given period crossed the threshold value, can you help with the code?

Sign in to comment.


simith
simith on 1 Sep 2017
please how to write a code to check number of up crossing and down crossing for a level in matlab

Community Treasure Hunt

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

Start Hunting!