Compiled Simulink model of transfer function block giving different results

I have a very simple model that consists of an input port, a transfer function and an output port. The model is attached to this question in case you want to check it.
The inputs for the first three steps are { -60.982112667828780, -60.781022873413790,60.168975966495110 }.
The outputs in Simulink are: {0, -0.003033557714140, -0.012065510055461}
While in the C code I get the following results: {0, 0, -0.0060982112667828780}.
So I unchecked the Single output/update function option in order to have them separated.
I don't know what is causing my results to be so different in Simulink and the generated C code. Does anybody have any idea?

댓글 수: 2

One simple question: What is your sampling rate for discretizing your transfer function while generating C code?
Thank you, Birdman!
I guess this is the point that I was missing. I haven't been able to find a command line that enables me to specify the sampling rate for discretizing my transfer function while generating the C code. Do you know if such a command exists ?
What I did instead is go to the menu Analysis > Control Design > Model Discretizer. Then I discretized my transfer function changing its sample rate from 1Hz to 0.001 Hz.
Now I obtain identical results in Simulink and the generated C code. However, the result is not identical to the one I obtained when the transfer function was continuous, the error is small though.
Do you know if it is possible to make the generated C code output the same result as the continuous transfer function ?
Best Regards

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

질문:

2017년 12월 7일

댓글:

2017년 12월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by