Search code examples
pythontime-seriessignal-processingbioinformaticsdata-preprocessing

Determining the Begin and End of Each Cycle in Quasi-Sinusoidal Timeseries Using Python


I'm working on a project where I have quasi-sinusoidal bio-signal data collected from a sensor that's attached to an athlete's arm. I have to determine where each rep of the exercise the athlete performs starts and where it ends. For example, given the signal in the figure below, the output should be something like

Ex1: Timestamp1 - Timestamp2
Ex2: Timestamp2 - Timestamp3
...

I should leave out the rest periods, which are marked in red. Is there any Python library that offers such a method? If not, are there any published methods that I can look up and implement myself?

I have thought about utilizing the fact that each rep usually starts or ends when the signal crosses zero. However, crossings happen often during the rest period, and they might occur more than once during the exercise. (See the crossing next to the Timestamp2 crossing). So, I'm not sure if this fact could be utilized or not.

If you have a suggestion or a method in mind, I would be grateful if you could also mention whether this method is suitable for signals from multiple sensors, i.e., whether it could determine where the beginning and the end of each exercise is based on signals collected from multiple sensors attached to the athlete, not just the arm one.Example of a biosignal timeseries


Solution

  • My idea is such:

    1. (optional) clear noise with some low-pass filtering.
    2. find all peaks (top and bottom), you can use scipy.signal.find_peaks or some self-written code
    3. group peaks into "single period pairs"
    4. iterating from the top peak to the left, find first timestamp for which value gets close enough to 0, thats your excercise beginning
    5. same to the right of the bottom peak - thats your end of the exercise