Compiled Simulink model of transfer function block giving different results

8 views (last 30 days)
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 Comments
Birdman
Birdman on 7 Dec 2017
One simple question: What is your sampling rate for discretizing your transfer function while generating C code?
RICARDO SEGALLA
RICARDO SEGALLA on 7 Dec 2017
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

Sign in to comment.

Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!