Clear Filters
Clear Filters

Simscape Fix-step simulaiton with two different time steps

24 views (last 30 days)
Hi folks,
I would like to conduct a simulation with Symscape electronics with two different time steps. The idea is to use for the beginning of simulation bigger time steps in for the period of time when the system is oscillation and after reaching of a stable state change the sampling time to more fine. For example the complete simulation time could be 0.5s and the system became stable after 0.46s. In this case I would like to simulate with sampling time Ts = 2e-5s during a time frame 0 - 0.46s and than beginning from 0.46s switch to Ts = 5e-8s and complete simulation between 0.46s and 0.5s with the fine time step. Basically I need it for obtaining of the spectrum for output voltage and current up to the relatively high frequency.
I have tried to manage it with the option Data Import/Export. The data from the simulation with Ts = 2e-5s was save into an intermediate storage. Than the time step was changed but a have got an error "Simulink cannot load the initial SimState because the model, 'EMI_model_motor_2017_09_06', was changed after the SimState was saved. Run the simulation again and resave the SimState. Ideally would be simply change the parameter Ts but seems like it is impossible to do.
Thank you in advance Illia

Answers (1)

Abhi Sundararaman
Abhi Sundararaman on 20 Sep 2017
Edited: Abhi Sundararaman on 20 Sep 2017
According to the following doc page: Changing the model's configuration parameters will prevent the SimState from being used. Therefore, it seems that changing the sample time between runs while trying to maintain SimState isn't possible unfortunately.
One workaround for this could be to start the simulation at your smallest sample time, and wherever you wish to have a higher sample time, you could set up logic (i.e a MATLAB function block) to only execute certain calculations every x time steps.
For example, if your lowest sample time was Ts1, but the start of your model from t = 0 to n should run at Ts2 (and Ts1 < Ts2), then you could have a MATLAB function block with an "if" statement that only ran calculations every Ts2/Ts1 timesteps for the first n seconds, and then afterwards it would run every Ts1 seconds.
Another, perhaps more straightforward workaround would be to package the higher-sample time section of the simulation into an Atomic Subsystem. The atomic subsystem can have blocks whose sample time is an integer multiple of the outer-model's sample time.
  1 Comment
illia manushyn
illia manushyn on 13 Oct 2017
Hi Abhi,
thank you for this advice. I sort of understand the principle which you recommend but I have no clue how to execute the model every x time steps. How can I run calculations every second or whatever step of the sampling time? Could you please provide an example of the proposed method. Which commands should I use to achieve this "every x time steps" execution?
PS: It is probably possible to use a trigged subsisted and trigger it with different time steps but than I will be forced simply put the whole model to the subsystem. Seems like it is not the best solutions ever.
Thank you for the support.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!