pyfopid
Fractional-order modelling and control in Python.
pyfopid provides tested, documented building blocks for fractional-order
control: Grünwald-Letnikov operators, Oustaloup rational approximations,
and a discrete-time FOPID (PI^λD^μ) controller that interoperates with
python-control and exports to C for
embedded targets (Arduino, ESP32, STM32).
Status: alpha (0.1.0.dev0). API may change before 1.0.
Installation
pip install pyfopid # once released on PyPI
pip install -e ".[test]" # development install from a clone
Requires Python ≥ 3.10, NumPy, SciPy and python-control ≥ 0.10.
Quick start
import numpy as np
import pyfopid as pf
# Fractional derivative of order 0.5 of t^2 (Grünwald-Letnikov)
h = 1e-3
t = np.arange(0, 1 + h, h)
d = pf.gl_derivative(t**2, 0.5, h)
# Oustaloup approximation of s^0.5 in [0.01, 100] rad/s as a control.TransferFunction
G = pf.oustaloup(0.5, wb=1e-2, wh=1e2, N=5)
# Discrete FOPID controller (accumulated fractional integral, filtered
# derivative on the measurement, saturation with anti-windup)
c = pf.FOPID(kp=2.0, ki=1.0, kd=0.1, lam=0.9, mu=0.5, dt=0.01, memory=2000,
u_min=0.0, u_max=12.0,
derivative_on="measurement", d_filter_tau=0.05)
u = c.step(error=0.3, measurement=24.7)
# Export the same controller to a C header for a microcontroller
open("fopid.h", "w").write(c.to_c_header("fopid"))
See examples/closed_loop.py for a full
closed-loop simulation.
Features (v0.1)
| Module | Contents |
|---|---|
operators |
gl_weights, gl_derivative (with short-memory principle), fractional_integral, caputo_derivative |
approx |
oustaloup (any real order; integer part realised exactly), ZPK, freqresp_zpk |
controller |
FOPID: accumulated (default) or direct GL fractional integral, derivative on error or measurement, first-order derivative filter, conditional-integration anti-windup and integral clamp, bumpless reset(), .tf() (Oustaloup-based continuous model), .to_c_header() (C99, same options) |
Design notes
- Accumulated integral (default).
s^-λ = s^-1 · s^(1-λ): the fractional operator of order1-λis evaluated with a GL sum and followed by an integer integrator. This keeps genuine integral action (zero steady-state error) for any memory length. The direct GL integral (integral="gl") has a finite DC gain when the memory is truncated. - Memory length. The fractional behaviour is effective for frequencies
above roughly
1/(L·dt)rad/s. ChooseL·dtcomparable to the dominant time constants of the plant. - Derivative. For
μ > 1noise amplification is severe; used_filter_tau. With non-integerμthe GL derivative of a constant is not zero, so differentiating the error and differentiating the measurement are not equivalent even for a constant set point;derivative_on="measurement"also removes the set-point kick.
Verification
The test suite (pytest) checks:
- GL weights against the signed binomial coefficients
(-1)^j C(α, j), including the sign pattern. - GL derivatives and integrals against closed-form results
(
D^α t^k = Γ(k+1)/Γ(k+1−α) t^(k−α),I^α 1 = t^α/Γ(1+α)) and the expected first-order convergence O(h). - Caputo derivatives (constants map to zero; orders above one with initial conditions).
- Oustaloup approximations against
(jω)^α: with the band[wb, wh]chosen at least two decades wider than the frequency range of interest, errors are < 0.05 dB and < 0.5°. One decade from the band edges the phase error rises to ≈ 3° for |α| = 0.5; this is dominated by band truncation, not byN. - Exact reduction of
FOPIDto the classical discrete PID for λ = μ = 1 in both integral modes. - Closed-loop tracking with and without saturation; zero steady-state error of the accumulated integral with a short memory.
- Sample-by-sample agreement (rtol 1e-9) in closed loop with an independent transcription of an FOPID firmware used on a Peltier test bench.
- Cross-validation against FOMCON 1.50.4 (MATLAB): Oustaloup approximations
identical to round-off for |α| ≤ 0.5 and more accurate for |α| > 0.5
(0.54° vs 5.09° phase error at α = −0.9); FOPID time response identical to
FOMCON
lsim(relative difference 7.5e-12). Seevalidation/fomcon. - Compiled C output against Python for all integral/derivative options.
Citing
If you use pyfopid in research, please cite it using the metadata in
CITATION.cff. A DOI will be issued through Zenodo with the
first release.
Contributing
Bug reports, questions and pull requests are welcome. See CONTRIBUTING.md for the development set-up and the Code of Conduct.
Acknowledgements
pyfopid is developed at the University Institute of Intelligent Systems and Numerical Applications in Engineering (SIANI), University of Las Palmas de Gran Canaria. The author thanks Carlos Sánchez Morales and Federico León Zerpa (Department of Process Engineering) and Alejandro Ramos Martín (SIANI) for their supervision and for their review of the experimental work in which the library was used.
License
BSD 3-Clause. See LICENSE.
Metadata
Release files for pyfopid 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyfopid-0.1.0.tar.gz | 112.6 kB | With provenance | Details for pyfopid-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyfopid-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pyfopid-0.1.0-py3-none-any.whl |
Total release size: 126.7 kB
Release files / pyfopid-0.1.0.tar.gz
| Download URL | pyfopid-0.1.0.tar.gz |
|---|---|
| Size | 112.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c83e8c5fc5c5479ed7f10c532582c533b9625bac974e660e3855bb8eacbe87fa
|
|
BLAKE2b-256 checksum How to use checksums |
f69100c184029f20a4d7220206ca8ba7d9a0915da88cc095c72d72fb7cdd7eab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logRelease files / pyfopid-0.1.0-py3-none-any.whl
| Download URL | pyfopid-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69d057037acd2672e96ce83a7902c70468b68a72b868d1990eef361ef76625bb
|
|
BLAKE2b-256 checksum How to use checksums |
f8af3ee65bab3f0da57995ff67ad53cd9af4377b102cb50bc0265dee97e943e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logSecurity for pyfopid 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyfopid-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.