Extract consecutive data points between 2 thresholds

2 views (last 30 days)
For a project, i have data in the form of wind speed (m/s) recorded with 1 minute intervals, starting from 2009 through to 2021. For the time of each recording I have created a datetime array in the form of yyyy:MM:dd_HH:mm:ss, and for the wind speed recorded at each minute i have created a double array.
The wind speed ranges from 0 through to 40+ m/s. For the project, any wind speeds above 30m/s will cause damage to some machinery and hence, occurances where windspeed exceeds 30m/s must be recorded. Additionally, for each case where wind speed data exceeds 30m/s, i need to find the time taken (in minutes based on the datetime data) for the wind speed to go from 20m/s to the 30m/s limit. So the extracted data points between 20 and 30 m/s must be consequtive, which will allow me to find the time taken for cases where wind speed gradually increases from 20 to 30 m/s. Im not too fussed on the method used to extract the data with said conditions, so any sort of direction/help would be greatly appreciated.
  4 Comments
Walter Roberson
Walter Roberson on 8 Sep 2021
Should there be a sliding window (what width?) in which the condition is set true if mean() over the window is > 30, or median() over the windows is > 30, or if count of (data>30) is > 1 ?
Joshua Pretorius
Joshua Pretorius on 5 Oct 2021
Hi Walter, sorry for the late reply.
Im able to use a moving average to smoothen the data set and get rid of instances where the wind speed quickly drops below the threshold. Based on different trials, a moving average of 5-10 does a good job.

Sign in to comment.

Answers (1)

KSSV
KSSV on 7 Sep 2021
Let t be your dates in datetime format and w be your wind data.
% get indices of wind lying in [20, 30]
idx = w>= 20 & w <= 30 ; % results into logical indexing
t1 = t(idx) ; % extract those dates
w1 = w(idx) ; % extract the wind data
  2 Comments
Walter Roberson
Walter Roberson on 7 Sep 2021
This does not handle the idea that the points must be consecutive.
KSSV
KSSV on 7 Sep 2021
From the obtained dates, calculate the diff, wherever diff is 1, those indices can be picked.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!