Rainflow
Fast rainflow counting written in C (C99)
... or use some predefined functions.
[1] ASTM Standard E 1049, 1985 (2011). "Standard Practices for Cycle Counting in Fatigue Analysis", West Conshohocken, PA: ASTM International, 2011.
[2] [https://community.plm.automation.siemens.com/t5/Testing-Knowledge-Base/Rainflow-Counting/ta-p/383093]