Is there a way to detect a defined interval of time between boolean states and if true, switch the boolean state within this interval?

2 views (last 30 days)
I am currently defining machine process cycles from a hydraulic pressure signal. The signal has been cleaned and I have created a simple script to output a Boolean state vector when the certain conditions are met. However, there are unpredictable pressure spikes that evade these Boolean conditions and cause <=5 second gaps between what is known to be a continuous machine process. Is it possible to detect these time gaps and set the Boolean vector to one when the duration of the localised low state is below a threshold, e.g. 5 seconds?

Answers (1)

Jan
Jan on 22 Feb 2019
The description is far too complicated. Actually you have a logical vector and want to remove blocks of TRUE (or FLASE?) is they are shorter then n elements (I cannot know, how many elements are meant by "5 seconds"). Then:
data = (rand(1, 1e6) < 0.2); % A logical vector
[B, N] = RunLength(data);
B(B & N < 50) = false; % Set TRUE with less than 50 elements to FALSE
B(~B & N < 20) = true; % Set FALSE with less than 20 elements to TRUE
cleaned = RunLength(B, N);

Categories

Find more on Data Import and Analysis 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!