TRiggered Subsystem is taking very high time
1 view (last 30 days)
Show older comments
Hi,
I have a simulation with several matlab function block in my simulation and I am using SampleTime to trigger it at different frequencies.
Now as part of the test I want to vary the frequency of these blocks and see the behavior of simulation. I am not able to change the SampleTime variable as all the blocks of this simulation are Encrypted in the end.
I am thinking of redesigning it as Edge Triggered subsytem, so that I can controll the clock externally. But the moment I add triggered block on top of the Matlab Function. It becomes very slow.
Can some help why the same simulation with same execution rate is very slow with triggered block?
I have checked with SImulink Profiler that the majority of timeis being consumed by the Triggered subsytem.
2 Comments
Fangjun Jiang
on 9 Jul 2024
Don't understand this. What do you mean by "Encrypted"?
"I am not able to change the SampleTime variable as all the blocks of this simulation are Encrypted in the end."
Answers (1)
Ruchika Parag
on 11 Jul 2024
Hi Shivam, when you redesign your simulation to use Edge Triggered subsystems, it can become slower due to several factors. Here are some possible reasons for the slowdown:
1. Overhead of Triggered Subsystem:
Triggered subsystems can introduce additional computational overhead because they need to check for the trigger condition at every simulation step. This overhead can become significant, especially if the trigger signal changes frequently.
2. Execution Order and Dependency:
The execution order and data dependencies might change when you switch from a SampleTime-based approach to a triggered approach. This can lead to less efficient execution.
3. Solver Configuration:
The solver settings might not be optimal for the triggered subsystem. For example, if you're using a variable-step solver, it might take smaller steps than necessary, increasing the number of steps and thus the computation time.
4. Inefficient Trigger Signal:
If the trigger signal is not efficiently generated or has a high frequency, it can cause the subsystem to execute more often than required, leading to increased computational load.
You can try the following to improve performance:
1. Optimize Trigger Signal:
Ensure that the trigger signal is generated efficiently and only triggers the subsystem when necessary. Reducing the frequency of the trigger signal can help improve performance.
2. Use Function-Call Subsystems:
Instead of triggered subsystems, consider using function-call subsystems. Function-call subsystems can be more efficient because they are explicitly called by a function-call generator block, reducing the overhead associated with checking trigger conditions.
3. Adjust Solver Settings:
Review and adjust the solver settings. For example, if you are using a variable-step solver, try switching to a fixed-step solver with an appropriate step size that matches your desired sample time. This can reduce the number of unnecessary steps.
4. Profile and Optimize Code:
Use the Simulink Profiler to identify specific parts of the triggered subsystem that are consuming the most time. Optimize the MATLAB code within the function blocks to reduce computation time.
5. Parallel Execution:
If you have multiple triggered subsystems, consider running them in parallel if possible. Simulink supports parallel execution, which can help distribute the computational load.
Here is a basic example of how you might set up a function-call subsystem:
1. Create a Function-Call Generator Block:
Use a Function-Call Generator block to generate function-call events at the desired frequency.
2. Connect to Function-Call Subsystem:
Connect the output of the Function-Call Generator block to the input of a Function-Call Subsystem. Inside the function-call subsystem, place your MATLAB Function block.
3. Set Sample Time:
Configure the Function-Call Generator block to generate events at the desired sample time.
Sample Model Configuration
1. Function-Call Generator Block: Set Sample Time yo `0.01` (for example, 100 Hz)
2. Function-Call Subsystem: Place your MATLAB Function block inside this subsystem.
By following these suggestions, you should be able to improve the performance of your simulation while maintaining control over the execution rate of your MATLAB function blocks.
See Also
Categories
Find more on Schedule Model Components 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!