Skip to content

Instantly share code, notes, and snippets.

@ryanmr
Last active January 19, 2020 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmr/9042bd9e308ed06b587da3923fd20159 to your computer and use it in GitHub Desktop.
Save ryanmr/9042bd9e308ed06b587da3923fd20159 to your computer and use it in GitHub Desktop.

Data in cycles

I'm trying to break a set of data into "cycles" for further processing. The data has no additional flags associated, so I can't identify the cycles any other way except numerically. Visually plotting data shows the cycles, but I'm looking for a robust numerically approach.

example image of cycles

Current approach

Given a list of datapoints...

  1. Calculate a moving average with a length of 4 for all points
  2. Calculate an approximate second derivative by taking the differences between the MAV values, and then the differences again - values here that are negative have the concavity of a peak
  3. Note: in this data set, after the peak is reached, the next value should effectively reset the cycle, causing a major cliff
  4. Keep track of the peak indicies
  5. Calculate the set of indicies directly after the peak indicies
  6. Split the list at these locations

Issues so far

This breaks down when an initial cycle is not long enough, and gets kept in the results of the following cycle. As shown in the example graph above, the cycle 0 could get into cycle 1 if the MAV doesn't smooth it over.

Looking for

What's an industry used approach for this kind of problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment