implementation of two different time domain

Problem:
  • two different time domain where I have sample and hold and, unit delay, and Ccaller code which automatically use a specific time domain and not the one from the "system";
  • for "sample and hold" is quite easy: exist a triggerable sample and hold, but not for unit delay and if I place an "m-function" or a Ccaller with a specific time samplig it is synchronized to the system time.
  • I am not talking about creating two different sampling time, but creating two "countinuos time" with nested a sampling time.
  • In the matter of fact I would like to recrated the "local" time of two different processors with slidly different clock.
Any ideas?
Thanks in advance

4 Comments

Make a subsystem atomic can allow you to specify a fixed sampling time that can be different from that used by the global solver.
Model Reference also allows use of a local solver that can be using a different sampling time.
Just some ideas without understanding your use case too well.
I noticed you put "Simscape" in the Products list. Is that accurate? There may be additonal step that needs to be taken if there is a Simscape network in your model.
Hi Yifeng
many thanks for your suggestions, the atomic subsystem seems a great idea, tomorrow i check.
Concerning Simscape: in general I implement model in this way
  • simscape uses local solver with backward euler with step time at ts = 1e-6/0.5e-6 for power electronics application where switching frequency is around ts_ctrl = 10kHz;
  • control system run with discretization at 10kHz using sample and hold;
  • global simulation set at fixed time step, backward euler at ts.
Performance are quite fine for power electronics applications. In case the switching frequency increase like with SiC components I increase also the ts. In general ts = ts_ctrl / 200.
The product "specialized power system" has a different solver and is "in general more accurate" than Simscape Electric, but if you build the model in correct way performance are OK. Sometimes is usefull to add some dummy state variables like placing inductors with 1e-6H along the "electrical" connections. I think this creates additional state which help the solver.
From my point of view, the good thing of Simscape is the possibility to build "dynamic system" with physical enviroment using "code style" implementation.
In general Simscape is more critical than "specialized power system" but at the end if everything is running fine the equivalent real system works very close to the simscape/simulink model. I am talking about power electronics, electrical drives and hysrostatic systems.
Concerning Simscape, with hydrostatic systems (only fundamental; the more complex devices like three ways valves have been built by coding in simscape ssc) the time step for backward euler was ts = 1e-3... but I am talking about device with 24000kg of mass... so "outer" dynamics was aroung 1Hz. Accuracy was quinte fine once compressibility of the fluid had been well managed... again: adding state variables the simulation getting faster and in particular more accurate.
Indeed, fluid systems (hydraulic, thermal liquid, gas, etc.) usually operates at much lower frequencies than power electronics, or they only need to be simulated at such lower frequencies. If you are able to separate the model into two separate Simscape networks, two local solvers at different time steps should work fine.

Sign in to comment.

 Accepted Answer

Hi Davide,
I understand you are trying to simulate two subsystems in Simulink/Simscape, each with its own local continuous time base, like modelling two processors with slightly different clocks. Here are some possible workarounds:
  • Atomic Subsystems: By making a subsystem atomic, you can assign it a specific sample time that is different from the rest of the model. This allows you to run certain parts of your model (such as control algorithms) at a unique and fixed rate, independent of the global simulation step size.
  • Model Reference with Local Solver: Using Model Reference blocks, you can encapsulate each subsystem as a separate referenced model and assign a local solver (continuous or discrete) to each one. This enables each referenced model to operate with its own solver settings and time base, providing true independence between subsystems.
  • Simscape Local Solvers: In Simscape, independent physical networks can each be assigned their own local solver settings, including different integration methods and step sizes. This is particularly useful when you have physical subsystems (e.g., electrical and hydraulic) that require different simulation time steps due to their dynamics.
Helpful Documentation:
  1. For subsystem/atomic subsystem: Sample Time in Systems and Subsystems - MATLAB & Simulink
  2. For referenced models: Use Local Solvers in Referenced Models - MATLAB & Simulink
Hope this helps clarify your options.

More Answers (0)

Categories

Find more on Simscape Electrical in Help Center and File Exchange

Products

Release

R2024b

Asked:

on 22 Aug 2025

Answered:

on 2 Sep 2025

Community Treasure Hunt

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

Start Hunting!