Skip to main content

smith/
smith.rs

1use bland::{gamma_from_z, Figure, SmithGridOpts, Stroke};
2
3fn main() {
4    // Sample S11 sweep: a frequency-dependent impedance Z(f) = R(f) + jX(f),
5    // converted to Ī“.
6    let n = 60;
7    let mut grs = Vec::with_capacity(n);
8    let mut gis = Vec::with_capacity(n);
9    for i in 0..n {
10        let f = i as f64 / (n - 1) as f64;
11        let r = 0.4 + 1.6 * f;
12        let x = -1.5 + 3.0 * f;
13        let (gr, gi) = gamma_from_z(r, x);
14        grs.push(gr);
15        gis.push(gi);
16    }
17
18    let fig = Figure::smith()
19        .title("S₁₁ sweep")
20        .smith_grid(SmithGridOpts::default())
21        .line(&grs, &gis, |s| s.label("Ī“(f)").stroke(Stroke::Solid))
22        .legend_bottom_right();
23
24    std::fs::create_dir_all("out").expect("create out/");
25    std::fs::write("out/smith.svg", fig.to_svg()).expect("write svg");
26    println!("wrote out/smith.svg");
27}