AlgDiff
Python toolbox with MATLAB interface and GUI for the design, analysis, and discretization of algebraic differentiators.
AlgDiff is an open-source Python package that provides all the tools needed for the design, analysis, and discretization of algebraic differentiators. An interface to MATLAB and a standalone graphical user interface are also provided. The implementation was released as part of the survey (Othmane et al., 2022); a tutorial on algebraic differentiators and on the package itself is given in (Othmane & Rudolph, 2023), and the software is archived on Zenodo (Othmane, 2024).
The code was created for research purposes at the Chair of Systems Theory and Control Engineering of Saarland University. We apply algebraic differentiators to a variety of problems in control theory and signal processing: parameter estimation, feedback control, fault detection and fault-tolerant control, and model-free control.
Installation
The package is on PyPI, so a single command is enough:
pip install AlgDiff
No further setup is required to start designing differentiators; see getting started below.
Motivation
Estimating the derivatives of noisy signals is of paramount importance in many fields of engineering and applied mathematics. It is, however, a longstanding ill-posed and challenging problem, in the sense that a small error in the measurement data can induce a significant error in the estimated derivatives.
The figure below compares the numerical estimation of the first time derivative of a noisy signal using an algebraic differentiator with the one obtained by the simple difference quotient rule, and illustrates the excellent performance of this numerical differentiation approach.
On algebraic differentiators
Algebraic differentiators have been derived and discussed in the systems and control theory community. The initial works, based on differential-algebraic methods, were developed by Mboup, Join, and Fliess in Numerical differentiation with annihilators in noisy environment. These numerical, non-asymptotic approximation approaches for higher-order derivatives of noisy signals are well suited for real-time embedded systems. A historical overview and a detailed discussion of the time-domain and frequency-domain properties of these differentiators are given in the survey (Othmane et al., 2022).
The approximation-theoretic derivation recalled in the survey allows the estimation process to be interpreted in three steps:
- Projection. At time \(t\), the sought \(n\)-th order derivative \(y^{(n)}\) over the interval \(I_T(t)\) is projected onto the space of polynomials of degree \(N\), which yields the polynomial \(p_N\).
- Evaluation. The polynomial \(p_N\) is evaluated at \(t-\delta_t\), which gives the estimate \(\hat{y}^{(n)}(t)=p_N(t-\delta_t)\). Choosing the delay as the largest root of a special Jacobi polynomial increases the approximation order by one with a minimal delay. Alternatively, a delay-free estimation or even a prediction of the future derivative can be selected, at the cost of a reduced accuracy.
- Repetition. The first two steps are repeated at each discrete time instant \(t_i\) while keeping the parameters of the differentiator constant, which yields the estimate \(\hat{y}^{(n)}\).
Algebraic differentiators can be interpreted as linear time-invariant filters with a finite-duration impulse response, and they can be approximated as lowpass filters with a known cutoff frequency and stopband slope. The figure below shows the amplitude and phase spectra of two exemplary filters together with the lowpass approximation of the amplitude spectrum. Details on the parametrization of these differentiators are given in (Othmane et al., 2022) and (Othmane et al., 2021), as well as in the work of Kiltz and Rudolph on the parametrization to achieve desired filter characteristics and the frequency-domain analysis and tuning by Mboup and Riachy.
Graphical user interface
Since version 1.1 a GUI is provided. Executable files for Linux and Windows are available on the release page and require no additional software: neither Python nor MATLAB has to be installed to design algebraic differentiators, obtain discrete filter coefficients, and estimate derivatives.
The GUI plots the relevant data (impulse and step responses, amplitude and phase spectra, estimated derivatives, …), displays the relevant properties of the differentiators (estimation delay, cutoff frequency, window length, discretization effects, …), and loads measured signals for the estimation of their derivatives without a single line of code. Properties, signals, spectra, and discrete filter coefficients can be exported for further processing. A sample data set for testing the import of measurement data is included in the folder DataForGUI.
Getting started
The contribution of the implementation is an easy-to-use framework for the design and discretization of algebraic differentiators achieving desired filter characteristics, i.e. a specified cutoff frequency and stopband slope. The file algebraicDifferentiator.py implements the class AlgebraicDifferentiator, which contains all functions for the design, analysis, and discretization of the differentiators.
Examples are provided both as Jupyter notebooks and as MATLAB live scripts:
- a quick start as a notebook, also available as an HTML file;
- a detailed notebook, also available as an HTML file;
- the simultaneous elimination of a harmonic disturbance and approximation of derivatives in a notebook, also available as an HTML file;
- a quick start in MATLAB and a MATLAB script with several examples.
Requirements
The code is implemented in Python 3; the packages required for the full functionality are listed in requirements.txt. The Python examples are written as Jupyter notebooks and additionally require jupyter_latex_envs for the generated documentation and matplotlib for the plots. The functions of the toolbox can also be used from MATLAB; see the MATLAB documentation for the compatibility of your MATLAB version with Python.
Documentation and support
A detailed documentation of all functions is provided on the project page, together with a list of known issues and fixes. Suggestions and questions are welcome by email.
License
AlgDiff is distributed under the BSD 3-Clause “New” or “Revised” License, which is suitable for both academic and industrial/commercial purposes.