I need to find the window of increasing trend and decreasing trend in a time series data. For example in the below plot, it has 3 increasing trend and 2 decreasing trend. I need identify the windows having this trend.
I tried using 'smoothed z-score algorithm' provided in Peak signal detection in realtime timeseries data. But am not getting the expected result.
Here increasing/decreasing trend may continue from 1sec to 1 minute. Also the height of peak may varies from 20 to 200.
Difference between current peak with next peak will not work here, since there will be minor fluctuations in the data.
Please suggest some idea here to use adaptive algorithm to detect the trend and its duration
CodePudding user response:
One can start by taking the gradient to detect the points where the signal changes direction and check the rise/drop in the neighborhood of this point to identify false/true rise (or fall).
Take a look at the inbuilt function to compute gradient : numpyp.gradient()
.
Difference between current peak with next peak will not work here, since there will be minor fluctuations in the data.
In that case, I would first try to define clearly what constitutes a window and a minor fluctuation; and then go about writing an algorithm to do it.