Why is there a difference in the sampling rate of the 'From Workspcace' and 'To workspace' blocks?

1 view (last 30 days)
I have a very simple model that has only a 'From Workspace' and 'To workspace' blocks. The 'From workspace' block, reads the data in the variable 'inputdata' defined in MATLAB workspace into Simulink, at the rate of 12.5 nano seconds. The 'From Workspace' block feeds into the 'To Workspace' block which captures the data in the variable 'outputdata' to the workspace with an inherited sampling time(-1). After running the Simulation,when I look at the timestamps of inputdata and outputdata, they are different.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
A possible reason behind why the time stamps of outputdata do not match that of the input signal inputdata could be the way in which sampling times are created in MATLAB and Simulink. Assuming the number of samples to be 77312, this is shown below:
dt = 1.25e-8;
t_ML = 0:dt:1.25e-8*77311; % example variable showing time values in MATLAB
t_SL = [0:1:77311]*dt; % example variable showing time values in Simulink
d = t_ML-t_SL;
plot(d)
Please note that t_ML and t_SL do not have the same values, even though mathematically the way they were defined is the same.
Hence, when we attempt to compare the time steps of inputdata which was created from MATLAB and outputdata, which is sampled according to Simulink methods, we notice the difference as above. To avoid this, use the following steps:
1) Define the time values for inputdata in the following way (Simulink approach):
inputdata.time = [0:1:77311]'*1.25e-8;
2) Now run your model to get the values of outputdata
3) Compare the time stamps of inputdata and outputdata:
find(~(inputdata==outputdata))
Note that the output from step 3 will be an empty matrix indicating that the time stamps match.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!