Sample Time from To Workspace not precise

4 ビュー (過去 30 日間)
Werner González Holtheuer
Werner González Holtheuer 2023 年 11 月 4 日
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.
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.
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!


Fangjun Jiang
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.
  1 件のコメント
Werner González Holtheuer
Werner González Holtheuer 2023 年 11 月 6 日
Thanks, this solved the issue!


その他の回答 (0 件)


Help Center および File ExchangeSources についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by