How to find first crossing of a threshold, then ignore n datapoints after?
80 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?
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