Random signls and clocktime in Simulink

7 views (last 30 days)
Serbia
Serbia on 10 Aug 2022
Moved: Atsushi Ueno on 17 Aug 2022
I have a problem in understanding a simple matlab property. If you have this simple model with the clock, a matlab function and a scope. Why does the fuction is just run every 0.2 seconds in the simulation time? Same when you use 100 as Stop time. Then the function will be run every 2 seconds. In between the random values generated by the funtion, Simulink connects the values linearzed. Next question is why is simulink generating alwys the same "random"signal? I want to implement a random noise signal in a bigger model, but i think i did not understand how it works.
function y = fcn(u)
y =rand;
end
  1 Comment
Atsushi Ueno
Atsushi Ueno on 10 Aug 2022
Moved: Atsushi Ueno on 17 Aug 2022
>Why does the fuction is just run every 0.2 seconds in the simulation time?
You must be using a Variable-step solver. It changes the step size during the simulation, reducing the step size to increase accuracy when model states are changing rapidly and increasing the step size to avoid taking unnecessary steps when model states are changing slowly. You can set expected step size as "Fixed-step size" below.
>Next question is why is simulink generating alwys the same "random" signal? I want to implement a random noise signal in a bigger model, but i think i did not understand how it works.
When you set the same seed value like zero as default, the rand function always return the same set of value. You need changing the seed value of the rand function.
Example: Each time you run the model, you will get different seed values depending on the time of day.
rng(sum(clock))

Sign in to comment.

Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!