DRTxECM

v0.2.0 繁體中文

Method

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.

① DRT deconvolutionTikhonov-regularized linear inversion
→
② Gaussian peak decompositionNonlinear least squares (multi-Gaussian)
→
③ CNLS fittingBounded nonlinear optimization (L-BFGS-B)

Stage 1: DRT deconvolution

An electrochemical impedance spectrum can be written in the integral form of a distribution of relaxation times (DRT, Distribution of Relaxation Times):

Z(ω) = R∞ + ∫ γ(ln τ) / (1 + jωτ)  d ln τ

If there is inductive behavior at the high-frequency end, a series inductance term is added:

Z(ω) = R∞ + jωL + ∫ γ(ln τ) / (1 + jωτ)  d ln τ

γ(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.

Discretization and Tikhonov 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):

minx   ‖A x − b‖2 + λ ‖M x‖2

λ 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.

OptionDescription
customλ is specified manually by the user
GCVGeneralized Cross-Validation
mGCVA modified GCV
rGCVA robust GCV
LCThe L-curve method
kfK-fold cross-validation
re-imReal-part / imaginary-part cross-validation

Discretization bases

BasisCharacteristics
GaussianThe default; smooth and the most stable for general use
C2 MaternThe Matern family, with adjustable smoothness (C2 → C6, increasingly smooth in that order)
C4 Matern
C6 Matern
Inverse QuadraticLong-tailed; suited to broad relaxation-time distributions
Inverse QuadricAnother long-tailed form
CauchyLong-tailed, less prone to sharp peaks
PWLPiecewise 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.

Other DRT algorithms

MethodPrinciple
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.

Stage 2: Gaussian peak decomposition

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:

γ(ln τ) ≈ Σi Ai · exp( −(ln τ − μi)2 / (2 σi2) )

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.

From peaks to circuit initial values

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 parameterConverted from the peak parameters
Resistance RR = A · σ · √(2π)
Time constant ττ = exp(μ)
CPE parameter QQ = τ / 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.

Stage 3: CNLS equivalent-circuit fitting

Circuit model

The equivalent circuit used by DRTxECM is a series LR0 + Σ(Ri//CPEi):

Z(ω) = R0 + jωL + Σi   1 / ( 1/Ri + Qi(jω)αi )

where the impedance of a single CPE is:

ZCPE = 1 / ( Q (jω)α )

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.

Objective function and optimization

The fit minimizes the sum of squares over the real and imaginary parts of the complex impedance simultaneously (CNLS, Complex Nonlinear Least Squares):

χ2(x) = Σk [ ( Re Zexp,k − Re Zsim,k )2 + ( Im Zexp,k − Im Zsim,k )2 ]

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.

ParameterAvailable modesCorresponding 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 α.

Parameter uncertainty

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:

dof = 2N − p   (N is the number of frequency points and p the number of optimized parameters)
mse = χ2 / dof
cov = H−1 · mse
Errorj = √( covjj )

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.

Why the CPE phase angle α is treated as a free parameter

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.

How DRTxECM differs from other tools

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

Theoretical foundations and citations

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.