I don't understand the concept of sample time in simulink

I had a simulink block(a constant block=2) connected to an output port(yout). I set a 'fixed step size' of 0.2 in the 'configuration parameters' dialogue box. I was thinking that if i set the constant block to a sample time of 0.4, the constant block should execute at every second sumulation time step since 'fixed step size' is 0.2. But when i ran the model for a stop time of 0.8(ie for 5 'time steps' including 0) i got yout=[0;2;2;2;2] meaning that the block executed 5 times. What i was expecting was for the block to execute only 3 times so that yout=[2;2;2].
So I concluded that I do not understand the concept of sample time. I will appreciate it if anyone could help explaining the above result and the general concept of sample time.
Thanks you in advance. Bethel

 Accepted Answer

In this case, since you are looking at the logged data yout, the sample time is determined by the sample time specification of the Outport block. If you change the sample time of the Outport block, you'll see the difference.
For general information regarding sample time in Simulink, see Sample Times

6 Comments

thank you for your reply Fangjun Jiang but the sample time on the outport was set to -1. I have just changed it to 0.4 and i am still getting the same result.
Ok why do i get yout=[2;2;2;2;2] when the sample time is equal to 0.2 for both blocks and yout=[0;2;2;2;2] when the sample time is 0.4 for both block. I have read the link on your reply but it talks about sample time on s-functions. I need to use simulink on a bigger project and am guessing i need to understand how things link sample time works
thanks
Okay, maybe I am mistaken. Make this example to understand it.
Drag a Clock or Ramp block from the source library, connect it to an Outport block. Set the solver to be fixed step discrete, time step to be 0.1. You can't set the sample time of the Clock or Ramp block, but you can change the sample time of the Outport block, set it to be 0.2 or 0.4. Run the simulation from 0 to 0.8. Check the tout and yout.
It looks like the number of data points in yout is determined by simulation time and time step. This reflects the data logging though. It doesn't reflect the sample time. You need to check the value of yout to see the effect of sample time.
I ran the setup you described but i got the following error. "The sample time 0.2 of 'untitled/Out1' at input port 1 is different from the sample time [0, 0] of 'untitled/Ramp/Output' at output port 1. Consider inserting a Rate Transition block between the two ports. Alternatively, you can control the diagnostic action for unspecified rate transitions on the Sample Time Diagnostics pane of the Configuration Parameters dialog box."
In the "Solver" panel of the "Configuration Parameters ..." dialog, un-check the option "Automatically handle data transfers between tasks".
Thank you very much. I think I understand it now. Well thats if the following is right: In the solver panel for the 'configuration parameter' dialogue, i saw a check box for 'Automatical handle rate transition for data transfer'. The check box was un-checked. I checked the box and ran the model again. I noticed that yout was being delayed by the value of its sample rate.
when I ran the setup I get the following error "The sample time 1 of 'G722_ITU_T_Codec/Multiport Switch' at input port 2 is different from the sample time 2.083333333333333e-05 of 'G722_ITU_T_Codec/Random Source' at output port 1. Consider inserting a Rate Transition block between the two ports. Alternatively, you can control the diagnostic action for unspecified rate transitions by changing the option "Multitask (or Single task) rate transition" on the Sample Time Diagnostics pane of the Configuration Parameters dialog box."

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!