Make a measurement of a signal at a specific time rate in Simulink
Make a measurement of a signal at a specific time rate in Simulink
I have a Simulink model with a controller that inputs a command in a system.
The controller gives its input based on the state measurements given by the system, and I want to simulate that the system has only access to measurements at a specific rate, 1/Ts (with Ts the sampling time). Which would imply that during one Ts the controller holds a constant input.
However I would like the system dynamics to be computed using an accurate solver using variable step-size.
Right now, I managed to make it work when using a solver with a fixed step-size. For instance when the sample rate Ts is 100 the fixed step size, I have simply added a block with this Matlab function after the controller and before the system:
function [old_input, output, new_counter] = fcn(new_input, old_input, counter)
if counter < 99
new_counter = counter + 1;
output = old_input;
else
new_counter = 0;
output = new_input;
old_input = new_input;
end
Where I initialize the counter variable to 99.
Is there a way to have a similar result when using a variable step-size.
You need to spend some time learning how Simulink works, perhaps starting with the basic examples at Sample Times in Systems. Simulink inherently allows you to do what you are trying to do with your code by setting block sample times appropriately.
– Phil Goddard
Sep 2 at 2:45
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Another way may be to have multiple rates in your model using rate transition blocks.
– Tom
Sep 1 at 21:37