A robust, modular implementation of the Rainflow Counting Algorithm using the 4-point method for fatigue analysis. This library is C99 compliant and provides bindings for Python and MATLAB.
Install from PyPI:
pip install rfcntBasic usage:
import numpy as np
import rfcnt
# Your measurement data
data = np.array([0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0])
# Perform rainflow counting
result = rfcnt.rfc(data, class_width=0.5)
print(f"Damage: {result['damage']}")
print(f"Cycles: {result['rp']}")#include "rainflow.h"
rfc_ctx_s ctx;
double data[] = {0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0};
RFC_init(&ctx, 100, 0.5, 0.0, 0.5, RFC_FLAGS_DEFAULT);
RFC_feed(&ctx, data, 7);
RFC_finalize(&ctx, RFC_RES_REPEATED);
double damage;
RFC_damage(&ctx, &damage, NULL);
RFC_deinit(&ctx);- Modular architecture - Select features at compile time
- Multiple counting methods - 4-point, HCM (Clormann/Seeger), ASTM
- Streaming capability - Process data sample-by-sample or in chunks
- Fatigue analysis - Wöhler curves, Miner's rule (4 variants), damage history
- Flexible histograms - Rainflow matrix, level crossing, range pairs
- Language bindings - Python (NumPy), MATLAB, C/C++
- Standards compliant - ASTM E 1049, DIN 45667, FKM guidelines
Table of Contents
Explore the full documentation in the docs/ folder:
- Documentation Index
- Complete documentation index with all topics organized by category
Core Documentation:
- Algorithm
- Detailed explanation of the rainflow counting algorithm, including the 4-point method, hysteresis filtering, and residue handling.
- ASTM Method
- ASTM E 1049 counting method vs. 4-point algorithm - why it's more efficient
- Features
- Complete feature list with compile-time options, counting methods, fatigue analysis capabilities, and language bindings.
- Installation
- Build instructions for all platforms (Windows, Linux, macOS) with Python, MATLAB, and C/C++ configurations.
- Examples
- Practical code examples in Python, C/C++, and MATLAB demonstrating various use cases and workflows.
Advanced Topics:
- C++ Wrapper
- Modern C++ interface with RAII, templates, and STL integration
- Damage History
- Track cumulative damage over time for predictive maintenance
- Delegates
- Custom behavior via function pointers and callbacks
- Turning Points
- External storage and management of turning points
- Residue Methods
- Different approaches for handling unclosed cycles
- Spread Damage
- Transient damage distribution methods explained
- Minimal Build
- RFC_MINIMAL for embedded systems and microcontrollers
- TP Prune
- RFC_tp_prune() logic for memory management
- References
- Bibliography and citations for standards, publications, and resources.
Rainflow Counting is a standardized method for analyzing fatigue in materials subjected to variable amplitude loading. The algorithm extracts discrete load cycles from complex time-varying stress-strain histories.
The core algorithm examines sequences of four consecutive turning points (A, B, C, D) to identify closed cycles:
* D
/ \
B *<--/ A cycle B-C is closed if:
/ \ / min(B,C) >= min(A,D) &&
/ * C max(B,C) <= max(A,D)
\ /
* A
When closed, the cycle B-C is:
- Counted in the histogram
- Removed from the residue
- Assigned damage based on the configured Wöhler curve
See docs/algorithm.rst for detailed explanation.
Using CMake (all platforms):
cmake -S. -Bbuild -G "Visual Studio 16 2019"
cmake --build build --config ReleaseOr on Linux/macOS:
cmake -S. -Bbuild
make -C buildBuild a Python wheel package:
cd src/python
pip install setuptools build wheel oldest-supported-numpy
python -m build -nwFor detailed build instructions, including MATLAB integration and custom feature selection, see docs/installation.rst.
Run the unit tests to verify your installation:
cmake --build build --target rfc_test --config Release
build/test/Release/rfc_test # Linux/macOS
build\test\Release\rfc_test.exe # WindowsOr use CTest:
cd build
ctest -C Releasepython -m rfcnt.run_testspython -m rfcnt.run_examples- Version: 0.5.2
- C Standard: C99 compliant
- Test Status:
- Languages: C, C++, Python, MATLAB
- Platforms: Windows, Linux, macOS
This library is suitable for:
- Fatigue life prediction in mechanical engineering
- Structural health monitoring of bridges, vehicles, aircraft
- Materials testing and characterization
- Load spectrum analysis for component design
- Real-time monitoring in embedded systems
The implementation follows these standards:
- ASTM E 1049 (2011) - Standard Practices for Cycle Counting
- DIN 45667-1:2025-12 - Mechanische Schwingungen - Zählverfahren für die Betriebsfestigkeit - Teil 1: Vorverarbeitung (signal preprocessing, turning point extraction)
- DIN 45667-2:2025-12 - Mechanische Schwingungen - Zählverfahren für die Betriebsfestigkeit - Teil 2: Zählverfahren (cycle counting algorithms and residue handling)
- FKM Guidelines - Analytical strength assessment
- FVA-Richtlinie - Counting methods for drive technology
See docs/references.rst for full bibliography.
The package uses a two-layer architecture:
- Core C Library (
src/lib/rainflow.c) - Pure C99 implementation with optional feature flags for customization.
Suitable for embedded systems and microcontrollers when built with
RFC_MINIMAL. - C++ Wrapper (
src/lib/rainflow.hpp) - Modern C++ interface with templates, containers, and RAII patterns. Provides object-oriented access and easier integration with C++ projects.
- Language Bindings
- Python extension (
src/python/src/rfcnt.cpp) with NumPy support - MATLAB MEX interface for use in MATLAB/Simulink
- Python extension (
Customize the build with compile-time flags:
RFC_MINIMAL- Core counting onlyRFC_TP_SUPPORT- Turning point storageRFC_HCM_SUPPORT- HCM algorithmRFC_ASTM_SUPPORT- ASTM variantRFC_DH_SUPPORT- Damage historyRFC_DAMAGE_FAST- Lookup tables for speed
See docs/features.rst for complete list.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Report issues at: https://github.com/a-ma72/rainflow/issues
See the LICENSE file in the repository for licensing information.
If you use this software in your research, please cite:
@software{rainflow,
author = {Andreas Martin},
title = {Rainflow Counting Algorithm},
year = {2026},
url = {https://github.com/a-ma72/rainflow},
version = {|version|}
}This implementation is based on the work described in the references section. Special thanks to the authors of ASTM E 1049 and the HCM method (Clormann/Seeger).
For questions, suggestions, or collaboration:
- GitHub Issues: https://github.com/a-ma72/rainflow/issues
- Repository: https://github.com/a-ma72/rainflow
---
Documentation Structure:
rainflow/
├── README.rst ← Readme
└── docs/
├── index.rst ← Documentation index (start here)
├── algorithm.rst ← Algorithm explanation
├── features.rst ← Feature descriptions
├── installation.rst ← Build instructions
├── examples.rst ← Code examples
├── references.rst ← Bibliography
├── astm_method.rst ← ASTM E1049 vs 4-point method
├── cpp_wrapper.rst ← C++ wrapper guide
├── damage_history.rst ← Damage tracking over time
├── delegates.rst ← Custom callbacks & extensibility
├── turning_points.rst ← Turning point storage & management
├── residue_methods.rst ← Residue handling methods
├── spread_damage.rst ← Damage spreading methods
├── minimal_build.rst ← Embedded systems build
└── tp_prune.rst ← Memory management with pruning
Start exploring with docs/index.rst for organized navigation, docs/algorithm.rst for algorithm details, or jump directly to docs/examples.rst for practical usage.