#import "../lib/unify.typ": qty, unit
#import "@preview/cetz:0.5.2"
#import "@preview/cetz-plot:0.1.4": plot

#figure(
  cetz.canvas({
    import cetz.draw: *

    plot.plot(
      size: (12, 9),
      y-mode: "log",
      x-label: [Time $t$ ($unit("s")$)],
      y-label: [Residual Voltage $V_upright("DA")$ ($unit("mV")$)],
      x-min: 0.001,
      x-max: 9,
      y-min: 0.01,
      y-max: 500,
      x-grid: "minor",
      y-grid: "minor",
      {
        // 200 uV (0.2 mV) Metrologic systematic error budget limit
        plot.add(
          ((0.001, 0.2), (10, 0.2)),
          style: (
            stroke: (paint: luma(120), thickness: 0.8pt, dash: "dash-dotted"),
          ),
          label: [Budget limit ($qty(200, "uV")$)],
        )
        // Ceramic X7R (DA = 2.5%, 10 V step -> 250 mV initial soakage peak)
        plot.add(
          style: (stroke: (dash: "solid")),
          label: [Ceramic (X7R / Class 2)],
          domain: (0.001, 10),
          samples: 1000,
          t => (
            250
              * (
                0.5 * calc.exp(-t / 0.01) + 0.3 * calc.exp(-t / 0.1) + 0.2 * calc.exp(-t / 1.0)
              )
          ),
        )
        // Polypropylene PP (DA = 0.05%, 10 V step -> 5 mV initial soakage peak)
        plot.add(
          style: (stroke: (dash: "dotted")),
          label: [Polypropylene (PP)],
          domain: (0.001, 10),
          samples: 1000,
          t => (
            5
              * (
                0.5 * calc.exp(-t / 0.01) + 0.3 * calc.exp(-t / 0.1) + 0.2 * calc.exp(-t / 1.0)
              )
          ),
        )
        // Polystyrene PP (DA = 0.002, 10 V step -> 2 mV initial soakage peak)
        plot.add(
          style: (stroke: (dash: "dashed")),
          label: [Polystyrene (PS)],
          domain: (0.001, 10),
          samples: 1000,
          t => (
            2
              * (
                0.5 * calc.exp(-t / 0.01) + 0.3 * calc.exp(-t / 0.1) + 0.2 * calc.exp(-t / 1.0)
              )
          ),
        )
        // Teflon PTFE (DA = 0.001, 10 V step -> 1 mV initial soakage peak)
        plot.add(
          style: (stroke: (dash: "dash-dotted")),
          label: [Teflon (PTFE)],
          domain: (0.001, 10),
          samples: 1000,
          t => (
            1
              * (
                0.5 * calc.exp(-t / 0.01) + 0.3 * calc.exp(-t / 0.1) + 0.2 * calc.exp(-t / 1.0)
              )
          ),
        )
        // Class 1 C0G/NP0 Ceramic (DA = 0.005%, 10 V step -> 0.5 mV initial soakage peak)
        plot.add(
          style: (stroke: (dash: (6pt, 2pt, 2pt, 2pt))),
          label: [Class 1 (C0G/NP0)],
          domain: (0.001, 10),
          samples: 1000,
          t => (
            0.5
              * (
                0.5 * calc.exp(-t / 0.01) + 0.3 * calc.exp(-t / 0.1) + 0.2 * calc.exp(-t / 1.0)
              )
          ),
        )
      },
    )
  }),
  caption: [Capacitor dielectric absorption residual voltage relaxation ($V_upright("DA")$) over time following a $qty(10, "V")$ step voltage reset, comparing dielectric classes against the $qty(200, "uV")$ systematic error budget],
) <figure-capacitor-dielectric-absorption-noise-typical-magnitude>
