Simulate RC Circuit Step Response

Medium Python Estimation Asked at Texas Instruments
Solve this problem

Simulate the step response of a series RC low-pass filter numerically and report the time to reach 63.2 percent of the final value, then compare it against the analytical time constant.

Constraints

  • Use forward Euler with a fixed timestep.
  • The timestep must be at least 100 times smaller than RC.
  • Return the measured time constant in seconds.
  • Must be within 2 percent of R*C.
  • No SciPy ODE solvers - write the integration loop.
Starter codePython
1def rc_step_response(r_ohms, c_farads, v_in=1.0):2    """Return the measured time constant in seconds."""3    # TODO4    return 0.0