In the attached model, I’m trying to compare the frequency response of an analogue 3P3Z (type-III) controller to it’s discrete counter-parts (two versions: MMPZ and Tustin), but the discrete versions seems way off around the crossover frequency (8 kHz), I suspect I didn’t set up the C block correctly, any chance it has to do with the discreteStates(0,0)?
Also why would frequency response generate a smooth bode plot, while the AC sweep produces a pretty jittery one?
Your diagnosis is correct. The methods below rely on accurate accounting of the system states. When you do not explicitly define states as such in the C-Script, then the PLECS solver doesn’t know they are states.
AC Sweep uses states for steady-state convergence.
Fixing the state issue, the Frequency Response Analysis (FRA) and Multitone both return consistent results. There also was an issue in your FRA setup where the settling time span was set to 0. This parameter is the “Time needed by the system to reach steady state after the sinusoidal perturbation is applied, in seconds (s).” and should be non-zero. It’s based on your system dynamics, but I chose 0.01 sec and it looked fine. Also note that multitone would have worked fine from the start because it doesn’t rely on the stored system state, but rather two transient runs.
The AC Sweep has some issues converging because it has a pure integrator, as alluded to in this previous forum post, so it isn’t a great method for this application. If you set the AC Sweep’s “Operating Point” to “non-periodic (DC)” then the analog TF extraction works, but the digital ones don’t. Generally, AC Sweep is superceded by FRA since it side-steps many of the steady-state convergences issues that limit that method.