This page explains what problem each of the three stages of DRTxECM solves, which numerical methods it uses, and which parts follow pyDRTtools and which are newly added extensions.
An electrochemical impedance spectrum can be written in the integral form of a distribution of relaxation times (DRT, Distribution of Relaxation Times):
If there is inductive behavior at the high-frequency end, a series inductance term is added:
γ(ln τ) is the DRT result. Because γ is a continuous function while the measured data are finite and noisy, this inversion problem is ill-posed: solving it directly yields a violently oscillating solution with no physical meaning. The pyDRTtools approach is to discretize γ with basis functions and then introduce regularization.
Expanding γ in a set of basis functions, γ(ln τ) = Σn xn φn(ln τ), and substituting this into the integral turns the problem into a linear system A x = b, where b is the measured impedance (the real and imaginary parts may be concatenated). The objective is then ridge regression (Tikhonov regularization):
λ is the regularization parameter and M is a matrix determined by the order of the derivative. If λ is too large it flattens γ and destroys resolution; if λ is too small, oscillatory spurious peaks appear. The choice of λ is the most critical step in DRT analysis.
| Option | Description |
|---|---|
| custom | λ is specified manually by the user |
| GCV | Generalized Cross-Validation |
| mGCV | A modified GCV |
| rGCV | A robust GCV |
| LC | The L-curve method |
| kf | K-fold cross-validation |
| re-im | Real-part / imaginary-part cross-validation |
| Basis | Characteristics |
|---|---|
| Gaussian | The default; smooth and the most stable for general use |
| C2 Matern | The Matern family, with adjustable smoothness (C2 → C6, increasingly smooth in that order) |
| C4 Matern | |
| C6 Matern | |
| Inverse Quadratic | Long-tailed; suited to broad relaxation-time distributions |
| Inverse Quadric | Another long-tailed form |
| Cauchy | Long-tailed, less prone to sharp peaks |
| PWL | Piecewise linear; it does not use Toeplitz acceleration, so it is slower to compute but the least restrictive |
The width of the basis is determined by RBF Shape Control (FWHM Coefficient or
Shape Factor), and its value is specified by FWHM Control, default 0.5.
This width determines the resolution limit of the DRT.
| Method | Principle |
|---|---|
| Simple Run | Tikhonov / ridge regression (the method described above), solved by optimization. Parameter Selection Method determines λ |
| Bayesian Run | Bayesian regularization: the noise variance and the regularization hyperparameter are treated as unknowns to be inferred, and the solution is obtained by sampling the posterior distribution |
| Hilbert Transform | BHT (Bayesian Hilbert Transform): the Kramers-Kronig relations are used to link the real and imaginary parts, and the problem is then solved within a Bayesian framework |
The package also contains implementations of GP-DRT (fGP.py, Gaussian process) and HMC
(HMC.py, Hamiltonian Monte Carlo), but the graphical interface currently provides no
buttons for them; they can be called directly from the Python API. All of the DRT computations above
reuse the original pyDRTtools source code; DRTxECM has made no changes to it.
The γ(ln τ) obtained from the DRT is a continuous curve, but a real physical system is usually made up of a finite number of relaxation processes. The second stage fits this curve with several Gaussian functions:
This is a nonlinear least-squares problem, solved with scipy.optimize.curve_fit with an
iteration limit of 10000. The number of peaks is specified by the user (the Number of peaks
field in the interface), and after the fit you can manually fine-tune the amplitude, position and
width of any peak.
This is the bridge between the second and the third stage. Each Gaussian peak corresponds to one
R//CPE branch, converted as follows (implemented in Stage2Window.export_to_stage3):
| Circuit parameter | Converted from the peak parameters |
|---|---|
| Resistance R | R = A · σ · √(2π) |
| Time constant τ | τ = exp(μ) |
| CPE parameter Q | Q = τ / R |
| Phase angle α | α = 1.0 (a starting value; it is determined by the fit only afterwards) |
The rationale for the conversion is that A·σ·√(2π) is the area of the
Gaussian on the ln τ axis, corresponding to the total resistance R contributed by that relaxation
process; and when α = 1, the time constant of the R//CPE branch is exactly τ = R·Q, so Q is
back-calculated from τ and R. The center position μ of the peak is ln τ, so taking the
exponential recovers τ.
This is the "DRT-informed initial guess": the starting values are not random guesses but are derived from the relaxation-time structure of the data itself, which greatly reduces the chance of the nonlinear fit falling into a local minimum.
The equivalent circuit used by DRTxECM is a series LR0 + Σ(Ri//CPEi):
where the impedance of a single CPE is:
When α = 1, Q degenerates to an ideal capacitance C and the branch becomes a standard RC semicircle; when α < 1, the semicircle in the Nyquist plot is depressed and its center falls below the real axis. The degree of depression corresponds directly to the value of α, which is also where the shape of this website's logo comes from.
The fit minimizes the sum of squares over the real and imaginary parts of the complex impedance simultaneously (CNLS, Complex Nonlinear Least Squares):
The optimizer is L-BFGS-B from scipy.optimize.minimize (a limited-memory
quasi-Newton method that supports upper and lower bounds on the parameters), with the convergence
tolerances set to ftol = gtol = 1e-12.
| Parameter | Available modes | Corresponding bounds |
|---|---|---|
| R, Q | Free, Free +-5%, Free +-10%, Fixed |
Free → [0, ∞); Free +-5% → ±5% of the current value; Free +-10% → ±10% of the current value; Fixed → excluded from the optimization vector |
α (n_i) |
Free, <= 1, Fixed |
<= 1 → [0.2, 1.0]; Free → [0.2, 1.05]; Fixed → excluded from the optimization vector |
| L | Free, Fixed |
Free → (−∞, ∞); Fixed → excluded from the optimization vector |
A parameter set to Fixed is not placed in the optimization variable vector,
and therefore does not count towards the degrees of freedom p.
The interface defaults are: Fixed for R, Q and L, and <= 1 for α.
After the optimization converges, the program computes the degrees of freedom and the mean squared error, and then estimates the covariance from the inverse Hessian matrix:
The inverse Hessian returned by L-BFGS-B is in the form of a LinearOperator; the program
converts it into a dense matrix before computing. If it cannot be obtained, the program falls back to
a numerical Jacobian approximation. This is the source of the Error and Error% columns
in the Stage 3 parameter table.
This is the most important design decision in DRTxECM. Real electrode surfaces are rough and reactions are non-uniform, so the CPE α is usually clearly below 1 (commonly between 0.7 and 0.95). Many commercial equivalent-circuit programs, however, fix α at 1, or restrict it to a very narrow range, in order to keep convergence stable.
Doing so has two consequences:
DRTxECM optimizes α together with R and Q, so you can distinguish "this branch really is close
to an ideal capacitor" from "this branch only looks like an ideal capacitor because it was fixed".
The default bounds [0.2, 1.0] cover the great majority of the actual CPE values reported
in the literature.
| Capability | General-purpose circuit-fitting software | pyDRTtools | DRTxECM |
|---|---|---|---|
| DRT computation | No (or requires a plugin) | Complete (Tikhonov, Bayesian, BHT, GP-DRT) | Complete (reused, unmodified) |
| Equivalent-circuit fitting | Complete | No | Yes (LR0 + ΣR//CPE) |
| CPE phase angle α | Usually fixed or range-limited | Not applicable | Fitted freely (0.2–1.05) |
| Source of initial values | Manual entry or random | Not applicable | Converted automatically from the DRT peaks |
| Parameter uncertainty | Available in some | Not applicable | Yes (inverse-Hessian estimate) |
| License | Mostly commercial | MIT | MIT |
The DRT method of the first stage builds on the existing work of pyDRTtools; for all the mathematical derivations, equation numbers and original references, see Citation & Credits. If you use these results in a paper, please be sure to cite the corresponding original references.