vecfit
Pure-Rust implementation of relaxed vector fitting for rational approximation of frequency-domain data. Fits scalar, vector, and matrix-valued responses.
[]
= "0.1"
Quick start
use ;
let csv = "\
freq_Hz,re_f1,im_f1
1.0,0.95,-0.31
3.0,0.55,-0.62
10.0,0.22,-0.78
30.0,0.08,-0.45
100.0,0.02,-0.15
";
let model = from_csv?.fit?;
Column formats are auto-detected from headers: re_*/im_* for rectangular,
|*|/ang_* for magnitude/phase.
Input formats
CSV from a file:
use ;
let model = from_path?.fit?;
Also supports TSV (from_tsv), SSV (from_ssv), and custom delimiters (from_delimited).
For matrix-valued data, chain .matrix(rows, cols)? before .fit(...).
Touchstone (.s1p, .s2p, ...):
use ;
let model = from_path?.fit?;
Supports S/Y/Z/G/H/T parameters, RI/MA/DB formats, and all standard frequency units.
Closure fitting
For analytic transfer functions, pass a closure directly:
use Complex64;
use ;
let s: =
.map
.collect;
let model = fit?;
Closures can return scalars, arrays, or nested arrays — the shape is inferred automatically.
See the API docs for c(re, im), axis wrappers (hz, rad, real),
and matrix fitting.
Axis wrappers
| Wrapper | Closure receives | Internal mapping | Typical use |
|---|---|---|---|
hz(&freq) |
f64 (Hz) |
j 2 pi f |
measured frequency data |
rad(&omega) |
f64 (rad/s) |
j omega |
angular frequency |
real(&x) |
f64 |
x (real line) |
kernel fitting, Laplace domain |
complex(&s) |
Complex64 |
passthrough | full control |
Examples
Scalar fit (10 poles, RMSE 2.2e-4)

Vector fit (18 poles, 3 channels, RMSE 2.3e-4)

Matrix EMT fit (10 poles, 2x2, RMSE 1.9e-4)

Author
Related projects
- gspx — graph signal processing in Rust, uses
vecfitfor its fitting backend - sgwt — spectral graph wavelet transform in Python (docs)
License
Licensed under either of Apache License 2.0 or MIT, at your option.