Skip to content

Design a Filter

This tutorial walks through a complete filter design workflow using mcltspice tools. You will create a circuit from a template, simulate it, measure the bandwidth, and adjust component values to hit a target specification.

Design a 1st-order RC lowpass filter with a -3dB cutoff at 10 kHz.

  1. Create the circuit

    Use create_from_template to generate an RC lowpass filter netlist:

    {
    "template_name": "rc_lowpass",
    "params": {
    "r": "1k",
    "c": "15n"
    }
    }

    The theoretical cutoff is f_c = 1 / (2 * pi * R * C) = 1 / (2 * pi * 1000 * 15e-9) = 10,610 Hz. Close to 10 kHz.

  2. Simulate

    Run AC analysis with simulate_netlist on the generated .cir file. The template includes an .ac dec 100 1 1meg directive by default.

  3. Measure bandwidth

    Use measure_bandwidth on the .raw file with signal V(out):

    {
    "raw_file_path": "/tmp/rc_lowpass.raw",
    "signal_name": "V(out)"
    }

    This returns the -3dB frequency, which should be near 10.6 kHz.

  4. Iterate if needed

    If the cutoff is off-target, use tune_circuit to get suggestions:

    {
    "template": "rc_lowpass",
    "params": {"r": "1k", "c": "15n"},
    "targets": {"bandwidth_hz": "~10000"},
    "signal": "V(out)"
    }

    The tool will measure the actual bandwidth and suggest adjusted component values.

  5. Visualize

    Generate a Bode plot with plot_waveform:

    {
    "raw_file": "/tmp/rc_lowpass.raw",
    "signal": "V(out)",
    "plot_type": "bode"
    }

    This creates an SVG showing magnitude and phase vs. frequency.

The RC lowpass cutoff frequency is f_c = 1 / (2 * pi * R * C). To lower the cutoff, increase R or C. To raise it, decrease them. The tune_circuit tool does this math for you and suggests standard component values from E12/E24 series.