Discrete transfer function implementation on hardware explodes to infinity

Hi,
I have a very simple transfer function model that works well in Matlab/Simulink. However, when I try to implement it on my actual hardware, the output quickly explodes to infinity.
I'm trying to deploy this model to a PLC running Twincat. Twincat has its own implementation of transfer functions which I have faith it is bug free. I have double checked my calls and I don't believe there is anything wrong (famous last words!).
Could this numeric instability be due to the way that matlab/simulink implements the calculation versus the way that Twincat does it?
Or could it be something related to the type/order of the model? Would state space offer any advantage in terms of numeric stability?
Thanks
#Matlab code
sys = tf([0 0.0611], [1 2.05 0])
sys =
0.0611
------------
s^2 + 2.05 s
Continuous-time transfer function.
sysd = c2d(sys, 0.002)
sysd =
1.22e-07 z + 1.219e-07
----------------------
z^2 - 1.996 z + 0.9959
Sample time: 0.002 seconds
Discrete-time transfer function.

댓글 수: 5

You may have faith, but faith is too often poorly rewarded. What you don't say, or possibly don't know, is if the implementation that you are using does its work in fewer significant digits. For example, is that code runniing in effectively a lower precision arithmetic?
Knowledge is always better than simple faith.
Hi John, thanks for your answer.
Beckhoff's Twincat Tc_ControllerToolbox, isn't some obscure open source repo off the internet. I paid for the license, I should trust it works. The same way you and I and everybody else using Matlab trust it works.
Twincat's implementation of TF's runs with long reals, it's plenty of resolution.
hello @Felipe
which IIR topology are you using ?
Biquad implementation is more numerically stable than Direct Forms
Hi Mathie, thanks for your reply!
I did not know that. The transfer function I'm trying to implement has 2 poles and 2 zeros. The API I'm using, implements the model in this form:
That sounds ok to me
make sure the a and b coefficients are passed in the right order (usual error is when copy paste from ascending vs descending power of z formalism)

댓글을 달려면 로그인하십시오.

답변 (1개)

Bora Eryilmaz
Bora Eryilmaz 2022년 12월 7일
편집: Bora Eryilmaz 2022년 12월 7일
Your discrete transfer function has poles (almost) right on the unit circle:
sys = tf([0 0.0611], [1 2.05 0]);
sysd = c2d(sys, 0.002);
pzmap(sysd)
Any slight perturbation of your model coefficients when it is implemented using fixed-point numbers on the PLC would likely make your transfer function unstable.
Also, your model has an integrator (1/s term). So its simulation would go to infinity anyway.
step(sys)

카테고리

도움말 센터File Exchange에서 Digital Input and Output에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 11월 5일

편집:

2022년 12월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by