Finding maxima in blocks of data, consecutively

Problem Statement: I have a time series, x. I am interested in consecutive, temporal blocks of x where x > value. I also want to focus on blocks that are at least time "T" apart. Let x(*) indicate x at time index *. If:
x(m-K), x(m-K+1), x(m-K+2), ...x(m) > value
and, later at n > m + T (a greater time)
x(n-K), x(n-K+1), x(n-K+2), ...x(n) > value
I want to identify the maximal value within each block, while ignoring all temporally consecutive blocks that are less than T samples apart. I currently have a for loops-method that works, but it's clumsy and not great for the application I have in mind.
Application: I am trying to detect certain events, where x exceeds a detection statistic, but I only want events spaced "T" distance apart. Events closer than "T" are considered to be the same.
HELP? Thanks.

 Accepted Answer

Can't you just say
maxValue = max(x(n-K:n));
or similar for m? If you have the Image Processing Toolbox, you can use imdilate(), which is a sliding local maximum. If you want to get the max only of x with values greater than value, then
thresholdedX = x(x>value);
but then I'm not sure if the (n-K) and n apply to the indexes before or after thresholding and extraction of the values above the threshold value, so I can't give the next step for certain.

5 Comments

My apologies for the amibiguity, I clarified the question. The block lengths and number are generally unknown. Unfortunately, I just have the stats and signals box.
How do you define a block (it's starting and ending indexes)? And once you have a block, how do you define how far away some other block is? Is it the min index of one block (the later one) minus the max index of the other block (the earlier one), in other words, the time in between?
I define a block if the time samples (indices) are consecutive--so if a set of time samples for x exceed "value" at indices 100,101,102,103, that is a block. The time between blocks, yes, is the min. of the current block, less the max. index of the preceding block.
Do you have the Image Processing Toolbox? If so you can do this easily. Just threshold and mask and pass to imdilate, then mask again. It's like 4 lines of code.
Thanks for the note! I don't have an image processing toolbox, just the statistics and signal processing box, as I said above. But, maybe I can look up the imdilate code. Thanks again!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!