Qu

rlkk_reconstruct

Builtin index · Signal processing

result = rlkk_reconstruct(Z, freqs, [lambda=1e-4], [fx=])

Input: Z, freqs, lambda, fx · Output: result

What it is

Z: a length-N complex vector (CVec); freqs: a length-N real vector (Hz); lambda (optional number): regularization strength, larger tolerates noisier data at the cost of fitting detail; fx (optional length-M real vector, Hz): overrides the default DRT frequency grid (logspace(-8, 8, 160), i.e. M=160).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = rlkk_reconstruct(Z, freqs, [lambda=1e-4], [fx=])
Z vector or CVecZ: a length-N complex vector (CVec).
freqs vectorfreqs: a length-N real vector (Hz).
lambda number, optional (default 1e-4)lambda (optional number): regularization strength, larger tolerates noisier data at the cost of fitting detail.
fx vector, optionalfx (optional length-M real vector, Hz): overrides the default DRT frequency grid (logspace(-8, 8, 160), i.e.
Model —kind "rlkk"
z CVeca length-N CVec, the reconstructed spectrum
gamma vectora length-M real vector, the fitted DRT coefficients
Returns a Model (kind "rlkk") with fields z (a length-N CVec, the reconstructed spectrum) and gamma (a length-M real vector, the fitted DRT coefficients). Fits the regularized Distribution of Relaxation Times (DRT) and reconstructs Z from it.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

Z = [100 - 20i, 80 - 45i, 50 - 55i, 30 - 35i, 22 - 12i]   # measured impedance

freqs = [0.1, 1, 10, 100, 1000]                          # Hz


fit = rlkk_reconstruct(Z, freqs, lambda = 1e-4) # fit.z, fit.gamma

v = rlkk_validate(Z, freqs, lambda = 1e-3, threshold = 2.0)
if v.valid
    print("consistent within {v.max_residual:.2f}%")
else
    print("bad points: {where(abs(v.residuals) > 2.0)}")
end if
output
consistent within 0.00%

from specialized

freqs = logspace(0, 4, 20)
R = 100
C = 1e-6
w = 2 * pi * freqs
Z = R / (1 + 1j * w * R * C)         # a simple RC impedance, as measured data


fit = rlkk_reconstruct(Z, freqs, lambda=1e-4)     # fit.z, fit.gamma

v = rlkk_validate(Z, freqs, lambda=1e-3, threshold=2.0)
if v.valid
    print("measurement is causal/linear/stable within {v.max_residual}%")
else
    print("bad points: {where(abs(v.residuals) > 2.0)}")
end

nyquist(Z)   # Re(Z) vs -Im(Z), the standard EIS view

output
measurement is causal/linear/stable within 0.013416%
-200 -100 0 100 200 300 400 500 -200 0 200 400 600 800 x=0.21, y=0 x=0.21, y=0 x=0.21, y=0 x=0.21, y=0 x=0.21, y=0 x=0.21, y=0 x=0.21, y=$10^{-9}$ x=0.21, y=$1.1\times10^{-9}$ x=0.21, y=$1.2\times10^{-9}$ x=0.21, y=$1.3\times10^{-9}$ x=0.21, y=$1.4\times10^{-9}$ x=0.21, y=$1.5\times10^{-9}$ x=0.21, y=$1.7\times10^{-9}$ x=0.21, y=$1.8\times10^{-9}$ x=0.21, y=$2\times10^{-9}$ x=0.21, y=$2.1\times10^{-9}$ x=0.21, y=$2.3\times10^{-9}$ x=0.21, y=$2.5\times10^{-9}$ x=0.21, y=$2.7\times10^{-9}$ x=0.21, y=$2.9\times10^{-9}$ x=0.21, y=$3.2\times10^{-9}$ x=0.21, y=$3.4\times10^{-9}$ x=0.21, y=$3.7\times10^{-9}$ x=0.21, y=$4\times10^{-9}$ x=0.21, y=$4.4\times10^{-9}$ x=0.21, y=$4.8\times10^{-9}$ x=0.21, y=$5.2\times10^{-9}$ x=0.21, y=$5.6\times10^{-9}$ x=0.21, y=$6.1\times10^{-9}$ x=0.21, y=$6.6\times10^{-9}$ x=0.21, y=$7.1\times10^{-9}$ x=0.21, y=$7.7\times10^{-9}$ x=0.21, y=$8.4\times10^{-9}$ x=0.21, y=$9.1\times10^{-9}$ x=0.21, y=$9.9\times10^{-9}$ x=0.21, y=$1.1\times10^{-8}$ x=0.21, y=$1.2\times10^{-8}$ x=0.21, y=$1.3\times10^{-8}$ x=0.21, y=$1.4\times10^{-8}$ x=0.21, y=$1.5\times10^{-8}$ x=0.21, y=$1.6\times10^{-8}$ x=0.21, y=$1.7\times10^{-8}$ x=0.21, y=$1.9\times10^{-8}$ x=0.21, y=$2\times10^{-8}$ x=0.21, y=$2.2\times10^{-8}$ x=0.21, y=$2.4\times10^{-8}$ x=0.21, y=$2.6\times10^{-8}$ x=0.21, y=$2.8\times10^{-8}$ x=0.21, y=$3.1\times10^{-8}$ x=0.21, y=$3.3\times10^{-8}$ x=0.21, y=$3.6\times10^{-8}$ x=0.21, y=$3.9\times10^{-8}$ x=0.21, y=$4.2\times10^{-8}$ x=0.21, y=$4.6\times10^{-8}$ x=0.21, y=$5\times10^{-8}$ x=0.21, y=$5.4\times10^{-8}$ x=0.21, y=$5.9\times10^{-8}$ x=0.21, y=$6.4\times10^{-8}$ x=0.21, y=$6.9\times10^{-8}$ x=0.21, y=$7.5\times10^{-8}$ x=0.21, y=$8.1\times10^{-8}$ x=0.21, y=$8.8\times10^{-8}$ x=0.21, y=$9.5\times10^{-8}$ x=0.21, y=$10^{-7}$ x=0.21, y=$1.1\times10^{-7}$ x=0.21, y=$1.2\times10^{-7}$ x=0.21, y=$1.3\times10^{-7}$ x=0.21, y=$1.4\times10^{-7}$ x=0.21, y=$1.5\times10^{-7}$ x=0.21, y=$1.7\times10^{-7}$ x=0.21, y=$1.8\times10^{-7}$ x=0.21, y=$2\times10^{-7}$ x=0.21, y=$2.1\times10^{-7}$ x=0.21, y=$2.3\times10^{-7}$ x=0.21, y=$2.5\times10^{-7}$ x=0.21, y=$2.7\times10^{-7}$ x=0.21, y=$3\times10^{-7}$ x=0.21, y=$3.2\times10^{-7}$ x=0.21, y=$3.5\times10^{-7}$ x=0.21, y=$3.8\times10^{-7}$ x=0.21, y=$4.1\times10^{-7}$ x=0.21, y=$4.4\times10^{-7}$ x=0.21, y=$4.8\times10^{-7}$ x=0.21, y=$5.2\times10^{-7}$ x=0.21, y=$5.7\times10^{-7}$ x=0.21, y=$6.1\times10^{-7}$ x=0.21, y=$6.7\times10^{-7}$ x=0.21, y=$7.2\times10^{-7}$ x=0.21, y=$7.8\times10^{-7}$ x=0.21, y=$8.5\times10^{-7}$ x=0.21, y=$9.2\times10^{-7}$ x=0.21, y=$10^{-6}$ x=0.21, y=$1.1\times10^{-6}$ x=0.21, y=$1.2\times10^{-6}$ x=0.21, y=$1.3\times10^{-6}$ x=0.21, y=$1.4\times10^{-6}$ x=0.21, y=$1.5\times10^{-6}$ x=0.21, y=$1.6\times10^{-6}$ x=0.21, y=$1.8\times10^{-6}$ x=0.21, y=$1.9\times10^{-6}$ x=0.21, y=$2.1\times10^{-6}$ x=0.21, y=$2.2\times10^{-6}$ x=0.21, y=$2.4\times10^{-6}$ x=0.21, y=$2.6\times10^{-6}$ x=0.21, y=$2.9\times10^{-6}$ x=0.21, y=$3.1\times10^{-6}$ x=0.21, y=$3.4\times10^{-6}$ x=0.21, y=$3.6\times10^{-6}$ x=0.21, y=$4\times10^{-6}$ x=0.21, y=$4.3\times10^{-6}$ x=0.21, y=$4.7\times10^{-6}$ x=0.21, y=$5\times10^{-6}$ x=0.21, y=$5.5\times10^{-6}$ x=0.21, y=$5.9\times10^{-6}$ x=0.21, y=$6.4\times10^{-6}$ x=0.21, y=$7\times10^{-6}$ x=0.21, y=$7.6\times10^{-6}$ x=0.21, y=$8.2\times10^{-6}$ x=0.21, y=$8.9\times10^{-6}$ x=0.21, y=$9.6\times10^{-6}$ x=0.21, y=$10^{-5}$ x=0.21, y=$1.1\times10^{-5}$ x=0.21, y=$1.2\times10^{-5}$ x=0.21, y=$1.3\times10^{-5}$ x=0.21, y=$1.4\times10^{-5}$ x=0.21, y=$1.6\times10^{-5}$ x=0.21, y=$1.7\times10^{-5}$ x=0.21, y=$1.8\times10^{-5}$ x=0.21, y=$2\times10^{-5}$ x=0.21, y=$2.2\times10^{-5}$ x=0.21, y=$2.3\times10^{-5}$ x=0.21, y=$2.5\times10^{-5}$ x=0.21, y=$2.8\times10^{-5}$ x=0.21, y=$3\times10^{-5}$ x=0.21, y=$3.2\times10^{-5}$ x=0.21, y=$3.5\times10^{-5}$ x=0.21, y=$3.8\times10^{-5}$ x=0.21, y=$4.1\times10^{-5}$ x=0.21, y=$4.5\times10^{-5}$ x=0.21, y=$4.9\times10^{-5}$ x=0.21, y=$5.3\times10^{-5}$ x=0.21, y=$5.7\times10^{-5}$ x=0.21, y=$6.2\times10^{-5}$ x=0.21, y=$6.7\times10^{-5}$ x=0.21, y=$7.3\times10^{-5}$ x=0.21, y=$7.9\times10^{-5}$ x=0.21, y=$8.6\times10^{-5}$ x=0.21, y=$9.3\times10^{-5}$ x=0.21, y=$10^{-4}$ x=0.21, y=$1.1\times10^{-4}$ x=0.21, y=$1.2\times10^{-4}$ x=0.21, y=$1.3\times10^{-4}$ x=0.21, y=$1.4\times10^{-4}$ x=0.21, y=$1.5\times10^{-4}$ x=0.21, y=$1.6\times10^{-4}$ x=0.21, y=$1.8\times10^{-4}$ x=0.21, y=$1.9\times10^{-4}$ x=0.21, y=$2.1\times10^{-4}$ x=0.21, y=$2.3\times10^{-4}$ x=0.21, y=$2.5\times10^{-4}$ x=0.21, y=$2.7\times10^{-4}$ x=0.21, y=$2.9\times10^{-4}$ x=0.21, y=$3.1\times10^{-4}$ x=0.21, y=$3.4\times10^{-4}$ x=0.21, y=$3.7\times10^{-4}$ x=0.21, y=$4\times10^{-4}$ x=0.21, y=$4.3\times10^{-4}$ x=0.21, y=$4.7\times10^{-4}$ x=0.21, y=$5.1\times10^{-4}$ x=0.21, y=$5.5\times10^{-4}$ x=0.21, y=$6\times10^{-4}$ x=0.21, y=$6.5\times10^{-4}$ x=0.21, y=$7\times10^{-4}$ x=0.21, y=$7.6\times10^{-4}$ x=0.21, y=$8.2\times10^{-4}$ x=0.21, y=$8.9\times10^{-4}$ x=0.21, y=$9.7\times10^{-4}$ x=0.21, y=0.001 x=0.21, y=0.001 x=0.21, y=0.001 x=0.21, y=0.001 x=0.21, y=0.001 x=0.21, y=0.002 x=0.21, y=0.002 x=0.21, y=0.002 x=0.21, y=0.002 x=0.21, y=0.002 x=0.209, y=0.002 x=0.209, y=0.002 x=0.209, y=0.003 x=0.209, y=0.003 x=0.209, y=0.003 x=0.209, y=0.003 x=0.209, y=0.003 x=0.209, y=0.004 x=0.208, y=0.004 x=0.208, y=0.004 x=0.208, y=0.004 x=0.207, y=0.004 x=0.207, y=0.005 x=100, y=0.063 x=100, y=0.102 x=100, y=0.166 x=99.999, y=0.269 x=99.998, y=0.437 x=99.995, y=0.709 x=99.987, y=1.152 x=99.965, y=1.869 x=99.908, y=3.034 x=99.757, y=4.919 x=99.363, y=7.956 x=98.338, y=12.785 x=95.734, y=20.21 x=89.485, y=30.674 x=76.347, y=42.495 x=55.04, y=49.745 x=31.708, y=46.534 x=14.973, y=35.68 x=6.261, y=24.225 x=2.47, y=15.522 Two stationary tones time (s) frequency (Hz)

from signal-processing

How it works

(rLKK) validation/reconstruction, a port of Ahmed Yousef Kallel's own published method (Kallel & Kanoun, "Regularized linear Kramers-Kronig transform for consistency check of noisy impedance spectra with logarithmic frequency distribution", IWIS 2021) — see qu_core::eis for the algorithm. Z is a complex impedance spectrum (a CVec), freqs its frequency vector in Hz. rlkk_reconstruct/ rlkk_validate return a Value::Model (the same named-field multi-return convention as kalman_init/ols_model) since each call's outputs are one related result, not independent ones. rlkk_reconstruct(Z, freqs, [lambda=1e-4], [fx=]) — model kind "rlkk", fields z (the reconstructed spectrum) and gamma (the fitted DRT coefficients).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.