Given your situation where the 3 input signals are of different sample rates, “Rate Transition” block or a “Zero-Order Hold” block can be used to ensure the simulation runs properly in a Multi-Rate system. Usage of “Rate Transition” block is best when the sample times of the input signals are multiples of each other.
If not, the next best option would be to use the “Zero-Order Hold” block. The “Zero-Order Hold” block holds its input for the sample period you specify. If the input is a vector, the block holds all elements of the vector for the same sample period. Using these blocks the signals with different sample rates can be handled.
Similarly, to create a trigger for a MATLAB function, you can either condition the trigger in the MATLAB function itself or use a “Enabled/Triggered Subsystem”.
For creating the trigger you can use a “Unit Delay” block and a “Relational Operator (~=)” block to check whether there is a change in the signal values and send the result through a switch or to the conditional input to the “Enabled/Triggered Subsystem”, by which we can set the condition to activate the subsystem only when the conditional input is satisfied.
Alternatively, you can check the change in data at previous and current time step in the MATLAB function itself and give the output accordingly.
Here is a sample code on how this validation can be done in the MATLAB function itself,
function [output, isNewData] = processData(inputSignal)
persistent prevData;
if isempty(prevData)
prevData = inputSignal;
end
output = prevData;
isNewData = false;
if inputSignal ~= prevData
isNewData = true;
output = inputSignal;
prevData = inputSignal;
end
end
For more information on “Zero-Order Hold”, “Rate Transition” blocks or “Enabled/Triggered Subsystems” you can refer the following documentation links:
- “Zero-Order Hold” - https://www.mathworks.com/help/simulink/slref/zeroorderhold.html
- “Rate Transition” - https://www.mathworks.com/help/simulink/slref/ratetransition.html
- “Enabled Subsystem” - https://www.mathworks.com/help/simulink/slref/enabledsubsystem.html
- “Triggered Subsystem” - https://www.mathworks.com/help/simulink/slref/triggeredsubsystem.html
Hope this helps!