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.





Another way may be to have multiple rates in your model using rate transition blocks.
– Tom
Sep 1 at 21:37





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ