Sample Time from To Workspace not precise
6 次查看(过去 30 天)
显示 更早的评论
I'm having trouble with the sample time when passing data from Simulink to the Workspace using the To Workspace block.
I have an electrical circuit (with PLECS blockset) and I'm measuring a voltage in a certain point. The measure this voltage I defined a sample time of Ts=1/(50*256)=7.8125e-5 using a ZOH block (The election of this sample time is from a real life voltmeter). The simulation is set for continouos time, so the output of the ZOH is a continouos stepped signal with steps every Ts seconds. The result of the simulation is shown below with a time span of 5*Ts.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1529122/image.png)
This signal is passed to a To Workspace block with the sample time set to Ts, but the arrays I'm getting in the workspace aren't entirely correct.
Also:
Limit data points to last = inf
Decimation = 1
Log fixed-point data as a fi object is checked
If I use the Cursor Measurments of the Simulink scope, the values in each step are:
[0.000, 0.257, 0.983, 2.224, 3.720]
But when I print this array from the workspace I get:
[0.000, 0.257, 0.983, 0.983, 3.7204]
In the bolded data point, the simulation time should be, 3*Ts = 2.34375e-4 [s] and the value should be 2.224. I believe that for some reason, the time it is evaluating is 2.3437e-4 [s] < 2.34375e-4 [s] getting the previous value of 0.983.
Is this because the time values are fixed point decimals? Or because in the continouos time array the point 2.34375e-4 [s] doesn't exist?
Thanks in advance!
0 个评论
采纳的回答
Fangjun Jiang
2023-11-6
If you use a ZOH block to measure the signal and specify the sample time of the ZOH block as Ts, then specify the sample time for the To Workspace block as -1. That should give you the correct data that matches the data shown in the Scope.
If you specify two sample times, Simulink may not be able to recognize that they are the same. It is like doing floating point data equal comparison. There is a precision problem when you specify data like 1/(50*256) in two places.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!