Transfer function block doesn't work inside a subsystem

Hi, I am applying a transfer function on a simple sine wave.
The result is ok when I run it in a model (transfer_no_sub).
But when I put the exact same thing inside a subsystem, the response diverges (transfer_sub).
I can’t figure out why.
Transfer_no_sub.plecs (13.3 KB)
Transfer_sub.plecs (22.3 KB)


[Edit]
One significant difference between the two is the step size: 1e-06 for _no_sub and 1e-04 for _sub. If I set _sub at 1e-06, I get a convergent signal. But I can’t afford this speed on my C2000.
Another oddity (to my eyes): when I set _no_sub at max step size = 1e-04, I get the same (good) result
[Edit2]
Further investigations make me think that the issue has to do with the precision of the float calculations. Is there any way I can make Plecs generate code with long double type ?

This has more to do with how the transfer function is discretized then floating vs. double point precision. The transfer function is discretized by default using Forward Euler when generating code in PLECS. This second order system is unstable with the default step size of 1e-4.

For this type of resonant transfer function, it is often better to explicitly discretize the system yourself. Attached is a model where I use the Octave controls toolbox to use the Tustin discretization method and Tustin with frequency prewarp. The prewarp assures the resonance is exactly at the desired frequency. I changed the sampling frequency (fe) to 1e3 to exaggerate the impact of the prewarp and highlight how the system is still stable even with the much smaller sampling frequency.

Transfer_sub_bl.plecs (24.7 KB)

1 Like